{"id":14955168,"url":"https://github.com/simplemediacode/hooks","last_synced_at":"2025-04-01T14:32:35.483Z","repository":{"id":55453132,"uuid":"325131360","full_name":"simplemediacode/hooks","owner":"simplemediacode","description":"Decoupled @WordPress Hooks (filters and actions)","archived":false,"fork":false,"pushed_at":"2025-03-31T17:11:38.000Z","size":49,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T17:46:20.032Z","etag":null,"topics":["composer","composer-package","hook","hook-functions","hooking","hooking-library","hooks","hooks-api","php","php7","php8","wordpress","wordpress-development","wordpress-php-library"],"latest_commit_sha":null,"homepage":"https://republa.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplemediacode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-28T22:36:02.000Z","updated_at":"2025-03-31T17:11:42.000Z","dependencies_parsed_at":"2024-11-02T15:25:27.009Z","dependency_job_id":"78529e2b-b24d-467a-aefd-7d69dc6692e0","html_url":"https://github.com/simplemediacode/hooks","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"bfb0651c5066fcc9e918a4848ed9ca06535cee35"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplemediacode%2Fhooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplemediacode%2Fhooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplemediacode%2Fhooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplemediacode%2Fhooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplemediacode","download_url":"https://codeload.github.com/simplemediacode/hooks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246512165,"owners_count":20789647,"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":["composer","composer-package","hook","hook-functions","hooking","hooking-library","hooks","hooks-api","php","php7","php8","wordpress","wordpress-development","wordpress-php-library"],"created_at":"2024-09-24T13:10:36.516Z","updated_at":"2025-04-01T14:32:35.465Z","avatar_url":"https://github.com/simplemediacode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Modern PHP Hooks System\r\n\r\nA lightweight, dependency-free implementation of an action and filter hook system inspired by WordPress hooks but designed for modern PHP applications.\r\n\r\n## Features\r\n\r\n- **Modern PHP Support**: Fully typed, supports PHP 8.0+\r\n- **Dependency Injection Ready**: Use the `HooksInterface` in your classes\r\n- **Static Facade**: Convenient static methods for quick integration\r\n- **No Dependencies**: Lightweight implementation with zero dependencies\r\n- **WordPress Inspired**: Familiar API if you're coming from WordPress\r\n\r\n## Installation\r\n\r\nVia **composer**:\r\n\r\n```bash\r\ncomposer require simplemediacode/hooks\r\n```\r\n\r\n## Usage\r\n\r\n### Using the Static Facade\r\n\r\n```php\r\nuse Simplemediacode\\Hooks\\Hooks;\r\n\r\n// Add a filter\r\nHooks::addFilter('content', function($content) {\r\n    return strtoupper($content);\r\n});\r\n\r\n// Apply a filter\r\n$content = Hooks::applyFilters('content', 'Hello World'); // Returns \"HELLO WORLD\"\r\n\r\n// Add an action\r\nHooks::addAction('save_post', function($postId) {\r\n    // Do something when a post is saved\r\n    echo \"Post {$postId} was saved!\";\r\n});\r\n\r\n// Execute an action\r\nHooks::doAction('save_post', 123);\r\n```\r\n\r\n### Using Dependency Injection\r\n\r\n```php\r\nuse Simplemediacode\\Hooks\\HooksInterface;\r\n\r\nclass MyClass\r\n{\r\n    private ?HooksInterface $hooks;\r\n\r\n    public function __construct(\r\n        ?HooksInterface $hooks = null\r\n    ) {\r\n        $this-\u003ehooks = $hooks;\r\n    }\r\n    \r\n    public function processContent(string $content): string\r\n    {\r\n        // If hooks are available, filter the content\r\n        if ($this-\u003ehooks) {\r\n            $content = $this-\u003ehooks-\u003eexecuteHook('content', $content);\r\n        }\r\n        \r\n        return $content;\r\n    }\r\n}\r\n```\r\n\r\n### Extending with Custom Implementations\r\n\r\nYou can implement your own version of `HooksInterface` to provide custom hook functionality:\r\n\r\n```php\r\n$customHooks = new MyCustomHooksImplementation();\r\nHooks::setInstance($customHooks);\r\n```\r\n\r\n## Migration from WP_Hook\r\n\r\nThis package is a complete rewrite of the original WordPress hook system. Key differences:\r\n\r\n- Renamed `WP_Hook` to `Hook`\r\n- Introduced proper interfaces for better type safety\r\n- Added dependency injection support\r\n- Replaced global variables with proper class properties\r\n- Improved naming conventions and method signatures\r\n\r\n## Changelog\r\n\r\nRead at [CHANGELOG.md](./CHANGELOG.md).\r\n\r\n## License\r\nThis library is released under the GPL-2.0 license. See the complete license in the bundled [LICENSE](./LICENSE) file.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplemediacode%2Fhooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplemediacode%2Fhooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplemediacode%2Fhooks/lists"}