-
Notifications
You must be signed in to change notification settings - Fork 232
/
inflector.html
665 lines (643 loc) · 15.9 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Inflector Class - Fuel Documentation</title>
<link href="../assets/css/main.css" media="screen" rel="stylesheet" />
<script type="text/javascript" src="../assets/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../assets/js/nav.js"></script>
<script type="text/javascript" src="../assets/js/highlight.pack.js"></script>
<script type="text/javascript">
$(function() {
show_nav('classes', '../');
});
hljs.tabReplace = ' ';
hljs.initHighlightingOnLoad();
</script>
</head>
<body>
<header>
<h1>Fuel Documentation</h1>
</header>
<div id="main-nav"></div>
<section id="content">
<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>
<article>
<h4 id="method_ascii">ascii($str)</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>
</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 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 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>
</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</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 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 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 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 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 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 id="method_friendly_title">friendly_title($str, $sep = '-', $lowercase = 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>
</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 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 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 id="method_pluralize">pluralize($word)</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>
</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</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 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 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 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>
</section>
<section id="footer">
<p>
<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
© 2010 - 2011 Fuel Development Team
</p>
</section>
</body>
</html>