Download the PHP package coinvestor/larahook without Composer

On this page you can find all versions of the php package coinvestor/larahook. 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 larahook

LaraHook - A Hook engine for Laravel

This is a maintained fork of the now inactive esemve/Hook library for laravel 8.

In most cases this library can be used as a drop in replacement, although some changes may require minor updates to your code. Please see the differences section for more information on the changes between this library and esemve/Hook

What is this?

Hooks allow programmers to make parts of their application open to being modified or adjusted from other locations within the code base. For example allowing an application modify the behavior of your package without them needing directly edit its source code.

What is a Hook?

It is similar to an event. A code bounded by a hook runs unless a hook listener catches it and orders that instead of the function in the hook, something else should run. They could be set in an established order, so you are able to make several modifications in the code.

What is it good for?

Example 1: You have a module which displays an editor. This remains the same editor in every case. If you bound the display of the editor in a hook, then you can write a module which can redefine/override this hook, and for example changs the textarea to a ckeditor.

Example 2: You list the users. You can include every line's print in a hook. This way you can write a separate module which could extend this line with an e-mail address print.

Example 3: You save the users' data in a database. If you do it in a hook, you can write a module which could add extra fields to the user model like "first name" or "last name". To do that, you didn't need to modify the code that handles the users, the extension module doesn't need to know the functioning of the main module.

... and so many other things. If you are building a CMS-like system, it will make your life a lot easier.

How do I install it?

How does it work?

Example code

In this case a fillUser hook is thrown, which receive the $user object as a parameter. If nothing catches it, the internal function, the return $user will run, so nothing happens. But it can be caught by a listener from a provider:

The $callback contains the hook's original internal function, so it can be called here.

Multiple listeners could be registered to a hook, so in the $output the listener receives the response of the previously registered listeners of the hook.

THen come the parameters delivered by the hook, in this case the user.

The hook listener above caught the call of the fillUser, extended the received object, and returned it to its original place. After the run of the hook the $user object contains a profileImage variable as well.

Number 10 in the example is the priority. They are executed in an order, so if a number 5 is registered to the fillUser as well, it will run before number 10.

Methods

Get

Run a hook and return some data. Listeners for the hook will be triggered and the final result from these will be returned.

Listen

Listen for the hook and either carry out an action or manipulated the output before it is returned.

Initial output

By passing true as the 4th paramater to the get you can ensure the default callback provided will always run, passing its self as the initial output value.

If there is no listeners, 'Hi Delilah' will be returned.

Usage in blade templates

In this case the hook listener can catch it like this:

In the $variables variable it receives all of the variables that are available for the blade template.

:exclamation: To listen blade templates you need to listen template.hookName instead of just hookName!

Wrap HTML

Now the $output parameter contains html wrapped by hook component.

Stop

Put in a hook listener it stops the running of the other listeners that are registered to this hook.

For testing

After that the hookName hook will return returnValue as a response.

Artisan

Lists all the active hook listeners.

Differences between this and esemve/Hook


License: MIT


All versions of larahook with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
laravel/framework Version ^11.14
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 coinvestor/larahook contains the following files

Loading the files please wait ....