Download the PHP package pokmot/hooks without Composer

On this page you can find all versions of the php package pokmot/hooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hooks

Wordpress Hooks Reworked

This code contains improvements on the Wordpress hooks system.

It works in a very similar way to the original Wordpress code, but has no dependencies at all.

Rather than functions, it's a namespaced static class using PSR-4.

Load like normal composer packages:

Add a filter:

The above filters are all added with standard priority and will be executed in order.

Call a filter:

$value = Hooks::filter('my_filter_name', 123);

You can add an event instead.

Hooks::addEvent('my_event_name', 'filter_function');

Trigger an event:

Hooks::trigger('my_event_name');

You can pass any number of arguments; only the first argument will be changed by the function (UNLESS they are objects - no cloning involved):

$value = Hooks::filter('my_filter_name', 123, 456, 789);

Very important - both for filters and triggers, none of the arguments are immutable IF they are objects. However, already immutable objects will of course stay immutable.

Use case

Use whenever you want to be able to change a value, or signal that something has happened in your code.

Perfect places to use it:

Writing your own framework? Some places you can callfilters or triggers it are:

Why has this class been created?

Quite simply, the Wordpress hook system is powerful and easy to use. It's a key part of why Wordpress is successful as it allows anyone to change the behaviour of Wordpress on a very deep level, without actually hacking the core code.

I wanted this for my own systems. At the time there weren't a huge number of options. Now there are more, both Laravel and Symfony as well as The League of Extraordinary Packages offer similar functionality, but I found all of them either cumbersome or requiring lots of extra components I didn't really want to install.

For instance, in Symfony you have to create a listener and add to a dispatcher, and you have Subscribers etc.

Here, you simply call the filter whenever it's needed in your code. Any piece of code can attach itself and listen with a one-line static class call.

Easy.

I realise making it a static class means it's difficult to mock in unit tests. If that's a concern then this class might not be right for you. Consider making it a non-static class; it should be easy.

However, a simple call to Hooks::clear(); is enough to clear out all filters and events - I would suggest you should create your unit tests with NO filters or events, and test those separately, so this should not really be an issue. Just issue clear() in your setup or tear-down of the unit tests.

Next Steps

I have done some refactoring of the code before publishing it on GitHub; I have used this code in production for several years but I am keeping the revision to 0.x until I have fully tested the refactoring.

The function calls will not change between 0.x and 1.x versions.

SemVer will be followed from v 1.x onwards.

What's left to do?

Licensing

I am guessing this should be under the GPLv2 license as the code is derived from the Wordpress Hooks system which is GPLv2. Personally I'd like to make this a MIT license - if anyone has feedback on this, feel free to let me know by creating an Issue.

How that affects your code I leave as an exercise to the reader; any feedback is appreciated.


All versions of hooks with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pokmot/hooks contains the following files

Loading the files please wait ....