{"id":16193184,"url":"https://github.com/koriym/koriym.attributes","last_synced_at":"2025-04-04T11:16:13.210Z","repository":{"id":37655302,"uuid":"321969007","full_name":"koriym/Koriym.Attributes","owner":"koriym","description":"A reader can read both doctrine/annotations and PHP8 attributes with a doctrine annotation interface.","archived":false,"fork":false,"pushed_at":"2025-02-23T15:04:01.000Z","size":156,"stargazers_count":41,"open_issues_count":1,"forks_count":7,"subscribers_count":5,"default_branch":"1.x","last_synced_at":"2025-03-28T10:11:19.236Z","etag":null,"topics":["annotatios","attributes","php"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/koriym/attributes","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/koriym.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-16T12:01:11.000Z","updated_at":"2025-02-23T15:01:54.000Z","dependencies_parsed_at":"2024-01-02T03:22:28.062Z","dependency_job_id":"64677ab1-40b7-4f71-8c7f-e0aaab1183d9","html_url":"https://github.com/koriym/Koriym.Attributes","commit_stats":{"total_commits":102,"total_committers":6,"mean_commits":17.0,"dds":"0.12745098039215685","last_synced_commit":"a7ccfea76dd319be5bd065e847f79cb39ff949a9"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koriym%2FKoriym.Attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koriym","download_url":"https://codeload.github.com/koriym/Koriym.Attributes/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166169,"owners_count":20894654,"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":["annotatios","attributes","php"],"created_at":"2024-10-10T08:14:17.806Z","updated_at":"2025-04-04T11:16:13.188Z","avatar_url":"https://github.com/koriym.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Koriym.Attributes\n\n[![codecov](https://codecov.io/gh/koriym/Koriym.Attributes/branch/master/graph/badge.svg?token=O1MBvJrlP6)](https://codecov.io/gh/koriym/Koriym.Attributes)\n[![Type Coverage](https://shepherd.dev/github/koriym/Koriym.Attributes/coverage.svg)](https://shepherd.dev/github/koriym/Koriym.Attributes)\n![Continuous Integration](https://github.com/koriym/Koriym.Attributes/workflows/Continuous%20Integration/badge.svg)\n![Static Analysis](https://github.com/koriym/Koriym.Attributes/workflows/Static%20Analysis/badge.svg)\n![Coding Standards](https://github.com/koriym/Koriym.Attributes/workflows/Coding%20Standards/badge.svg)\n\nA `koriym/attributes` dual reader implements doctrine/annotation [Reader](https://github.com/doctrine/annotations/blob/master/lib/Doctrine/Common/Annotations/Reader.php) interface\nin order to read both doctrine/annotation and PHP 8 attributes.\n\nDoctrine annotations are different by design than PHP core one. \nNot all attributes can be read by this reader (ex. parameters), and not all doctrine/annotations can be read by this reader either. (ex. nested annotations)\n\nHowever, This reader help you to code forward compatible that supports both PHP 7.x annotations and 8.x attributes in certain senario.\n\n## Installation\n\n    composer require koriym/attributes\n\n## Usage\n\nCreate the reader instance.\n\n```php\nuse Doctrine\\Common\\Annotations\\AnnotationReader;\nuse Doctrine\\Common\\Annotations\\Reader;\nuse Koriym\\Attributes\\DualReader;\nuse Koriym\\Attributes\\AttributeReader;\n\n$reader = new DualReader(\n    new AnnotationReader(),\n    new AttributeReader()\n);\nassert($reader instanceof Reader);\n```\n\nThe reader can read both annotations and attributes.\n\n## Compatible Annotation\n\nExisting doctrine annotations can be changed into annotations that work for both doctrine annotation and PHP8 attributes.\n\nAdd `#[Attribute]` attribute.\n\n```diff\nuse Attribute;\n\n/** @Annotation */\n+#[Attribute]\nfinal class Foo\n{\n}\n```\n\nThen add constructor when annotation has properties.\nFollowing example works with both PHP8 attribute and `doctrine/annotations`.\n\n```diff\nuse Attribute;\n+use Doctrine\\Common\\Annotations\\NamedArgumentConstructor;\n\n/**\n * @Annotation \n * @Target(\"METHOD\")\n+* @NamedArgumentConstructor\n */\n+#[Attribute(Attribute::TARGET_METHOD)]\nfinal class Foo\n{\n    public string $bar;\n    public int $baz;\n+    public function __construct(string $bar = '', int $baz = 0)\n+    {\n+        $this-\u003ebar = $bar;\n+        $this-\u003ebaz = $baz;\n+    }\n}\n```\n\nSee more about annotation compatible attribute at [Constructors with Named Parameters](https://github.com/doctrine/annotations/blob/1.11.x/docs/en/custom.rst#optional-constructors-with-named-parameters)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoriym%2Fkoriym.attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoriym%2Fkoriym.attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoriym%2Fkoriym.attributes/lists"}