{"id":21989209,"url":"https://github.com/micropackage/dochooks","last_synced_at":"2025-10-17T01:33:28.676Z","repository":{"id":43061348,"uuid":"232264607","full_name":"micropackage/dochooks","owner":"micropackage","description":"WordPress hooks in method comments. Annotated hooks.","archived":false,"fork":false,"pushed_at":"2023-06-23T08:52:49.000Z","size":59,"stargazers_count":37,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-06-22T06:06:35.836Z","etag":null,"topics":["annotations","bracketspace","composer-library","micropackage","wordpress"],"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/micropackage.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-01-07T07:08:30.000Z","updated_at":"2025-02-05T19:47:13.000Z","dependencies_parsed_at":"2024-06-19T00:00:02.223Z","dependency_job_id":"262bc5ab-c15f-4cc4-9a94-d54102535708","html_url":"https://github.com/micropackage/dochooks","commit_stats":{"total_commits":35,"total_committers":4,"mean_commits":8.75,"dds":0.4285714285714286,"last_synced_commit":"abb8fc11f7c9d7b3270d87279913f7a2d829f695"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/micropackage/dochooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micropackage%2Fdochooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micropackage%2Fdochooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micropackage%2Fdochooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micropackage%2Fdochooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micropackage","download_url":"https://codeload.github.com/micropackage/dochooks/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micropackage%2Fdochooks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261244053,"owners_count":23129642,"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","bracketspace","composer-library","micropackage","wordpress"],"created_at":"2024-11-29T19:28:21.815Z","updated_at":"2025-10-17T01:33:28.614Z","avatar_url":"https://github.com/micropackage.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DocHooks\n\n[![BracketSpace Micropackage](https://img.shields.io/badge/BracketSpace-Micropackage-brightgreen)](https://bracketspace.com)\n[![Latest Stable Version](https://poser.pugx.org/micropackage/dochooks/v/stable)](https://packagist.org/packages/micropackage/dochooks)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/micropackage/dochooks.svg)](https://packagist.org/packages/micropackage/dochooks)\n[![Total Downloads](https://poser.pugx.org/micropackage/dochooks/downloads)](https://packagist.org/packages/micropackage/dochooks)\n[![License](https://poser.pugx.org/micropackage/dochooks/license)](https://packagist.org/packages/micropackage/dochooks)\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://bracketspace.com/extras/micropackage/micropackage-small.png\" alt=\"Micropackage logo\"/\u003e\n\u003c/p\u003e\n\n## 🧬 About DocHooks\n\nThe Laravel or Symfony projects are using method annotations for various things. This helps to have the project organized without too much code. WordPress has no implementation of such concept and this package is a remedy.\n\nDocHooks package allows you to do:\n\n```php\nclass Example extends HookAnnotations {\n\n\t/**\n\t * @action test\n\t */\n\tpublic function test_action() {}\n\n\t/**\n\t * @filter test 5\n\t */\n\tpublic function test_filter( $val, $arg ) {\n\t\treturn $val;\n\t}\n\n\t/**\n\t * @shortcode test\n\t */\n\tpublic function test_shortcode( $atts, $content ) {\n\t\treturn 'This is test';\n\t}\n\n}\n\n$example = new Example();\n$example-\u003eadd_hooks();\n```\n\nInstead of old:\n\n```php\n$example = new Example();\n\nadd_action( 'test', [ $example, 'test_action' ] );\nadd_filter( 'test', [ $example, 'test_filter' ], 5, 2 );\nadd_shortcode( 'test', [ $example, 'test_shortcode' ] );\n```\n\n## 💾 Installation\n\n``` bash\ncomposer require micropackage/dochooks\n```\n\n## 🕹 Usage\n\n### Annotations\n\n```\n@action \u003chook_name*\u003e \u003cpriority\u003e\n@filter \u003chook_name*\u003e \u003cpriority\u003e\n@shortcode \u003cshortcode_name*\u003e\n```\n\nThe hook and shortcode name is required while default priority is `10`.\n\nYou don't provide the argument count, the class will figure it out. Just use the callback params you want.\n\n### Test if DocHooks are working\n\nWhen OPCache has the `save_comments` and `load_comments` disabled, this package won't work, because the comments are stripped down. [See the fallback solution](#fallback).\n\n```php\nuse Micropackage\\DocHooks\\Helper;\n\n(bool) Helper::is_enabled();\n```\n\n### Using within the class\n\nYou can extend the HookAnnotations class:\n\n```php\nuse Micropackage\\DocHooks\\HookAnnotations;\n\nclass Example extends HookAnnotations {\n\n\t/**\n\t * @action test\n\t */\n\tpublic function test_action() {}\n\n}\n\n$example = new Example();\n$example-\u003eadd_hooks();\n```\n\nOr use the Trait:\n\n```php\nuse Micropackage\\DocHooks\\HookTrait;\n\nclass Example {\n\n\tuse HookTrait;\n\n\t/**\n\t * @action test\n\t */\n\tpublic function test_action() {}\n\n}\n\n$example = new Example();\n$example-\u003eadd_hooks();\n```\n\n### Using as a standalone object\n\n```php\nuse Micropackage\\DocHooks\\Helper;\n\nclass Example {\n\n\t/**\n\t * @action test\n\t */\n\tpublic function test_action() {}\n\n}\n\n$example = Helper::hook( new Example() );\n```\n\n### Fallback\n\nBecause the HookAnnotations object stores the called hooks in `_called_doc_hooks` property, you are able to pull them out and parse them into a list of old `add_action`, `add_filter` and `add_shortcode` functions.\n\nFor this you'll need a central \"repository\" of all objects with hooks ie. Runtime class. [See the example of this approach](https://github.com/BracketSpace/Notification/blob/master/src/Cli/DumpHooks.php) in the Notification plugin, which uses the WP CLI to dump all the hooks into separate file.\n\n## 📦 About the Micropackage project\n\nMicropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.\n\nThe aim is to have multiple packages which can be put together to create something bigger by defining only the structure.\n\nMicropackages are maintained by [BracketSpace](https://bracketspace.com).\n\n## 📖 Changelog\n\n[See the changelog file](./CHANGELOG.md).\n\n## 📃 License\n\nThis software is released under MIT license. See the [LICENSE](./LICENSE) file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicropackage%2Fdochooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicropackage%2Fdochooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicropackage%2Fdochooks/lists"}