{"id":16314898,"url":"https://github.com/frostealth/php-presenter","last_synced_at":"2025-04-28T11:08:21.054Z","repository":{"id":62507629,"uuid":"47888431","full_name":"frostealth/php-presenter","owner":"frostealth","description":"Simple View Presenters","archived":false,"fork":false,"pushed_at":"2015-12-14T11:48:03.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-25T07:22:30.812Z","etag":null,"topics":["php","presenter","view"],"latest_commit_sha":null,"homepage":null,"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/frostealth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-12T17:55:52.000Z","updated_at":"2016-03-02T08:44:52.000Z","dependencies_parsed_at":"2022-11-02T12:32:01.495Z","dependency_job_id":null,"html_url":"https://github.com/frostealth/php-presenter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostealth%2Fphp-presenter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostealth%2Fphp-presenter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostealth%2Fphp-presenter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostealth%2Fphp-presenter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frostealth","download_url":"https://codeload.github.com/frostealth/php-presenter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239161841,"owners_count":19592336,"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":["php","presenter","view"],"created_at":"2024-10-10T21:55:33.332Z","updated_at":"2025-02-16T16:42:22.158Z","avatar_url":"https://github.com/frostealth.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PHP View Presenters\n=============\n\nSo you have those scenarios where a bit of logic needs to be performed before some data (likely from your entity) \nis displayed from the view.\n\n* Should that logic be hard-coded into the view? **No.**\n* Should we instead store the logic in the model? **No again!**\n\nInstead, leverage view presenters. That's what they're for! This package provides one such implementation.\n\n## Installation\n\nRun the [Composer](http://getcomposer.org/download/) command to install the latest stable version:\n\n```bash\ncomposer require frostealth/php-presenter @stable\n```\n\n## Usage\n\nThe first step is to store your presenters somewhere - anywhere. \nThese will be simple objects that do nothing more than format data, as required.\n\nHere's an example of a presenter.\n\n```php\nnamespace app\\presenters;\n\nuse frostealth\\presenter\\Presenter;\n\n/**\n * Class ConcreteEntityPresenter\n *\n * @property-read string $fullName\n * @property-read string $birthDate\n */\nclass ConcreteModelPresenter extends Presenter\n{\n    /**\n     * @return string\n     */\n    public function getFullName()\n    {\n        return implode(' ', [$this-\u003efirstName, $this-\u003elastName]);\n    }\n    \n    /**\n     * @return string\n     */\n    public function getBirthDate()\n    {\n        return date('y.M.d', $this-\u003eentity-\u003ebirthDate);\n    }\n}\n```\n\nHere's an example of an presentable model.\n\n```php\nnamespace app\\models;\n\nuse app\\presenters\\ConcreteModelPresenter;\nuse frostealth\\presenter\\interfaces\\PresentableInterface;\n\nclass ConcreteModel implements PresentableInterface\n{\n    /** @var string */\n    public $firstName;\n    \n    /** @var string */\n    public $lastName;\n    \n    /** @var string */\n    public $birthDate;\n    \n    /** @var ConcreteModelPresenter */\n    protected $presenter;\n\n    /**\n     * @return ConcreteModelPresenter\n     */\n    public function presenter()\n    {\n        if ($this-\u003epresenter === null) {\n            $this-\u003epresenter = new ConcreteModelPresenter($this);\n        }\n    \n        return $this-\u003epresenter;\n    }\n}\n```\n\nNow, within your view, you can do:\n\n```php\n\u003cdl\u003e\n    \u003cdt\u003eName\u003c/dt\u003e\n    \u003cdd\u003e\u003c?= $model-\u003epresenter()-\u003efullName ?\u003e\u003c/dd\u003e\n    \n    \u003cdt\u003eBirth Date\u003c/dt\u003e\n    \u003cdd\u003e\u003c?= $model-\u003epresenter()-\u003ebirthDate ?\u003e\u003c/dd\u003e\n\u003c/dl\u003e\n```\n\n## License\n\nThe MIT License (MIT).\nSee [LICENSE.md](https://github.com/frostealth/php-presenter/blob/master/LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostealth%2Fphp-presenter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrostealth%2Fphp-presenter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostealth%2Fphp-presenter/lists"}