{"id":18750724,"url":"https://github.com/webiny/annotations","last_synced_at":"2026-03-12T21:32:25.727Z","repository":{"id":20224707,"uuid":"23496493","full_name":"webiny/Annotations","owner":"webiny","description":"[READ-ONLY]  This simple PHP component lets you read/parse annotations/phpdoc assigned to a `class`, `method` or a `property`. (master at Webiny/Framework)","archived":false,"fork":false,"pushed_at":"2017-11-26T21:24:11.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-26T18:06:09.532Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.webiny.com/","language":"PHP","has_issues":false,"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/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-30T17:05:16.000Z","updated_at":"2023-05-21T17:35:24.000Z","dependencies_parsed_at":"2022-07-25T07:02:04.071Z","dependency_job_id":null,"html_url":"https://github.com/webiny/Annotations","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FAnnotations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FAnnotations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FAnnotations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FAnnotations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/Annotations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647258,"owners_count":21139081,"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":[],"created_at":"2024-11-07T17:12:55.147Z","updated_at":"2026-03-12T21:32:25.683Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Annotations Component\n=====================\nThis simple component lets you read annotations assigned to a `class`, `method` or a `property`.\n\nInstall the component\n---------------------\nThe best way to install the component is using Composer.\n\n```bash\ncomposer require webiny/annotations\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/annotations).\n\n## Configuration and setup\nThe component configuration is minimal, you just need to define the bridge dependency.\nThe built-in bridge uses [Minime\\Annotations](https://github.com/marcioAlmada/annotations) library.\n\n```yaml\nAnnotations:\n    Bridge: \\Webiny\\Component\\Annotations\\Bridge\\Minime\\Annotations\n    # You don't need this part if you are using Composer autoload.\n    ClassLoader:\n        Minime\\Annotations: /var/www/Vendors/Minime/Annotations/src\n```\n\nOnce defined, you can start parsing the annotations. The best approach is to use the `AnnotationsTrait`.\nLet's say that this is the class that you wish to parse the annotations from.\n\n```php\n/**\n * This is a class description with some annotations.\n *\n * @prop SomeProperty that has a string value.\n * @author.name AuthorName\n * @author.email author@name.com\n * @author.website.url http://www.webiny.com\n * @author.website.desc My website\n *\n */\nclass TestClass\n{\n    /**\n     * @var SomeVarAnnotation\n     * @public\n     */\n    var $someVar;\n\n    /**\n     * @access.role ADMIN\n     * @access.level 3\n     * @name SomeName\n     */\n    private $_anotherVar;\n\n    /**\n     * @post @get\n     * @cache.ttl 10\n     * @cache.store true @cache.key cacheKey\n     * @accept [\"json\", \"xml\"]\n     */\n    function someMethod()\n    {\n\n    }\n}\n```\n\nIn your class, where you wish to do the actually parsing, just use the `AnnotationsTrait`.\nTrait methods return an instance of `ConfigObject` giving you the option to use the `get` method and to chain the namespaces.\nAnnotation namespaces are fully supported, giving you the possibility to organize the annotations in much cleaner way.\n\n```php\nclass MyClass\n{\n    use AnnotationsTrait;\n\n    function getClassAnnotations()\n    {\n        $classAnnotations = $this-\u003eannotationsFromClass('TestClass');\n        $classAnnotations-\u003eprop; // SomeProperty that has a string value.\n        $classAnnotations-\u003eauthor-\u003ewebsite-\u003eurl; // http://www.webiny.com\n    }\n\n    function getPropertyAnnotations()\n    {\n        $someVarPropertyAnnotations = $this-\u003eannotationsFromProperty('TestClass', 'someVar');\n        $someVarPropertyAnnotations-\u003epublic; // returns \"true\"\n    }\n\n    function getMethodAnnotations()\n    {\n        $methodAnnotations = $this-\u003eannotationsFromMethod('TestClass', 'someMethod');\n        $methodAnnotations-\u003ecache-\u003ekey; // cacheKey\n        $methodAnnotations-\u003eaccept; // [0 =\u003e \"json\", 1 =\u003e \"xml\"]\n    }\n}\n```\n\nResources\n---------\n\nTo run unit tests, you need to use the following command:\n\n    $ cd path/to/Webiny/Component/Annotations/\n    $ composer.phar install\n    $ phpunit","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fannotations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fannotations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fannotations/lists"}