summaryrefslogtreecommitdiff
path: root/vendor/doctrine/inflector/docs/en/index.rst
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
committerpolo <ordipolo@gmx.fr>2024-08-13 23:45:21 +0200
commitbf6655a534a6775d30cafa67bd801276bda1d98d (patch)
treec6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/inflector/docs/en/index.rst
parent94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff)
downloadAppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/inflector/docs/en/index.rst')
-rw-r--r--vendor/doctrine/inflector/docs/en/index.rst226
1 files changed, 226 insertions, 0 deletions
diff --git a/vendor/doctrine/inflector/docs/en/index.rst b/vendor/doctrine/inflector/docs/en/index.rst
new file mode 100644
index 0000000..29866f4
--- /dev/null
+++ b/vendor/doctrine/inflector/docs/en/index.rst
@@ -0,0 +1,226 @@
1Introduction
2============
3
4The Doctrine Inflector has methods for inflecting text. The features include pluralization,
5singularization, converting between camelCase and under_score and capitalizing
6words.
7
8Installation
9============
10
11You can install the Inflector with composer:
12
13.. code-block:: console
14
15 $ composer require doctrine/inflector
16
17Usage
18=====
19
20Using the inflector is easy, you can create a new ``Doctrine\Inflector\Inflector`` instance by using
21the ``Doctrine\Inflector\InflectorFactory`` class:
22
23.. code-block:: php
24
25 use Doctrine\Inflector\InflectorFactory;
26
27 $inflector = InflectorFactory::create()->build();
28
29By default it will create an English inflector. If you want to use another language, just pass the language
30you want to create an inflector for to the ``createForLanguage()`` method:
31
32.. code-block:: php
33
34 use Doctrine\Inflector\InflectorFactory;
35 use Doctrine\Inflector\Language;
36
37 $inflector = InflectorFactory::createForLanguage(Language::SPANISH)->build();
38
39The supported languages are as follows:
40
41- ``Language::ENGLISH``
42- ``Language::FRENCH``
43- ``Language::NORWEGIAN_BOKMAL``
44- ``Language::PORTUGUESE``
45- ``Language::SPANISH``
46- ``Language::TURKISH``
47
48If you want to manually construct the inflector instead of using a factory, you can do so like this:
49
50.. code-block:: php
51
52 use Doctrine\Inflector\CachedWordInflector;
53 use Doctrine\Inflector\RulesetInflector;
54 use Doctrine\Inflector\Rules\English;
55
56 $inflector = new Inflector(
57 new CachedWordInflector(new RulesetInflector(
58 English\Rules::getSingularRuleset()
59 )),
60 new CachedWordInflector(new RulesetInflector(
61 English\Rules::getPluralRuleset()
62 ))
63 );
64
65Adding Languages
66----------------
67
68If you are interested in adding support for your language, take a look at the other languages defined in the
69``Doctrine\Inflector\Rules`` namespace and the tests located in ``Doctrine\Tests\Inflector\Rules``. You can copy
70one of the languages and update the rules for your language.
71
72Once you have done this, send a pull request to the ``doctrine/inflector`` repository with the additions.
73
74Custom Setup
75============
76
77If you want to setup custom singular and plural rules, you can configure these in the factory:
78
79.. code-block:: php
80
81 use Doctrine\Inflector\InflectorFactory;
82 use Doctrine\Inflector\Rules\Pattern;
83 use Doctrine\Inflector\Rules\Patterns;
84 use Doctrine\Inflector\Rules\Ruleset;
85 use Doctrine\Inflector\Rules\Substitution;
86 use Doctrine\Inflector\Rules\Substitutions;
87 use Doctrine\Inflector\Rules\Transformation;
88 use Doctrine\Inflector\Rules\Transformations;
89 use Doctrine\Inflector\Rules\Word;
90
91 $inflector = InflectorFactory::create()
92 ->withSingularRules(
93 new Ruleset(
94 new Transformations(
95 new Transformation(new Pattern('/^(bil)er$/i'), '\1'),
96 new Transformation(new Pattern('/^(inflec|contribu)tors$/i'), '\1ta')
97 ),
98 new Patterns(new Pattern('singulars')),
99 new Substitutions(new Substitution(new Word('spins'), new Word('spinor')))
100 )
101 )
102 ->withPluralRules(
103 new Ruleset(
104 new Transformations(
105 new Transformation(new Pattern('^(bil)er$'), '\1'),
106 new Transformation(new Pattern('^(inflec|contribu)tors$'), '\1ta')
107 ),
108 new Patterns(new Pattern('noflect'), new Pattern('abtuse')),
109 new Substitutions(
110 new Substitution(new Word('amaze'), new Word('amazable')),
111 new Substitution(new Word('phone'), new Word('phonezes'))
112 )
113 )
114 )
115 ->build();
116
117No operation inflector
118----------------------
119
120The ``Doctrine\Inflector\NoopWordInflector`` may be used to configure an inflector that doesn't perform any operation for
121pluralization and/or singularization. If will simply return the input as output.
122
123This is an implementation of the `Null Object design pattern <https://sourcemaking.com/design_patterns/null_object>`_.
124
125.. code-block:: php
126
127 use Doctrine\Inflector\Inflector;
128 use Doctrine\Inflector\NoopWordInflector;
129
130 $inflector = new Inflector(new NoopWordInflector(), new NoopWordInflector());
131
132Tableize
133========
134
135Converts ``ModelName`` to ``model_name``:
136
137.. code-block:: php
138
139 echo $inflector->tableize('ModelName'); // model_name
140
141Classify
142========
143
144Converts ``model_name`` to ``ModelName``:
145
146.. code-block:: php
147
148 echo $inflector->classify('model_name'); // ModelName
149
150Camelize
151========
152
153This method uses `Classify`_ and then converts the first character to lowercase:
154
155.. code-block:: php
156
157 echo $inflector->camelize('model_name'); // modelName
158
159Capitalize
160==========
161
162Takes a string and capitalizes all of the words, like PHP's built-in
163``ucwords`` function. This extends that behavior, however, by allowing the
164word delimiters to be configured, rather than only separating on
165whitespace.
166
167Here is an example:
168
169.. code-block:: php
170
171 $string = 'top-o-the-morning to all_of_you!';
172
173 echo $inflector->capitalize($string); // Top-O-The-Morning To All_of_you!
174
175 echo $inflector->capitalize($string, '-_ '); // Top-O-The-Morning To All_Of_You!
176
177Pluralize
178=========
179
180Returns a word in plural form.
181
182.. code-block:: php
183
184 echo $inflector->pluralize('browser'); // browsers
185
186Singularize
187===========
188
189Returns a word in singular form.
190
191.. code-block:: php
192
193 echo $inflector->singularize('browsers'); // browser
194
195Urlize
196======
197
198Generate a URL friendly string from a string of text:
199
200.. code-block:: php
201
202 echo $inflector->urlize('My first blog post'); // my-first-blog-post
203
204Unaccent
205========
206
207You can unaccent a string of text using the ``unaccent()`` method:
208
209.. code-block:: php
210
211 echo $inflector->unaccent('año'); // ano
212
213Legacy API
214==========
215
216The API present in Inflector 1.x is still available, but will be deprecated in a future release and dropped for 3.0.
217Support for languages other than English is available in the 2.0 API only.
218
219Acknowledgements
220================
221
222The language rules in this library have been adapted from several different sources, including but not limited to:
223
224- `Ruby On Rails Inflector <http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html>`_
225- `ICanBoogie Inflector <https://github.com/ICanBoogie/Inflector>`_
226- `CakePHP Inflector <https://book.cakephp.org/3.0/en/core-libraries/inflector.html>`_