{"id":26319655,"url":"https://github.com/nayleen/attribute","last_synced_at":"2025-03-15T15:20:13.965Z","repository":{"id":51093548,"uuid":"332902805","full_name":"nayleen/attribute","owner":"nayleen","description":"Provides accessors to single-value PHP Attributes.","archived":false,"fork":false,"pushed_at":"2023-12-26T17:14:23.000Z","size":40,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T21:55:26.050Z","etag":null,"topics":["annotations","php","php-annotations","php-attibutes","php-library","php8","php8-features"],"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/nayleen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-01-25T22:32:31.000Z","updated_at":"2023-07-16T20:39:14.000Z","dependencies_parsed_at":"2023-11-10T23:40:38.178Z","dependency_job_id":null,"html_url":"https://github.com/nayleen/attribute","commit_stats":{"total_commits":45,"total_committers":5,"mean_commits":9.0,"dds":"0.24444444444444446","last_synced_commit":"88b7a5292016ec60ac01b7fa8d5a7be280fd8182"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nayleen%2Fattribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nayleen%2Fattribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nayleen%2Fattribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nayleen%2Fattribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nayleen","download_url":"https://codeload.github.com/nayleen/attribute/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243746566,"owners_count":20341257,"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":["annotations","php","php-annotations","php-attibutes","php-library","php8","php8-features"],"created_at":"2025-03-15T15:20:13.360Z","updated_at":"2025-03-15T15:20:13.955Z","avatar_url":"https://github.com/nayleen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nayleen-attribute [![Latest Stable Version](https://poser.pugx.org/nayleen/attribute/v)](//packagist.org/packages/nayleen/attribute) [![License](https://poser.pugx.org/nayleen/attribute/license)](//packagist.org/packages/nayleen/attribute)\nProvides accessors to single-value [PHP Attributes](https://www.php.net/manual/en/language.attributes.overview.php).\n\n## Installation\n`composer require nayleen/attribute`\n\n## Flavors\nFor ease of use the library provides two identical ways of accessing attribute values:\n\n```php\nnamespace Nayleen\\Attribute;\n\n// function\nget(string|object $class, string $attribute, mixed $default = null): mixed;\n\n// public static method\nAttributeValueGetter::get(string|object $class, string $attribute, mixed $default = null): mixed;\n```\n\n## Usage\nWorks on both instances and class names:\n\n```php\nuse function Nayleen\\Attribute\\get;\n\n#[Attribute]\nclass SomeAttribute\n{\n    public function __construct(private string $value) {}\n}\n\n#[SomeAttribute('foo')]\nclass MyClass {}\n\n$value = get(MyClass::class, 'SomeAttribute'); // \"foo\"\n$value = get(new MyClass(), 'SomeAttribute'); // \"foo\"\n```\n\n---\n\nThrows a `MissingAttributeException` if the attribute is not set:\n\n```php\nget(MyClass::class, 'UnknownAttribute');\n// uncaught Nayleen\\Attribute\\Exception\\MissingAttributeException\n```\n\nUnless you provide a default value as a third argument:\n\n```php\nget(MyClass::class, 'UnknownAttribute', 'foo'); // \"foo\"\nget(MyClass::class, 'UnknownAttribute', 'bar'); // \"bar\"\nget(MyClass::class, 'UnknownAttribute', 'baz'); // \"baz\"\n```\n\nFor heavy lifting or lazy evaluation, a default value can be a `callable`:\n\n```php\nget(MyClass::class, 'UnknownAttribute', fn () =\u003e 'bar'); // \"bar\"\n```\n\n---\n\nIf the attribute is repeatable, it'll return an array of that attribute's values:\n\n```php\nuse function Nayleen\\Attribute\\get;\n\n#[Attribute(Attribute::IS_REPEATABLE)]\nfinal class RepeatableAttribute\n{\n    public function __construct(private string $value) {}\n}\n\n#[RepeatableAttribute('foo')]\n#[RepeatableAttribute('bar')]\nclass MyClass {}\n\n$value = get(MyClass::class, 'RepeatableAttribute'); // [\"foo\", \"bar\"]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnayleen%2Fattribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnayleen%2Fattribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnayleen%2Fattribute/lists"}