All Projects → micropackage → dochooks

micropackage / dochooks

Licence: GPL-3.0 license
WordPress hooks in method comments. Annotated hooks.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to dochooks

filesystem
Wrapper for WordPress' Filesystem for easier file manipulations
Stars: ✭ 19 (-42.42%)
Mutual labels:  composer-library, micropackage, bracketspace
block-loader
Automatic WordPress Gutenberg block loader based on template files
Stars: ✭ 21 (-36.36%)
Mutual labels:  composer-library, micropackage, bracketspace
cache
WordPress cache wrapper
Stars: ✭ 13 (-60.61%)
Mutual labels:  composer-library, micropackage
requirements
Requirements checker for WordPress plugins
Stars: ✭ 37 (+12.12%)
Mutual labels:  composer-library, micropackage
cocktail
Traits, Talents & Annotations for NodeJS.
Stars: ✭ 65 (+96.97%)
Mutual labels:  annotations
annotated
Schema generation using annotated entities and mappers
Stars: ✭ 19 (-42.42%)
Mutual labels:  annotations
zf-dependency-injection
Advanced dependency injection for laminas framework
Stars: ✭ 17 (-48.48%)
Mutual labels:  annotations
graphql-metadata
Annotate your graphql schema with lightweight directives
Stars: ✭ 28 (-15.15%)
Mutual labels:  annotations
ScoutAR
Augmented reality app displays nearby restaurant information in a live camera and map view.
Stars: ✭ 28 (-15.15%)
Mutual labels:  annotations
SimpleVideoAnnotation
A simple video annotation made with python + OpenCV for detection in YoloV2 format
Stars: ✭ 13 (-60.61%)
Mutual labels:  annotations
soap-typescript
SOAP decorators for creating wsdl's and annotating services to provide metadata for node-soap
Stars: ✭ 20 (-39.39%)
Mutual labels:  annotations
geantyref
Advanced generic type reflection library with support for working with AnnotatedTypes (for Java 8+)
Stars: ✭ 73 (+121.21%)
Mutual labels:  annotations
ClassifyCNV
ClassifyCNV: a tool for clinical annotation of copy-number variants
Stars: ✭ 33 (+0%)
Mutual labels:  annotations
aspecio
Aspecio, AOP Proxies for OSGi services
Stars: ✭ 14 (-57.58%)
Mutual labels:  annotations
Symfony-4-by-Samples
Symfony 4 by Samples is a personal project in which I will be creating small demos with tutorial in which to learn the symfony framework 4. Each of the samples contains a README.md file that indicates the purpose of the sample plus an step by step guide to reproduce it. Basic topics, login and register form, authentication, webpack encore, sass…
Stars: ✭ 40 (+21.21%)
Mutual labels:  annotations
gum
Repository for the Georgetown University Multilayer Corpus (GUM)
Stars: ✭ 71 (+115.15%)
Mutual labels:  annotations
Exact
An open source online platform for collaborative image labeling of almost everything
Stars: ✭ 47 (+42.42%)
Mutual labels:  annotations
com2ann
Tool for translation type comments to type annotations in Python
Stars: ✭ 115 (+248.48%)
Mutual labels:  annotations
api-router
👨 RESTful router for your API in Nette Framework (@nette). Created either directly or via annotation.
Stars: ✭ 18 (-45.45%)
Mutual labels:  annotations
2vcf
convert 23andme or Ancestry.com raw genotype calls into VCF format, with dbSNP annotations
Stars: ✭ 42 (+27.27%)
Mutual labels:  annotations

DocHooks

BracketSpace Micropackage Latest Stable Version PHP from Packagist Total Downloads License

Micropackage logo

🧬 About DocHooks

The 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.

DocHooks package allows you to do:

class Example extends HookAnnotations {

	/**
	 * @action test
	 */
	public function test_action() {}

	/**
	 * @filter test 5
	 */
	public function test_filter( $val, $arg ) {
		return $val;
	}

	/**
	 * @shortcode test
	 */
	public function test_shortcode( $atts, $content ) {
		return 'This is test';
	}

}

$example = new Example();
$example->add_hooks();

Instead of old:

$example = new Example();

add_action( 'test', [ $example, 'test_action' ] );
add_filter( 'test', [ $example, 'test_filter' ], 5, 2 );
add_shortcode( 'test', [ $example, 'test_shortcode' ] );

💾 Installation

composer require micropackage/dochooks

🕹 Usage

Annotations

@action <hook_name*> <priority>
@filter <hook_name*> <priority>
@shortcode <shortcode_name*>

The hook and shortcode name is required while default priority is 10.

You don't provide the argument count, the class will figure it out. Just use the callback params you want.

Test if DocHooks are working

When OPCache has the save_comments and load_comments disabled, this package won't work, because the comments are stripped down. See the fallback solution.

use Micropackage\DocHooks\Helper;

(bool) Helper::is_enabled();

Using within the class

You can extend the HookAnnotations class:

use Micropackage\DocHooks\HookAnnotations;

class Example extends HookAnnotations {

	/**
	 * @action test
	 */
	public function test_action() {}

}

$example = new Example();
$example->add_hooks();

Or use the Trait:

use Micropackage\DocHooks\HookTrait;

class Example {

	use HookTrait;

	/**
	 * @action test
	 */
	public function test_action() {}

}

$example = new Example();
$example->add_hooks();

Using as a standalone object

use Micropackage\DocHooks\Helper;

class Example {

	/**
	 * @action test
	 */
	public function test_action() {}

}

$example = Helper::hook( new Example() );

Fallback

Because 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.

For this you'll need a central "repository" of all objects with hooks ie. Runtime class. See the example of this approach in the Notification plugin, which uses the WP CLI to dump all the hooks into separate file.

📦 About the Micropackage project

Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.

The aim is to have multiple packages which can be put together to create something bigger by defining only the structure.

Micropackages are maintained by BracketSpace.

📖 Changelog

See the changelog file.

📃 License

GNU General Public License (GPL) v3.0. See the LICENSE file for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].