Download the PHP package razu/laravel-hooks without Composer

On this page you can find all versions of the php package razu/laravel-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 laravel-hooks

Laravel Hooks

The filter and action system in Laravel is inspired by WordPress hooks

About

Actions are code snippets that run at specific points in your program. They don't return any value but provide a way to hook into your existing code without causing interference.

Filters are designed to alter data. They always return a value, typically the modified version of the first parameter, which is the default return behavior.

Notes: This works similarly to the Observer design pattern, or the Publisher/Subscriber pattern, which is also related to event-driven architecture.

More Resources

Read more about filters

Read more about actions

Read more about filters and actions

Installation

  1. Install using Composer

Great! Now you're ready to use laravel-hooks.

ACTION

EVENT

The do_action function is used to trigger all callback functions attached to a specified action hook ($tag).

Parameters

By calling do_action, you execute all functions linked to the specified hook ($tag), passing any optional arguments to each function. This allows custom code to be run at specific points within the application.

LISTENER

The add_action function associates a callback function with a specified hook ($tag) in a Laravel or WordPress-style hook system. Here’s what each parameter does:

Parameters

By using add_action, you can ensure that your custom functions are executed at the appropriate points in your application’s lifecycle, allowing you to extend or modify functionality as needed.

FILTER

EVENT

The apply_filters function calls all functions attached to a specific filter hook ($tag). This allows you to modify a value by passing it through multiple filters.

Parameters

When apply_filters is called, it sequentially runs all functions associated with hook ($tag), passing $value through each one. This allows custom modifications to be made to the value at specific points in the application.

LISTENER

The add_filter function allows you to modify various types of internal data at runtime by attaching callback functions to specific filter hooks.

Parameters

-$tag (string) (Required) – The name of the filter to which the callback will be added. This specifies the specific filter hook where data modification should occur.

-$callback (callable) (Required) – The callback function to be executed when the filter is applied. This function should process and potentially modify the filtered data.

-$priority (int) (Optional) – Specifies the order in which functions associated with this filter will execute. Lower numbers correspond to earlier execution. Functions with the same priority are executed in the order they were added. The default is 10.

Using add_filter, you can ensure that specific functions modify data when the designated filter is applied, allowing for flexible data processing throughout the application.

Here’s how to pass a callback function:

The callback can be specified in various ways, including:

Examples

Usages

Actions

Anywhere in your code, you can define a new action like this:

Here, user_registered is the action name, which will be used later when the action is being listened to. The $user parameter will be available whenever you listen for the action. This parameter can represent any relevant data.

To listen for your actions, attach listeners at the appropriate points. Another good approach is to add these in the boot() method of your AppServiceProvider.

For example, if you want to hook into the above action, you could do the following:

The first argument must be the name of the action. The second argument can be closures, callbacks, or anonymous functions. The third argument specifies the order in which the functions associated with a particular action are executed. Lower numbers correspond to earlier execution, and functions with the same priority are executed in the order in which they were added to the action. The default value is 10. The fourth argument specifies the number of arguments the function accepts, with the default value being 1.

Filters

Filters must always have data coming in and going out to ensure it reaches the browser for output. Your content might pass through multiple filters before finally being displayed. In contrast, actions—though similar to filters—do not require any data to be returned. However, data can still be passed through actions if needed.

Filters are functions in Laravel applications that allow data to be passed through and modified. They enable developers to adjust the default behavior of specific functions.

Here’s an example of how a filter can be used in a application.

In the Product.php model, we have a getAvailable method that builds a query to fetch all available products:

Using a filter, we can modify this query dynamically:

Now, in the entry point of the application, such as in a module or plugin, you can modify this product availability query.

In the service provider of the module or plugin (ideally within the boot method), we'll register a listener for the filter.

License

This software is licensed under the (MIT) License. For more details, please refer to the License file.

Related Link

https://packagist.org/packages/razu/laravel-hooks


All versions of laravel-hooks with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0|^8.0
laravel/framework Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.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 razu/laravel-hooks contains the following files

Loading the files please wait ....