Download the PHP package rubenmartindev/prestashop-module-hook-bus without Composer

On this page you can find all versions of the php package rubenmartindev/prestashop-module-hook-bus. 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 prestashop-module-hook-bus

PrestaShop Hook Bus

This library provides a flexible and centralized way to route and handle PrestaShop hooks.

Overview

As you develop your module and add hooks to the main file, the module can grow disproportionately; all logic ends up in a single place, breaking the SOLID Single Responsibility principle and making maintenance and readability chaotic.

Ideally, each hook should be self-contained and have a single responsibility. Making it easy to configure, use, and maintain.

Compared to managing hooks directly in your module's main class, Hook Bus offers:

The library is composed of three main building blocks:

Requirements

Installation

Install via Composer in your PrestaShop module:

Complete Example

A typical module structure could look like this:

Configure the Hook Bus once in the module constructor:

Each hook is implemented in its own Handler:

Factory

To make configuring and creating the Hook Bus easier, HookBusFactory provides static methods:

Method Best suited for
create() Full control over the Identifier and Locator.
createWithArray() Quick setup using an array of handlers.
createWithCallable() Dynamic handler resolution.
createWithContainer() Symfony service containers and Dependency Injection.

HookBusFactory::create()

Argument Type Description
hookIdentifier HookIdentifierInterface The Identifier that will be used to locate the Handler.
handlerLocator HandlerLocatorInterface The Locator where the Handlers are registered.

Example

HookBusFactory::createWithArray()

Argument Type Description
hookIdentifier HookIdentifierInterface The Identifier that will be used to locate the Handler.
handlers array An array with key representing the Identifier and value the Handler. If the handler implements NamedHandlerInterface, key is optional.

Example

HookBusFactory::createWithCallable()

Argument Type Description
hookIdentifier HookIdentifierInterface The Identifier that will be used to locate the Handler.
callable callable A callback that will resolve which Handler will be used.

Example

HookBusFactory::createWithContainer()

Argument Type Description
container ContainerInterface Container where services are registered.
hookIdentifier HookIdentifierInterface The Identifier that will be used to locate the Handler.
handlers array An array with key representing the Identifier and value the service to use as Handler. If the handler implements NamedHandlerInterface, key is optional.

Example

[!NOTE] Service container integration requires PrestaShop 1.7 or higher, as PrestaShop 1.6 does not use Symfony, or, use your own container, for example prestashop/module-lib-service-container.

Identifier

Used to identify the hook and to locate the corresponding Handler during the dispatch cycle.

If the Identifier cannot resolve the identity, it will throw the exception UnresolvedHookIdentifierException.

Literal

The provided string will be used literally as the identifier.

Example

Method Hook

Designed to be used inside the module's public hook<hook_name>() methods. It obtains the identifier from the method name; for example, the method hookActionAdminControllerSetMedia() will be the identifier actionAdminControllerSetMedia.

Example

Callable

Through a callback we can generate a custom identifier.

Example

Custom Identifier

You can create your own Identifiers to generate custom identities. It should implement the interface HookIdentifierInterface.

Example

Locator

Where Handlers are located and which identities are associated with them.

If the Locator cannot resolve which Handler is assigned to the identity, it will throw the exception MissingHandlerException.

Array

Example

Callable

Example

Container

Example

Custom Locator

You can create your own Locators that return which Handler will manage the hook. It should implement the interface HandlerLocatorInterface.

If you want it to be compatible with the Factory, you should implement the interface AppendableHandlerLocatorInterface to enable the addHandler() method.

Example

Handler

Handlers are responsible for resolving what to do with the hook. They must implement the interface HookHandlerInterface.

The handle() method receives the $params argument, which is the same argument that the native hook<hook_name>() method of the module received.

If the Handler implements the interface NamedHandlerInterface, the Factory can infer the identity automatically from the static method getIdentityName().

Example

Exceptions

All library exceptions extend HookBusException.

Exception Description
MissingHandlerException No Handler was found for the resolved identity.
UnresolvedHookIdentifierException The Identifier could not resolve an identity.

All versions of prestashop-module-hook-bus with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
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 rubenmartindev/prestashop-module-hook-bus contains the following files

Loading the files please wait ...