|
| 1 | +Conventions |
| 2 | +=========== |
| 3 | + |
| 4 | +The :doc:`standards` document describes the coding standards for the Symfony2 |
| 5 | +projects and the internal and third-party bundles. This document describes |
| 6 | +coding standards and conventions used in the core framework to make it more |
| 7 | +consistent and predictable. You can follow them in your own code, but you |
| 8 | +don't need to. |
| 9 | + |
| 10 | +Method Names |
| 11 | +------------ |
| 12 | + |
| 13 | +When an object has a "main" many relation with related "things" |
| 14 | +(objects, parameters, ...), the method names are normalized: |
| 15 | + |
| 16 | + * ``get()`` |
| 17 | + * ``set()`` |
| 18 | + * ``has()`` |
| 19 | + * ``all()`` |
| 20 | + * ``replace()`` |
| 21 | + * ``remove()`` |
| 22 | + * ``clear()`` |
| 23 | + * ``isEmpty()`` |
| 24 | + * ``add()`` |
| 25 | + * ``register()`` |
| 26 | + * ``count()`` |
| 27 | + * ``keys()`` |
| 28 | + |
| 29 | +The usage of these methods are only allowed when it is clear that there |
| 30 | +is a main relation: |
| 31 | + |
| 32 | +* a ``CookieJar`` has many ``Cookie``s; |
| 33 | +
|
| 34 | +* a Service ``Container`` has many services and many parameters (as services |
| 35 | + is the main relation, we use the naming convention for this relation); |
| 36 | + |
| 37 | +* a Console ``Input`` has many arguments and many options. There is no "main" |
| 38 | + relation, and so the naming convention does not apply. |
| 39 | + |
| 40 | +For many relations where the convention does not apply, the following methods |
| 41 | +must be used instead (where ``XXX`` is the name of the related thing): |
| 42 | + |
| 43 | +============== ================= |
| 44 | +Main Relation Other Relations |
| 45 | +============== ================= |
| 46 | +``get()`` ``getXXX()`` |
| 47 | +``set()`` ``setXXX()`` |
| 48 | +``has()`` ``hasXXX()`` |
| 49 | +``all()`` ``getXXXs()`` |
| 50 | +``replace()`` ``setXXXs()`` |
| 51 | +``remove()`` ``removeXXX()`` |
| 52 | +``clear()`` ``clearXXX()`` |
| 53 | +``isEmpty()`` ``isEmptyXXX()`` |
| 54 | +``add()`` ``addXXX()`` |
| 55 | +``register()`` ``registerXXX()`` |
| 56 | +``count()`` ``countXXX()`` |
| 57 | +``keys()`` n/a |
| 58 | +============== ================= |
0 commit comments