{"id":20678873,"url":"https://github.com/phpgt/propfunc","last_synced_at":"2025-07-16T21:33:12.514Z","repository":{"id":57040445,"uuid":"339784556","full_name":"phpgt/PropFunc","owner":"phpgt","description":"Property accessor and mutator functions.","archived":false,"fork":false,"pushed_at":"2023-03-10T05:08:40.000Z","size":64,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-07T12:08:36.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["phpgt"]}},"created_at":"2021-02-17T16:25:20.000Z","updated_at":"2024-06-08T10:39:44.000Z","dependencies_parsed_at":"2025-01-17T15:15:39.447Z","dependency_job_id":"fe814cd8-0140-4c2b-a301-c29874f3629d","html_url":"https://github.com/phpgt/PropFunc","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"c941c5aad92210030f8d0c6c5e6978090d4e5375"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FPropFunc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FPropFunc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FPropFunc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FPropFunc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpgt","download_url":"https://codeload.github.com/phpgt/PropFunc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242911344,"owners_count":20205478,"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-16T21:22:53.002Z","updated_at":"2025-03-10T19:26:50.041Z","avatar_url":"https://github.com/phpgt.png","language":"PHP","funding_links":["https://github.com/sponsors/phpgt"],"categories":[],"sub_categories":[],"readme":"# Property accessor and mutator functions.\n\nProperty accessors and mutators are commonly referred to as \"getter\" and \"setter\" functions. This library uses [PHP's Magic Methods][magic-methods] to easily hook up getter and setter functions that are exposed externally as normal properties, via the `MagicProp` trait.\n\nWhy? This kind of functionality can certainly be seen as a hack, but sometimes hacks are necessary. Specifically PHP.Gt is implementing [the DOM standard in PHP][dom] which requires certain properties to have \"live\" or \"readonly\" functionality, which is only possible using magic __get and __set functions. This library simply holds the reusable behaviour for other repositories that require it.\n\n***\n\n\u003ca href=\"https://github.com/PhpGt/PropFunc/actions\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/propfunc-build.svg\" alt=\"Build status\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://scrutinizer-ci.com/g/PhpGt/PropFunc\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/propfunc-quality.svg\" alt=\"Code quality\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://scrutinizer-ci.com/g/PhpGt/PropFunc\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/propfunc-coverage.svg\" alt=\"Code coverage\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/PhpGt/PropFunc\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/propfunc-version.svg\" alt=\"Current version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"http://www.php.gt/propfunc\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/propfunc-docs.svg\" alt=\"PHP.Gt/PropFunc documentation\" /\u003e\n\u003c/a\u003e\n\nExample usage: Read-only properties that are calculated upon access\n-------------------------------------------------------------------\n\nSee the class `Day` below, which represents a day in time:\n\n```php\nuse Gt\\PropFunc\\MagicProp;\n\n/**\n * @property-read bool $future True if the day is in the future\n * @property-read int $daysApart Days between now and this day\n */\nclass Day {\n\tuse MagicProp;\n\t\n\tpublic function __construct(\n\t\tprivate DateTimeInterface $dateTime\n\t) {}\n\t\n// Expose the \"dateTime\" private property with read-only access:\n\tprivate function __prop_get_dateTime():DateTimeInterface {\n\t\treturn $this-\u003edateTime;\n\t}\n\t\n// Expose the \"future\" calculated property with read-only access:\n\tprivate function __prop_get_future():bool {\n\t\t$now = new DateTime();\n\t\treturn $now \u003c $this-\u003edateTime;\n\t}\n\t\n// Expose the \"daysApart\" calculated property with read-only access:\n\tprivate function __prop_get_daysApart():int {\n\t\t$now = new DateTime();\n\t\t$diff = $now-\u003ediff($this-\u003edateTime);\n\t\treturn $diff-\u003edays;\n\t}\n}\n```\n\nSee the code below which uses the `Day` class. It can access the properties, but not mutate them.\n\n```php\n$day = new Day($dateTime);\necho \"Day is $day-\u003ediff days in the \";\necho $day-\u003efuture ? \"future\" : \"past\";\necho PHP_EOL;\n$day-\u003ediff = 10;\necho \"Exception thrown on line above!\";\n```\n\nUsages\n------\n\n+ Read only properties - as with the above example, properties can be made read-only. This feature is [coming to the PHP language][write-once-property-rfc], but without the ability to define the accessor logic.\n+ Live properties - if a property's value is required to update depending on certain conditions, a getter function is required.\n+ Property validation - if a property's value can't simply be validated by its type alone, the setter function can be used to ensure the value meets validation criteria.\n\n[magic-methods]: https://www.php.net/manual/en/language.oop5.magic.php\n[dom]: https://www.php.gt/dom\n[write-once-property-rfc]: https://wiki.php.net/rfc/write_once_properties\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fpropfunc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpgt%2Fpropfunc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fpropfunc/lists"}