{"id":14987423,"url":"https://github.com/tattersoftware/codeigniter4-handlers","last_synced_at":"2025-04-12T00:15:06.650Z","repository":{"id":35052836,"uuid":"200236624","full_name":"tattersoftware/codeigniter4-handlers","owner":"tattersoftware","description":"Handler discovery and management, for CodeIgniter 4","archived":false,"fork":false,"pushed_at":"2024-01-18T01:13:54.000Z","size":191,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-04-12T00:14:59.240Z","etag":null,"topics":["codeigniter","codeigniter4","factories","handlers","metaprogramming","php"],"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/tattersoftware.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-02T13:09:36.000Z","updated_at":"2023-09-08T17:56:30.000Z","dependencies_parsed_at":"2024-06-21T19:07:39.017Z","dependency_job_id":"9dd248bd-d356-4670-985d-4f20314406fa","html_url":"https://github.com/tattersoftware/codeigniter4-handlers","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-handlers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-handlers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-handlers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-handlers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tattersoftware","download_url":"https://codeload.github.com/tattersoftware/codeigniter4-handlers/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248497818,"owners_count":21113984,"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":["codeigniter","codeigniter4","factories","handlers","metaprogramming","php"],"created_at":"2024-09-24T14:14:35.579Z","updated_at":"2025-04-12T00:15:06.614Z","avatar_url":"https://github.com/tattersoftware.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tatter\\Handlers\nHandler discovery and management, for CodeIgniter 4\n\n[![](https://github.com/tattersoftware/codeigniter4-handlers/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-handlers/actions/workflows/test.yml)\n[![](https://github.com/tattersoftware/codeigniter4-handlers/workflows/PHPStan/badge.svg)](https://github.com/tattersoftware/codeigniter4-handlers/actions/workflows/analyze.yml)\n[![](https://github.com/tattersoftware/codeigniter4-handlers/workflows/Deptrac/badge.svg)](https://github.com/tattersoftware/codeigniter4-handlers/actions/workflows/inspect.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tattersoftware/codeigniter4-handlers/badge.svg?branch=develop)](https://coveralls.io/github/tattersoftware/codeigniter4-handlers?branch=develop)\n\n## Quick Start\n\n1. Install with Composer: `\u003e composer require tatter/handlers`\n2. Create a Factory to identify your handlers\n2. Discover classes from any namespace: `$widgets = WidgetFactory::findAll();`\n\n## Features\n\n**Handlers** allows developers to define and discover classes of predetermined types\nacross all namespaces; it is essentially a database-free \"model\" for classes.\n\n## Installation\n\nInstall easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities\nand always be up-to-date:\n```bash\ncomposer require tatter/handlers\n```\n\nOr, install manually by downloading the source files and adding the directory to\n**app/Config/Autoload.php**.\n\n## Configuration (optional)\n\nThe library's default behavior can be altered by extending its config file. Copy\n**examples/Handlers.php** to **app/Config/** and follow the instructions\nin the comments. If no config file is found in **app/Config** the library will use its own.\n\n## Usage\n\n**Handlers** uses relative paths to discover files that contain handler classes. Create a\nnew folder in your project or module with an appropriate name for your implementation,\ne.g. **app/Widgets/** or **src/Reports**.\n\n### Compatibility\n\nIn order for them be discovered as handlers your classes need to have a consistent class or\ninterface type and supply a unique ID via the class constant `HANDLER_ID`.\n\n**Handlers** will resolve class extensions by using this handler ID, so if you want your\napp to \"replace\" a handler from another namespace then simply extend the original class and\nleave the `HANDLER_ID` constant the same.\n\n### Factories\n\nOnce your handler classes are created you will need a Factory that provides the lookup path\nand expected class or interface to identify the handlers. Create the new class extending `BaseFactory`:\n```php\n\u003c?php\n\nnamespace App\\Factories;\n\nuse App\\Interfaces\\WidgetInterface;\nuse Tatter\\Handlers\\BaseFactory;\n\nclass WidgetFactory extends BaseFactory\n{\n    public const HANDLER_PATH = 'Widgets';\n    public const HANDLER_TYPE = WidgetInterface::class;\n}\n```\n\nYou can then use the `BaseFactory` methods to locate all handler classes or a specific\nhandler by its ID:\n```php\nuse App\\Factories\\WidgetFactory;\n\n// Iterate through all discovered handlers\nforeach (WidgetFactory::findAll() as $class)\n{\n    $widget = new $class($param1, $param2);\n    $widget-\u003edisplay();\n}\n\n// ... or get a single handler by specifying its ID\n$class = WidgetFactory::find('FancyHandler');\n(new $class)-\u003edisplay();\n```\n\n## Caching\n\n**Handlers** scans through all namespaces to discover relevant classes. This distributed\nfilesystem read can be costly in large projects, so **Handlers** will cache the results\nfor an amount of time set in the config file (default: one day). You can disable Caching\nusing the config file by setting `$cacheDuration` to `null`.\n\nOften it is a good idea to pre-cache handlers so the filesystem search does not happen on\nan actual page load. This library includes `FactoryFactory`, a \"Factory to discover other\nFactories\". If you would like your Factories to be discoverable by `FactoryFactory` and\nthus their handlers enabled for auto-caching then place your Factory classes in the\n**Factories** subfolder and provide them a `HANDLER_ID` constant like any other handler.\n\n### Commands\n\nTo assist with `FactoryFactory`'s discovery of your factories and their handlers this\nlibrary includes two commands that will pre-cache all handler classes and clear the cached\nvalues respectively:\n```bash\n# Discovers and caches all compatible factories and their handlers\nphp spark handlers:cache\n\n# Clears all cached factories and handlers\nphp spark handlers:clear\n```\n\nSet your cron job to run `spark handlers:cache` on some interval smaller than the Config\n`$cacheDuration` to ensure your handlers are always at hand.\n\n## Examples\n\nHere are some other libraries that implement their own Factory class with a set of handlers.\nBrowse their code to get an idea of how you might use **Handlers** for your own projects.\n\n* [Tatter\\Thumbnails](https://github.com/tattersoftware/codeigniter4-thumbnails): Modular thumbnail generation, for CodeIgniter 4\n* [Tatter\\Exports](https://github.com/tattersoftware/codeigniter4-exports): Modular file exports, for CodeIgniter 4\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-handlers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftattersoftware%2Fcodeigniter4-handlers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-handlers/lists"}