{"id":13883371,"url":"https://github.com/mmoreram/ControllerExtraBundle","last_synced_at":"2025-07-16T19:30:27.386Z","repository":{"id":12514679,"uuid":"15184442","full_name":"mmoreram/ControllerExtraBundle","owner":"mmoreram","description":"Controller extra Bundle for Symfony2","archived":false,"fork":false,"pushed_at":"2018-01-05T16:39:54.000Z","size":500,"stargazers_count":153,"open_issues_count":7,"forks_count":17,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-05-02T01:26:53.804Z","etag":null,"topics":["annotation","controller","mapping","php","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmoreram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-14T11:14:16.000Z","updated_at":"2023-07-21T20:36:23.000Z","dependencies_parsed_at":"2022-09-16T23:40:42.695Z","dependency_job_id":null,"html_url":"https://github.com/mmoreram/ControllerExtraBundle","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoreram%2FControllerExtraBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoreram%2FControllerExtraBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoreram%2FControllerExtraBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoreram%2FControllerExtraBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmoreram","download_url":"https://codeload.github.com/mmoreram/ControllerExtraBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226038841,"owners_count":17564046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation","controller","mapping","php","symfony"],"created_at":"2024-08-06T09:01:26.107Z","updated_at":"2024-11-24T11:30:49.085Z","avatar_url":"https://github.com/mmoreram.png","language":"PHP","funding_links":[],"categories":["PHP","Development"],"sub_categories":[],"readme":"# ControllerExtra for Symfony2\n\n[![Build Status](https://travis-ci.org/mmoreram/ControllerExtraBundle.png?branch=master)](https://travis-ci.org/mmoreram/ControllerExtraBundle)\n\nThis bundle provides a collection of annotations for Symfony2 Controllers,\ndesigned to streamline the creation of certain objects and enable smaller and\nmore concise actions.\n\nTable of contents\n-----\n1. [Reference](#reference)\n1. [Entity Provider](#entity-provider)\n    * [By namespace](#by-namespace)\n    * [By doctrine shortcut](#by-doctrine-shortcut)\n    * [By parameter](#by-parameter)\n1. [Controller Annotations](#controller-annotations)\n    * [@CreatePaginator](#-createpaginator)\n        * [Paginator Entity](#paginator-entity)\n        * [Paginator Page](#paginator-page)\n        * [Paginator Limit](#paginator-limit)\n        * [Paginator OrderBy](#paginator-orderby)\n        * [Paginator Wheres](#paginator-wheres)\n        * [Paginator Left Joins](#paginator-left-joins)\n        * [Paginator Inner Joins](#paginator-inner-joins)\n        * [Paginator Not Nulls](#paginator-not-nulls)\n        * [Paginator Attributes](#paginator-attributes)\n        * [Paginator Example](#paginator-example)\n        * [Pagerfanta Add-on](#pagerfanta-add-on)\n        * [KNPPaginator Add-on](#knppaginator-add-on)\n    * [@LoadEntity](#-loadentity)\n        * [Entity Mapping](#entity-mapping)\n        * [Entity Mapping fallback](#entity-mapping-fallback)\n        * [Entity Repository](#entity-repository)\n        * [Entity Factory](#entity-factory)\n    * [@CreateForm](#-createform)\n    * [@Flush](#-flush)\n    * [@ToJsonResponse](#-tojsonresponse)\n    * [@Log](#-log)\n    * [@Get](#-get)\n    * [@Post](#-post)\n1. [Custom annotations](#custom-annotations)\n    * [Annotation](#annotation)\n    * [Resolver](#resolver)\n    * [Definition](#definition)\n    * [Registration](#registration)\n\n# Reference\n\nBy default, all annotations are loaded, but any individual annotation can be\ncompletely disabled by setting to false `active` parameter.\n\nDefault values are:\n\n``` yml\ncontroller_extra:\n    resolver_priority: -8\n    request: current\n    paginator:\n        active: true\n        default_name: paginator\n        default_page: 1\n        default_limit_per_page: 10\n    entity:\n        active: true\n        default_name: entity\n        default_persist: true\n        default_mapping_fallback: false\n        default_factory_method: create\n        default_factory_mapping: true\n    form:\n        active: true\n        default_name: form\n    object_manager:\n        active: true\n        default_name: form\n    flush:\n        active: true\n        default_manager: default\n    json_response:\n        active: true\n        default_status: 200\n        default_headers: []\n    log:\n        active: true\n        default_level: info\n        default_execute: pre\n```\n\n\u003e ResolverEventListener is subscribed to `kernel.controller` event with \n\u003e priority -8. This element can be configured and customized with \n\u003e `resolver_priority` config value. If you need to get ParamConverter entities,\n\u003e make sure that this value is lower than 0. The reason is that this listener\n\u003e must be executed always after ParamConverter one.\n\n# Entity provider\n\nIn some annotations, you can define an entity by several ways. This chapter is\nabout how you can define them.\n\n## By namespace\n\nYou can define an entity using its namespace. A simple new `new()` be performed.\n\n``` php\n/**\n * Simple controller method\n *\n * @SomeAnnotation(\n *      class = \"Mmoreram\\CustomBundle\\Entity\\MyEntity\",\n * )\n */\npublic function indexAction()\n{\n}\n```\n\n## By doctrine shortcut\n\nYou can define an entity using Doctrine shortcut notations. With this format\nyou should ensure that your Entities follow Symfony Bundle standards and your\nentities are placed under `Entity/` folder.\n\n``` php\n/**\n * Simple controller method\n *\n * @SomeAnnotation(\n *      class = \"MmoreramCustomBundle:MyEntity\",\n * )\n */\npublic function indexAction()\n{\n}\n```\n\n## By parameter\n\nYou can define an entity using a simple config parameter. Some projects\nuse parameters to define all entity namespaces (To allow overriding). If you\ndefine the entity with a parameter, this bundle will try to instance it\nwith a simple `new()` accessing directly to the container ParametersBag.\n\n``` yml\nparameters:\n\n    #\n    # Entities\n    #\n    my.bundle.entity.myentity: Mmoreram\\CustomBundle\\Entity\\MyEntity\n```\n\n``` php\n/**\n * Simple controller method\n *\n * @SomeAnnotation(\n *      class = \"my.bundle.entity.myentity\",\n * )\n */\npublic function indexAction()\n{\n}\n```\n\n# Controller annotations\n\nThis bundle provide a reduced but useful set of annotations for your controller\nactions.\n\n## @CreatePaginator\n\nCreates a Doctrine Paginator object, given a request and a configuration. This\nannotation just injects into de controller a new\n`Doctrine\\ORM\\Tools\\Pagination\\Pagination` instance ready to be iterated.\n\nYou can enable/disable this bundle by overriding `active` flag in configuration file\n`config.yml`\n\n``` yml\ncontroller_extra:\n    pagination:\n        active: true\n```\n\n\u003e By default, if `name` option is not set, the generated object will be placed\n\u003e in a parameter named `$paginator`. This behaviour can be configured using\n\u003e `default_name` in configuration.\n\nThis annotation can be configured with these sections\n\n### Paginator Entity\n\nTo create a new Pagination object you need to refer to an existing Entity. You\ncan check all available formats you can define it just reading the\n[Entity Provider](#entity-provider) section.\n\n``` php\n\u003c?php\n\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\n### Paginator page\n\nYou need to specify Paginator annotation the page to fetch. By default, if none\nis specified, this bundle will use the default one defined in configuration. You\ncan override in `config.yml`\n\n``` yml\ncontroller_extra:\n    pagination:\n        default_page: 1\n```\n\nYou can refer to an existing Request attribute using `~value~` format, to any\n`$_GET` element by using format `?field?` or to any `$_POST` by using format\n`#field#`\n\n\u003e You can choose between Master Request or Current Request accessing to its\n\u003e attributes, by configuring the request value of the configuration.\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/{foo}\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      page = \"~foo~\"\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\nor you can hardcode the page to use.\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      page = 1\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\n### Paginator limit\n\nYou need to specify Paginator annotation the limit to fetch. By default, if none\nis specified, this bundle will use the default one defined in configuration. You\ncan override in `config.yml`\n\n``` yml\ncontroller_extra:\n    pagination:\n        default_limit_per_page: 10\n```\n\nYou can refer to an existing Request attribute using `~value~` format, to any\n`$_GET` element by using format `?field?` or to any `$_POST` by using format\n`#field#`\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/{foo}/{limit}\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      page = \"~foo~\",\n *      limit = \"~limit~\"\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\nor you can hardcode the page to use.\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      page = 1,\n *      limit = 10\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\n### Paginator OrderBy\n\nYou can order your Pagination just defining the fields you want to orderBy and\nthe desired direction. The `orderBy` section must be defined as an array of\narrays, and each array should contain these positions:\n\n* First position: Entity alias (Principal object is set as `x`)\n* Second position: Entity field\n* Third position: Direction\n* Fourth position: Custom direction map ***(optional)***\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      orderBy = {\n *          {\"x\", \"createdAt\", \"ASC\"},\n *          {\"x\", \"updatedAt\", \"DESC\"},\n *          {\"x\", \"id\", 1, {\n *              0 =\u003e \"ASC\",\n *              1 =\u003e \"DESC\",\n *          }},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\nWith the third and fourth value you can define a map where to match your own\ndirection nomenclature with DQL one. DQL nomenclature just accept ASC for\nAscendant and DESC for Descendant.\n\nThis is very useful when you need to match a url format with the DQL one. You\ncan refer to an existing Request attribute using `~value~` format, to any\n`$_GET` element by using format `?field?` or to any `$_POST` by using format\n`#field#`\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/order/{field}/{direction}\n *\n * For example, some matchings...\n *\n * /myroute/paginate/order/id/1 -\u003e ORDER BY id DESC\n * /myroute/paginate/order/enabled/0 - ORDER BY enabled ASC\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      orderBy = {\n *          {\"x\", \"createdAt\", \"ASC\"},\n *          {\"x\", \"updatedAt\", \"DESC\"},\n *          {\"x\", \"~field~\", ~direction~, {\n *              0 =\u003e \"ASC\",\n *              1 =\u003e \"DESC\",\n *          }},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\nThe order of the definitions will alter the order of the DQL query.\n\n### Paginator Wheres\n\nYou can define some where statements in your Paginator. The `wheres` section\nmust be defined as an array of arrays, and each array should contain these\npositions:\n\n* First position: Entity alias (Principal object is set as `x`)\n* Second position: Entity field\n* Third position: Operator *=, \u003c=, \u003e, LIKE...*\n* Fourth position: Value to compare with\n* Fifth position: Is a filter. By default, false\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      wheres = {\n *          {\"x\", \"enabled\", \"=\", true},\n *          {\"x\", \"age\", \"\u003e\", 18},\n *          {\"x\", \"name\", \"LIKE\", \"Eferv%\"},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\nYou can refer to an existing Request attribute using `~value~` format, to any\n`$_GET` element by using format `?field?` or to any `$_POST` by using format\n`#field#`\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/{field}\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      wheres = {\n *          {\"x\", \"name\", \"LIKE\", \"~field~\"},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\nYou can use as well this feature for optional filtering by setting the last\nposition to `true`. In that case, if the filter value is not found, such line\nwill be ignored.\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute?query=name%\n * This Controller matches pattern /myroute as well\n *\n * In both cases this will work. In the first case we will apply the where line\n * in the paginator. In the second case, we wont.\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      wheres = {\n *          {\"x\", \"name\", \"LIKE\", \"?query?\", true},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\n### Paginator Not Nulls\n\nYou can also define some fields to not null. Is same as `wheres` section, but\nspecific for NULL assignments. The `notNulls` section must be defined as an array\nof arrays, and each array should contain these positions:\n\n* First position: Object (Principal object is set as `x`)\n* Second position: Field\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      notNulls = {\n *          {\"x\", \"enabled\"},\n *          {\"x\", \"deleted\"},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\n### Paginator Left Join\n\nYou can do some left joins in this section. The `leftJoins` section must be\ndefined as an array of array, where each array can have these fields:\n\n* First position: Entity alias (Principal object is set as `x`)\n* Second position: Entity relation (Address)\n* Third position: Relation identifier (a)\n* Fourth position: If true, this relation is added in select group. Otherwise, wont\nbe loaded until its request ***(optional)***\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      leftJoins = {\n *          {\"x\", \"User\", \"u\", true},\n *          {\"x\", \"Address\", \"a\", true},\n *          {\"x\", \"Cart\", \"c\"},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\n### Paginator Inner Join\n\nYou can do some inner joins in this section. The `innerJoins` section must be\ndefined as an array of array, where each array can have these fields:\n\n* First position: Entity alias (x)\n* Second position: Entity relation (Address)\n* Third position: Relation identifier (a)\n* Fourth position: If true, this relation is added in select group. Otherwise, wont\nbe loaded until its request ***(optional)***\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      innerJoins = {\n *          {\"x\", \"User\", \"u\", true},\n *          {\"x\", \"Address\", \"a\", true},\n *          {\"x\", \"Cart\", \"c\"},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\n### Paginator Attributes\n\nA nice feature of this annotation is that you can also inject into your\ncontroller a `Mmoreram\\ControllerExtraBundle\\ValueObject\\PaginatorAttributes`\ninstance with some interesting information about your pagination.\n\n* currentPage : Current page fetched\n* totalElements : Total elements given your criteria. If none criteria is\ndefined in your configuration, this value will show all elements of a certain entity.\n* totalPages : Total pages you can fetch given a criteria.\n* limitPerPage: Maximum number of elements in each page.\n\nTo inject this object you need to define the \"attributes\" annotation field with\nthe method parameter name.\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\nuse Mmoreram\\ControllerExtraBundle\\ValueObject\\PaginatorAttributes;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/\n *\n * @CreatePaginator(\n *      attributes = \"paginatorAttributes\",\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      page = 1,\n *      limit = 10\n * )\n */\npublic function indexAction(\n    Paginator $paginator,\n    PaginatorAttributes $paginatorAttributes\n)\n{\n    $currentPage = $paginatorAttributes-\u003egetCurrentPage();\n    $totalElements = $paginatorAttributes-\u003egetTotalElements();\n    $totalPages = $paginatorAttributes-\u003egetTotalPages();\n    $limitPerPage = $paginatorAttributes-\u003egetLimitPerPage();\n\n}\n```\n\n### Paginator Example\n\nThis is a completed example and its DQL resolution\n\n``` php\nuse Doctrine\\ORM\\Tools\\Pagination\\Pagination;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /paginate/nb/{limit}/{page}\n *\n * Where:\n *\n * * limit = 10\n * * page = 1\n *\n * @CreatePaginator(\n *      entityNamespace = \"ControllerExtraBundle:Fake\",\n *      page = \"~page~\",\n *      limit = \"~limit~\",\n *      orderBy = {\n *          { \"x\", \"createdAt\", \"ASC\" },\n *          { \"x\", \"updatedAt\", \"DESC\" },\n *          { \"x\", \"id\", \"0\", {\n *              \"1\" = \"ASC\",\n *              \"2\" = \"DESC\",\n *          }}\n *      },\n *      wheres = {\n *          { \"x\", \"enabled\" , \"=\", true }\n *      },\n *      leftJoins = {\n *          { \"x\", \"relation\", \"r\" },\n *          { \"x\", \"relation2\", \"r2\" },\n *          { \"x\", \"relation5\", \"r5\", true },\n *      },\n *      innerJoins = {\n *          { \"x\", \"relation3\", \"r3\" },\n *          { \"x\", \"relation4\", \"r4\", true },\n *      },\n *      notNulls = {\n *          {\"x\", \"address1\"},\n *          {\"x\", \"address2\"},\n *      }\n * )\n */\npublic function indexAction(Paginator $paginator)\n{\n}\n```\n\nThe DQL generated by this annotation is\n\n``` sql\n    SELECT x, r4, r5\n    FROM Mmoreram\\\\ControllerExtraBundle\\\\Tests\\\\FakeBundle\\\\Entity\\\\Fake x\n\n    INNER JOIN x.relation3 r3\n    INNER JOIN x.relation4 r4\n\n    LEFT JOIN x.relation r\n    LEFT JOIN x.relation2 r2\n    LEFT JOIN x.relation5 r5\n\n    WHERE enabled = ?where0\n    AND x.address1 IS NOT NULL\n    AND x.address2 IS NOT NULL\n\n    ORDER BY createdAt ASC, id ASC\n```\n\n### PagerFanta Add-on\n\nThis annotation can create a PagerFanta instance if you need it. You only have\nto define your parameter as such, and the annotation resolver will wrap your\npaginator with a Pagerfanta object instance.\n\n``` php\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\nuse Pagerfanta\\Pagerfanta;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      page = 1,\n *      limit = 10\n * )\n */\npublic function indexAction(Pagerfanta $paginator)\n{\n}\n```\n\n### KNPPaginator Add-on\nThis annotation can create a KNPPaginator instance if you need it. You only have\nto define your parameter as such, and the annotation resolver will wrap your\npaginator with a KNPPaginator object instance.\n``` php\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreatePaginator;\nuse Knp\\Component\\Pager\\Pagination\\PaginationInterface;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /myroute/paginate/\n *\n * @CreatePaginator(\n *      entityNamespace = \"MmoreramCustomBundle:User\",\n *      page = 1,\n *      limit = 10\n * )\n */\npublic function indexAction(PaginationInterface $paginator)\n{\n}\n```\n\n## @LoadEntity\n\nLoads an entity from your database, or creates a new one.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Entity;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @Entity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      name  = \"user\"\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\n\u003e By default, if `name` option is not set, the generated object will be placed\n\u003e in a parameter named `$entity`. This behaviour can be configured using\n\u003e `default_name` in configuration.\n\nYou can also use setters in Entity annotation. It means that you can simply call\nentity setters using Request attributes.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Entity;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\Address;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @Entity(\n *      namespace = \"MmoreramCustomBundle:Address\",\n *      name  = \"address\"\n * )\n * @Entity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      name  = \"user\",\n *      setters = {\n *          \"setAddress\": \"address\"\n *      }\n * )\n */\npublic function indexAction(Address $address, User $user)\n{\n}\n```\n\nWhen `User` instance is built, method `setAddress` is called using as parameter\nthe new `Address` instance.\n\nNew entities are just created with a simple `new()`, so they are not persisted.\nBy default, they will be persisted using configured manager, but you can disable\nthis feature using `persist` option.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Entity;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @Entity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      name  = \"user\",\n *      persist = false\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\n### Entity Mapping\n\nWhen you define a new Entity annotation, you can also request the mapped entity\ngiven a map. It means that if a map is defined, this bundle will try to request\nthe mapped instance satisfying it.\n\nThe keys of the map represent the names of the mapped fields and the values\nrepresent their desired values. Remember than you can refer to any Request\nattribute by using format `~field~`, to any `$_GET` element by using format\n`?field?` or to any `$_POST` by using format `#field#`\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Entity;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /user/edit/{id}/{username}\n *\n * @Entity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      name  = \"user\",\n *      mapping = {\n *          \"id\": \"~id~\",\n *          \"username\": \"~username~\"\n *      }\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\nIn this case, you will try to get the mapped instance of User with passed id. If\nsome mapping is defined and any entity is found, a new EntityNotFoundException`\nis thrown.\n\n### Entity Mapping Fallback\n\nSo what if one ore more than one mapping references are not found? For example,\nyou're trying to map the {id} parameter from your route, but this parameter is\nnot even defined. Whan happens here? Well, you can assume then that you want to\npass a new entity instance by using the *mappingFallback*.\n\n\u003e By default, if `mapping_fallback` option is not set, the used value will be\n\u003e the parameter `default_mapping_fallback` defined in configuration. By default\n\u003e this value is `false`\n\nDon't confuse with the scenario where you're looking for an entity in your\ndatabase, all mapping references have been resolved, and the entity is not\nfound. In that case, a common \"EntityNotFound\" exception will be thrown by\nDoctrine.\n\nLets see an example. Because we have enabled the mappingFallback, and because\nthe mapping definition does not match the assigned route, we will return a new\nempty User entity.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Entity;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * This Controller matches pattern /user/edit/{id}\n *\n * @LoadEntity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      name  = \"user\",\n *      mapping = {\n *          \"id\": \"~id~\",\n *          \"username\": \"~nonexisting~\"\n *      },\n *      mappingFallback = true\n * )\n */\npublic function indexAction(User $user)\n{\n    // $user-\u003egetId() === null\n}\n```\n\n### Entity Repository\n\nBy default, the Doctrine entity manager provides the right repository per each\nentity (not the default one, but the right specific one). Although, you can\ndefine a custom repository to be used in your annotation by using the repository\nconfiguration.\n\n``` php\n/**\n * Simple controller method\n *\n * @CreateEntity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      mapping = {\n *          \"id\": \"~id~\",\n *          \"username\": \"~username~\"\n *      }\n *      repository = {\n *          \"class\" = \"Mmoreram\\CustomBundle\\Repository\\AnotherRepository\",\n *      },\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\nBy default, the method *findOneBy* will always be used, unless you define\nanother one.\n\n``` php\n/**\n * Simple controller method\n *\n * @CreateEntity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      mapping = {\n *          \"id\": \"~id~\",\n *          \"username\": \"~username~\"\n *      }\n *      repository = {\n *          \"class\" = \"Mmoreram\\CustomBundle\\Repository\\AnotherRepository\",\n *          \"method\" = \"find\",\n *      },\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\n### Entity Factory\n\nWhen the annotation considers that a new entity must be created, because no\nmapping information has been provided, or because the mapping fallback has been\nactivated, by default a new instance will be created by using the *namespace*\nvalue.\n\nThis configuration block has three positions\n\n* class - factory class\n* method - Method to use when retrieving the object\n* static - Method is static\n\nYou can define the factory with a simple namespace\n\n``` php\n/**\n * Simple controller method\n *\n * @CreateEntity(\n *      namespace = \"MmoreramCustomBundle:User\",\n *      factory = {\n *          \"class\" = \"Mmoreram\\CustomBundle\\Factory\\UserFactory\",\n *          \"method\" = \"create\",\n *          \"static\" = true,\n *      },\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\nIf you want to define your Factory as a service, with the possibility of\noverriding namespace, you can simply define service name. All other options have\nthe same behaviour.\n\n``` yml\nparameters:\n\n    #\n    # Factories\n    #\n    my.bundle.factory.user_factory: Mmoreram\\CustomBundle\\Factory\\UserFactory\n```\n\n``` php\n/**\n * Simple controller method\n *\n * @CreateEntity(\n *      class = {\n *          \"factory\" = my.bundle.factory.user_factory,\n *          \"method\" = \"create\",\n *          \"static\" = true,\n *      },\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\nIf you do not define the `method`, default one will be used. You can\noverride this default value by defining new one in your `config.yml`. Same with\n`static` value\n\n``` yml\ncontroller_extra:\n    entity:\n        default_factory_method: create\n        default_factory_static: true\n```\n\n## @CreateForm\n\nProvides form injection in your controller actions. This annotation only needs\na name to be defined in, where you must define namespace where your form is\nplaced.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreateForm;\nuse Symfony\\Component\\Form\\AbstractType;\n\n/**\n * Simple controller method\n *\n * @CreateForm(\n *      class = \"\\Mmoreram\\CustomBundle\\Form\\Type\\UserType\",\n *      name  = \"userType\"\n * )\n */\npublic function indexAction(AbstractType $userType)\n{\n}\n```\n\n\u003e By default, if `name` option is not set, the generated object will be placed\n\u003e in a parameter named `$form`. This behaviour can be configured using\n\u003e `default_name` in configuration.\n\nYou can not just define your Type location using the namespace, in which case\na new AbstractType element will be created. but you can also define it using\nservice alias, in which case this bundle will return an instance using Symfony\nDI.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreateForm;\nuse Symfony\\Component\\Form\\AbstractType;\n\n/**\n * Simple controller method\n *\n * @CreateForm(\n *      class = \"user_type\",\n *      name  = \"userType\"\n * )\n */\npublic function indexAction(AbstractType $userType)\n{\n}\n```\n\nThis annotation allows you to not only create an instance of FormType, but\nalso allows you to inject a Form object or a FormView object\n\nTo inject a Form object you only need to cast method value as such.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreateForm;\nuse Symfony\\Component\\Form\\Form;\n\n/**\n * Simple controller method\n *\n * @CreateForm(\n *      class = \"user_type\",\n *      name  = \"userForm\"\n * )\n */\npublic function indexAction(Form $userForm)\n{\n}\n```\n\nYou can also, using [SensioFrameworkExtraBundle][1]'s [ParamConverter][2],\ncreate a Form object with an previously created entity. you can define this\nentity using `entity` parameter.\n\n``` php\n\u003c?php\n\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route;\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter;\nuse Symfony\\Component\\Form\\Form;\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreateForm;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @Route(\n *      path = \"/user/{id}\",\n *      name = \"view_user\"\n * )\n * @ParamConverter(\"user\", class=\"MmoreramCustomBundle:User\")\n * @CreateForm(\n *      class  = \"user_type\",\n *      entity = \"user\"\n *      name   = \"userForm\",\n * )\n */\npublic function indexAction(User $user, Form $userForm)\n{\n}\n```\n\nTo handle current request, you can set `handleRequest` to true. By default\nthis value is set to `false`\n\n\n``` php\n\u003c?php\n\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route;\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter;\nuse Symfony\\Component\\Form\\Form;\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreateForm;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @Route(\n *      path = \"/user/{id}\",\n *      name = \"view_user\"\n * )\n * @ParamConverter(\"user\", class=\"MmoreramCustomBundle:User\")\n * @CreateForm(\n *      class         = \"user_type\",\n *      entity        = \"user\"\n *      handleRequest = true,\n *      name          = \"userForm\",\n * )\n */\npublic function indexAction(User $user, Form $userForm)\n{\n}\n```\n\nYou can also add as a method parameter if the form is valid, using `validate`\nsetting. Annotation will place result of `$form-\u003eisValid()` in specified method\nargument.\n\n``` php\n\u003c?php\n\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route;\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter;\nuse Symfony\\Component\\Form\\Form;\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreateForm;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @Route(\n *      path = \"/user/{id}\",\n *      name = \"view_user\"\n * )\n * @ParamConverter(\"user\", class=\"MmoreramCustomBundle:User\")\n * @CreateForm(\n *      class         = \"user_type\",\n *      entity        = \"user\"\n *      handleRequest = true,\n *      name          = \"userForm\",\n *      validate      = \"isValid\",\n * )\n */\npublic function indexAction(User $user, Form $userForm, $isValid)\n{\n}\n```\n\nTo inject a FormView object you only need to cast method variable as such.\n\n``` php\n\u003c?php\n\nuse Symfony\\Component\\Form\\FormView;\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\CreateForm;\n\n/**\n * Simple controller method\n *\n * @CreateForm(\n *      class = \"user_type\",\n *      name  = \"userFormView\"\n * )\n */\npublic function indexAction(FormView $userFormView)\n{\n}\n```\n\n## @Flush\n\nFlush annotation allows you to flush entityManager at the end of request using\nkernel.response event\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Flush;\n\n/**\n * Simple controller method\n *\n * @Flush\n */\npublic function indexAction()\n{\n}\n```\n\nIf not otherwise specified, default Doctrine Manager will be flushed with this\nannotation. You can overwrite default Manager in your `config.yml` file.\n\n``` yml\ncontroller_extra:\n    flush:\n        default_manager: my_custom_manager\n```\n\nYou can also override this value in every single Flush Annotation\ninstance defining `manager` value\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Flush;\n\n/**\n * Simple controller method\n *\n * @Flush(\n *      manager = \"my_own_manager\"\n * )\n */\npublic function indexAction()\n{\n}\n```\n\nIf you want to change default manager in all annotation instances, you should\noverride bundle parameter in your `config.yml` file.\n\n``` yml\ncontroller_extra:\n    flush:\n        default_manager: my_own_manager\n```\n\nIf any parameter is set, annotation will flush all. If you only need to flush\none or many entities, you can define explicitly which entity must be flushed.\n\n``` php\n\u003c?php\n\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter;\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Flush;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @ParamConverter(\"user\", class=\"MmoreramCustomBundle:User\")\n * @Flush(\n *      entity = \"user\"\n * )\n */\npublic function indexAction(User $user)\n{\n}\n```\n\nYou can also define a set of entities to flush\n\n``` php\n\u003c?php\n\nuse Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\ParamConverter;\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Flush;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\Address;\nuse Mmoreram\\ControllerExtraBundle\\Entity\\User;\n\n/**\n * Simple controller method\n *\n * @ParamConverter(\"user\", class=\"MmoreramCustomBundle:User\")\n * @ParamConverter(\"address\", class=\"MmoreramCustomBundle:Address\")\n * @Flush(\n *      entity = {\n *          \"user\", \n *          \"address\"\n *      }\n * )\n */\npublic function indexAction(User $user, Address $address)\n{\n}\n```\n\n\u003e If multiple @Mmoreram\\Flush are defined in same action, last instance will\n\u003e overwrite previous. Anyway just one instance should be defined.\n\n## @ToJsonResponse\n\nJsonResponse annotation allows you to create a \n`Symfony\\Component\\HttpFoundation\\JsonResponse` object, given a simple\ncontroller return value. \n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\ToJsonResponse;\n\n/**\n * Simple controller method\n *\n * @ToJsonResponse\n */\npublic function indexAction(User $user, Address $address)\n{\n    return array(\n        'This is my response'\n    );\n}\n```\n\nBy default, JsonResponse is created using default `status` and `headers` defined\nin bundle parameters. You can overwrite them in your `config.yml` file.\n\n``` yml\ncontroller_extra:\n    json_response:\n        default_status: 403\n        default_headers:\n            \"User-Agent\": \"Googlebot/2.1\"\n```\n\nYou can also overwrite these values in each `@JsonResponse` annotation.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\ToJsonResponse;\n\n/**\n * Simple controller method\n *\n * @ToJsonResponse(\n *      status = 403,\n *      headers = {\n *          \"User-Agent\": \"Googlebot/2.1\"\n *      }\n * )\n */\npublic function indexAction(User $user, Address $address)\n{\n    return array(\n        'This is my response'\n    );\n}\n```\n\nIf an Exception is returned the response status is set by default to 500 and the\nException message is returned as response.\n\n`STATUS 500 Internal server error`\n\n``` json\n{\n    message : 'Exception message'\n}\n\n```\n\nIn case we use a HttpExceptionInterface the use the exception status code as\nstatus code. In case we launch this exception\n\n``` php\nuse Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException;\n\n...\n\nreturn new NotFoundHttpException('Resource not found');\n```\n\nWe'll receive this response\n\n`STATUS 404 Not Found`\n\n``` json\n{\n    message : 'Resource not found'\n}\n\n```\n\n\u003e If the exception is being launched on an annotation (e.g. Entity annotation)\n\u003e remember to add the JsonResponse annotation at the beginning or at least before\n\u003e any annotation that could cause an exception.\n\n\u003e If multiple @Mmoreram\\JsonResponse are defined in same action, last instance \n\u003e will overwrite previous. Anyway just one instance should be defined.\n\n## @Log\n\nLog annotation allows you to log any plain message before or after controller\naction execution\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Log;\n\n/**\n * Simple controller method\n *\n * @Log(\"Executing index Action\")\n */\npublic function indexAction()\n{\n}\n```\n\nYou can define the level of the message. You can define default one if none is\nspecified overriding it in your `config.yml` file.\n\n``` yml\ncontroller_extra:\n    log:\n        default_level: warning\n```\n\nEvery Annotation instance can overwrite this value using `level` field.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Log;\n\n/**\n * Simple controller method\n *\n * @Log(\n *      value   = \"Executing index Action\",\n *      level   = @Log::LVL_WARNING\n * )\n */\npublic function indexAction()\n{\n}\n```\n\nSeveral levels can be used, as defined in [Psr\\Log\\LoggerInterface][6]\ninterface\n\n* @Mmoreram\\Log::LVL_EMERG\n* @Mmoreram\\Log::LVL_CRIT\n* @Mmoreram\\Log::LVL_ERR\n* @Mmoreram\\Log::LVL_WARN\n* @Mmoreram\\Log::LVL_NOTICE\n* @Mmoreram\\Log::LVL_INFO\n* @Mmoreram\\Log::LVL_DEBUG\n* @Mmoreram\\Log::LVL_LOG\n\n\nYou can also define the execution of the log. You can define default one if\nnone is specified overriding it in your `config.yml` file.\n\n``` yml\ncontroller_extra:\n    log:\n        default_execute: pre\n```\n\nEvery Annotation instance can overwrite this value using `level` field.\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Log;\n\n/**\n * Simple controller method\n *\n * @Log(\n *      value   = \"Executing index Action\",\n *      execute = @Log::EXEC_POST\n * )\n */\npublic function indexAction()\n{\n}\n```\n\nSeveral executions can be used,\n\n* @Mmoreram\\Log::EXEC_PRE - Logged before controller execution\n* @Mmoreram\\Log::EXEC_POST - Logged after controller execution\n* @Mmoreram\\Log::EXEC_BOTH - Logged both\n\n## @Get\n\nThe Get annotation allows you to get any parameter from the request query string.\n\nFor a `GET` request like:\n\n```\nGET /my-page?foo=bar HTTP/1.1\n```\n\nYou can can simply get the `foo` var using the `GET` annotation\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Get;\n\n/**\n * Simple controller method\n *\n * @Get(\n *     path = \"foo\"\n * )\n */\npublic function indexAction($foo)\n{\n    // Use the foo var\n}\n```\n\nYou can also customize the var name and the default value in case the var is not\nsent on the query string.\n\nFor a `GET` request like:\n\n```\nGET /my-page HTTP/1.1\n```\n\nAnd this annotation\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Get;\n\n/**\n * Simple controller method\n *\n * @Get(\n *     path = \"foo\",\n *     name = \"varName\",\n *     default = 'bar',\n * )\n */\npublic function indexAction($varName)\n{\n    // This would print 'bar'\n    echo $varName;\n}\n```\n\n## @Post\n\nThe Post annotation allows you to get any parameter from the post request body.\n\nFor a `POST` request like:\n\n```\nPOST /my-page HTTP/1.1\nfoo=bar\n```\n\nYou can can simply get the `foo` var using the `POST` annotation\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Post;\n\n/**\n * Simple controller method\n *\n * @Post(\n *     path = \"foo\"\n * )\n */\npublic function indexAction($foo)\n{\n    // Use the foo var\n}\n```\n\nYou can also customize the var name and the default value in case the var is not\nsent on the query string.\n\nFor a `POST` request like:\n\n```\nPOST /my-page HTTP/1.1\n```\n\nAnd this annotation\n\n``` php\n\u003c?php\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Post;\n\n/**\n * Simple controller method\n *\n * @Post(\n *     path = \"foo\",\n *     name = \"varName\",\n *     default = 'bar',\n * )\n */\npublic function indexAction($varName)\n{\n    // This would print 'bar'\n    echo $varName;\n}\n```\n\n# Custom annotations\n\nUsing this bundle you can now create, in a very easy way, your own controller\nannotation.\n\n## Annotation\n\nThe annotation object. You need to define the fields your custom annotation\nwill contain. Must extends `Mmoreram\\ControllerExtraBundle\\Annotation\\Annotation`\nabstract class.\n\n``` php\n\u003c?php\n\nnamespace My\\Bundle\\Annotation;\n\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Annotation;\n\n/**\n * Entity annotation driver\n *\n * @Annotation\n * @Target({\"METHOD\"})\n */\nfinal class MyCustomAnnotation extends Annotation\n{\n    /**\n     * @var string\n     *\n     * Dummy field\n     */\n    public $field;\n    \n    /**\n     * Get Dummy field\n     *\n     * @return string Dummy field\n     */\n    public function getField()\n    {\n        return $this-\u003efield;\n    }\n}\n```\n\n## Resolver\n\nOnce you have defined your own annotation, you have to resolve how this\nannotation works in a controller. You can manage this using a Resolver. Must\nextend `Mmoreram\\ControllerExtraBundle\\Resolver\\AnnotationResolver;` abstract \nclass.\n\n``` php\n\u003c?php\n\nnamespace My\\Bundle\\Resolver;\n\nuse Symfony\\Component\\HttpFoundation\\Request;\n\nuse Mmoreram\\ControllerExtraBundle\\Resolver\\AnnotationResolver;\nuse Mmoreram\\ControllerExtraBundle\\Annotation\\Annotation;\n\n/**\n * MyCustomAnnotation Resolver\n */\nclass MyCustomAnnotationResolver extends AnnotationResolver\n{\n    /**\n     * Specific annotation evaluation.\n     *\n     * This method must be implemented in every single EventListener\n     * with specific logic\n     *\n     * All method code will executed only if specific active flag is true\n     *\n     * @param Request          $request\n     * @param Annotation       $annotation\n     * @param ReflectionMethod $method\n     */\n    public function evaluateAnnotation(\n        Request $request,\n        Annotation $annotation,\n        ReflectionMethod $method\n    )\n    {\n        /**\n         * You can now manage your annotation.\n         * You can access to its fields using public methods.\n         * \n         * Annotation fields can be public and can be acceded directly,\n         * but is better for testing to use getters; they can be mocked.\n         */\n        $field = $annotation-\u003egetField();\n        \n        /**\n         * You can also access to existing method parameters.\n         * \n         * Available parameters are:\n         * \n         * # ParamConverter parameters ( See `resolver_priority` config value )\n         * # All method defined parameters, included Request object if is set.\n         */\n        $entity = $request-\u003eattributes-\u003eget('entity');\n        \n        /**\n         * And you can now place new elements in the controller action.\n         * In this example we are creating new method parameter\n         * called $myNewField with some value\n         */\n        $request-\u003eattributes-\u003eset(\n            'myNewField',\n            new $field()\n        );\n        \n        return $this;\n    }\n\n}\n```\n\nThis class will be defined as a service, so this method is computed just\nbefore executing current controller. You can also subscribe to some kernel\nevents and do whatever you need to do ( You can check\n`Mmoreram\\ControllerExtraBundle\\Resolver\\LogAnnotationResolver` for some\nexamples.\n\n## Definition\n\nOnce Resolver is done, we need to define our service as an Annotation\nResolver. We will use a custom `tag`.\n\n``` yml\nparameters:\n    #\n    # Resolvers\n    #\n    my.bundle.resolver.my_custom_annotation_resolver.class: My\\Bundle\\Resolver\\MyCustomAnnotationResolver\n\nservices:\n    #\n    # Resolvers\n    #\n    my.bundle.resolver.my_custom_annotation_resolver:\n        class: %my.bundle.resolver.my_custom_annotation_resolver.class%\n        tags:\n            - { name: controller_extra.annotation }\n```\n\n## Registration\n\nWe need to register our annotation inside our application. We can just do it in\nthe `boot()` method of `bundle.php` file.\n\n``` php\n\u003c?php\n\nnamespace My\\Bundle;\n\nuse Symfony\\Component\\HttpKernel\\Bundle\\Bundle;\nuse Doctrine\\Common\\Annotations\\AnnotationRegistry;\n\n/**\n * MyBundle\n */\nclass ControllerExtraBundle extends Bundle\n{\n\n    /**\n     * Boots the Bundle.\n     */\n    public function boot()\n    {\n        $kernel = $this-\u003econtainer-\u003eget('kernel');\n\n        AnnotationRegistry::registerFile($kernel\n            -\u003elocateResource(\"@MyBundle/Annotation/MyCustomAnnotation.php\")\n        );\n    }\n}\n```\n\n*Et voilà!*  We can now use our custom Annotation in our project controllers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmoreram%2FControllerExtraBundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmoreram%2FControllerExtraBundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmoreram%2FControllerExtraBundle/lists"}