-
Notifications
You must be signed in to change notification settings - Fork 232
/
inflector.html
781 lines (758 loc) · 20.3 KB
/
inflector.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../assets/css/combined.css?20170912">
<link rel="shortcut icon" href="./../favicon.ico" />
<script src="https://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../';
var class_prefix = "Inflector::";
</script>
<script src="./../assets/js/combined.js?20170912"></script>
<title>Inflector - Classes - FuelPHP Documentation</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<div id="cse">
<gcse:searchbox-only newWindow="true"></gcse:searchbox-only>
</div>
<h1>
<a href="https://fuelphp.com"><img height="37px" width="147px" src="./../assets/img/fuel.png" /></a>
<strong>Documentation</strong>
</h1>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">table of contents</a>
<div class="clear"></div>
</header>
<div id="main">
<h2>Inflector Class</h2>
<p>
The Inflector class allows you to transforms words from singular to plural,
class names to table names, modularized class names to ones without,
and class names to foreign keys.
</p>
<p>
Inflector rulesets can be defined as language files, to be able to localize them.
The framework comes with a default set of rules for the English language, which
can act as a template for localisation.
</p>
<article>
<h4 class="method" id="method_ascii">ascii($str, $allow_non_ascii = false)</h4>
<p>The <strong>ascii</strong> method allows you to translate a string to a 7-bit ASCII string. This method only works with UTF-8.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$str</kbd></th>
<td><i>Required</i></td>
<td>The string to translate.</td>
</tr>
<tr>
<th><kbd>$allow_non_ascii</kbd></th>
<td><pre class="php"><code>false</code></pre></td>
<td>Whether to allow non ASCII chars.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::ascii('Inglés'); // returns Ingles</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_camelize">camelize($underscored_word)</h4>
<p>The <strong>camelize</strong> method allows you to convert a string with words separated by underscores into a CamelCased string.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$underscored_word</kbd></th>
<td><i>Required</i></td>
<td>The underscored word.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::camelize('apples_and_oranges'); // returns ApplesAndOranges</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_words_to_upper">words_to_upper($class)</h4>
<p>The <strong>words_to_upper</strong> method uppercases the first letter of each word in a classname with
the words separated by underscores.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$class</kbd></th>
<td><i>Required</i></td>
<td>The classname.</td>
</tr>
<tr>
<th><kbd>$sep</kbd></th>
<td><i>_</i></td>
<td>The separator</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::words_to_upper('fuel_users'); // returns Fuel_Users
echo Inflector::words_to_upper('module::method', '::'); // returns Module::Method</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_classify">classify($table_name)</h4>
<p>The <strong>classify</strong> method allows you to convert a table name to a class name.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$table_name</kbd></th>
<td><i>Required</i></td>
<td>The table name.</td>
</tr>
<tr>
<th><kbd>$singularize</kbd></th>
<td><pre class="php"><code>true</code></pre></td>
<td>Whether the $tablename is singularized before its words are uppercased.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::classify('fuel_users'); // returns Fuel_User</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_demodulize">demodulize($class_name_in_module)</h4>
<p>The <strong>demodulize</strong> method allows you to take the class name out of a modulized string.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$class_name_in_module</kbd></th>
<td><i>Required</i></td>
<td>The modulized class.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::demodulize('Uri::main()'); // returns main()</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_denamespace">denamespace($class_name)</h4>
<p>The <strong>denamespace</strong> method allows you to take the namespace off the given class name.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$class_name</kbd></th>
<td><i>required</i></td>
<td>The class name.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::denamespace('Fuel\\Core\\Config'); // returns Config</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_get_namespace">get_namespace($class_name)</h4>
<p>The <strong>get_namespace</strong> method returns the namespace of the given class name..</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$class_name</kbd></th>
<td><i>required</i></td>
<td>The class name.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string, the namespace</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::get_namespace('Fuel\\Core\\Config'); // returns Fuel\Core\</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_foreign_key">foreign_key($class_name, $use_underscore = true)</h4>
<p>The <strong>foreign_key</strong> method allows you to get the foreign key for a given class.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$class_name</kbd></th>
<td><i>Required</i></td>
<td>The class name.</td>
</tr>
<tr>
<th><kbd>$use_underscore</kbd></th>
<td><pre class="php"><code>true</code></pre></td>
<td>Whether to use an underscore or not.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::foreign_key('Inflector'); // returns inflector_id
echo Inflector::foreign_key('Inflector', false); // returns inflectorid</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_friendly_title">friendly_title($str, $sep = '-', $lowercase = false, $allow_non_ascii = false)</h4>
<p>The <strong>friendly_title</strong> method allows you to convert your text to a URL-friendly title so that it can be used in the URL. It only works with UTF-8 input and outputs 7 bit ASCII characters.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$str</kbd></th>
<td><i>Required</i></td>
<td>The text to convert.</td>
</tr>
<tr>
<th><kbd>$sep</kbd></th>
<td><pre class="php"><code>-</code></pre></td>
<td>The separator (either - or _)</td>
</tr>
<tr>
<th><kbd>$lowercase</kbd></th>
<td><pre class="php"><code>false</code></pre></td>
<td>Whether to use lowercase or not.</td>
</tr>
<tr>
<th><kbd>$allow_non_ascii</kbd></th>
<td><pre class="php"><code>false</code></pre></td>
<td>Whether to allow non ASCII chars.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::friendly_title('Fuel is a community driven PHP 5 web framework.', '-', true);
// returns fuel-is-a-community-driven-php-5-web-framework</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_humanize">humanize($lower_case_and_underscored_word)</h4>
<p>The <strong>humanize</strong> method allows you to turn an underscore separated word and turns it into a human looking string.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$lower_case_and_underscored_word</kbd></th>
<td><i>Required</i></td>
<td>The word to convert.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::humanize('apples_and_oranges'); // returns Apples and oranges</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_is_countable">is_countable($word)</h4>
<p>The <strong>is_countable</strong> method allows you check if the given word has a plural version.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$word</kbd></th>
<td><i>Required</i></td>
<td>The word to check.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>boolean</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::is_countable('fish'); // returns false
echo Inflector::is_countable('apple'); // returns true</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_pluralize">pluralize($word, $count)</h4>
<p>The <strong>pluralize</strong> method allows you get the plural version of the given word.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$word</kbd></th>
<td><i>Required</i></td>
<td>The word you want to pluralize.</td>
</tr>
<tr>
<th><kbd>$count</kbd></th>
<td><strong>0</strong></td>
<td>An instance, which if equal <kbd>1</kbd> will return the string as a singular.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::pluralize('apple'); // returns apples
echo Inflector::pluralize('apple', 1); // returns apple</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_ordinalize">ordinalize($number)</h4>
<p>The <strong>ordinalize</strong> method allows you to add english language order number suffixes.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$number</kbd></th>
<td><i>Required</i></td>
<td>The number you want to ordinalize.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::ordinalize(2); // returns 2nd</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_singularize">singularize($word)</h4>
<p>The <strong>singularize</strong> method allows you get the singular version of the given word.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$word</kbd></th>
<td><i>Required</i></td>
<td>The word you want to singularize.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::singularize('apples'); // returns apple</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_tableize">tableize($class_name)</h4>
<p>The <strong>tableize</strong> method allows you to convert a class name to a table name.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$class_name</kbd></th>
<td><i>Required</i></td>
<td>The class name.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::tableize('FuelUser'); // returns fuel_users</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_underscore">underscore($camel_cased_word)</h4>
<p>The <strong>underscore</strong> method allows you to convert a CamelCased string into an underscore separated string.</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
<table class="parameters">
<tr>
<th>Param</th>
<th>Default</th>
<th class="description">Description</th>
</tr>
<tr>
<th><kbd>$camel_cased_word</kbd></th>
<td><i>Required</i></td>
<td>The CamelCased word.</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Returns</th>
<td>string</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>echo Inflector::underscore('ApplesAndOranges'); // returns apples_and_oranges</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 class="method" id="method_load_rules">load_rules()</h4>
<p>
The <strong>load_rules</strong> method loads the inflector rules based on the current
language configuration. If no rulesset can be found (i.e. no inflector lang file exists),
the class will default to a ruleset for the English language. If you have loaded a ruleset,
you change your language configuration, reload again, but the new configuration doesn't have
a ruleset defined, Inflector will continue to use the current one.
</p>
<p class="note">
Upon first use the Inflector class will autoload the the ruleset based on the language
configuration. Normally you do not have to use this method.
</p>
<table class="method">
<tbody>
<tr>
<th class="legend">Static</th>
<td>Yes</td>
</tr>
<tr>
<th>Parameters</th>
<td>
None
</td>
</tr>
<tr>
<th>Example</th>
<td>
<pre class="php"><code>Inflector::load_rules(); // (re)loads the Inflector ruleset</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2025 - <a href="https://fuelphp.com">FuelPHP</a> is released under the MIT license.
</p>
</footer>
</div>
</body>
</html>