Skip to content

Commit e8268f9

Browse files
committed
Update README.md: enhance documentation with installation, usage examples, and contribution guidelines
1 parent e538227 commit e8268f9

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,85 @@
11
# Laravel Hookable
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/saschaende/laravel-hookable.svg?style=flat-square)](https://packagist.org/packages/saschaende/laravel-hookable)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/saschaende/laravel-hookable/run-tests?label=tests&style=flat-square)](
4+
5+
Laravel Hookable is a package that allows you to easily add hooks (actions and filters) to your Laravel applications,
6+
similar to the hook system in WordPress.
7+
8+
## Installation
9+
10+
You can install the package via Composer:
11+
12+
```bash
13+
composer require saschaende/laravel-hookable
14+
```
15+
16+
## Usage
17+
18+
### Adding Hooks
19+
20+
You can add hooks using the `Hookable` facade. There are two types of hooks: actions and filters.
21+
22+
#### Actions
23+
24+
Actions are hooks that do not modify data. You can add an action like this:
25+
26+
```php
27+
use SaschaEnde\Hookable\Facades\Hookable;
28+
Hookable::addAction('my_action', function ($arg1, $arg2) {
29+
// Do something with $arg1 and $arg2
30+
});
31+
```
32+
33+
You can then trigger the action like this:
34+
35+
```php
36+
Hookable::doAction('my_action', $arg1, $arg2);
37+
```
38+
39+
#### Filters
40+
41+
Filters are hooks that modify data. You can add a filter like this:
42+
43+
```php
44+
use SaschaEnde\Hookable\Facades\Hookable;
45+
Hookable::addFilter('my_filter', function ($value) {
46+
// Modify $value
47+
return $value;
48+
});
49+
```
50+
51+
You can then apply the filter like this:
52+
53+
```php
54+
$value = Hookable::applyFilters('my_filter', $value);
55+
```
56+
57+
### Priorities and Arguments
58+
59+
You can specify the priority and number of arguments for your hooks.
60+
61+
```php
62+
Hookable::addAction('my_action', function ($arg1, $arg2) {
63+
// Do something
64+
}, 20);
65+
```
66+
67+
In this example, the action will be executed with a priority of 20 and will receive
68+
2 arguments.
69+
70+
## Testing
71+
72+
You can run the tests using PHPUnit:
73+
74+
```bash
75+
vendor/bin/phpunit
76+
```
77+
78+
## Contributing
79+
80+
Contributions are welcome! Please submit a pull request or open an issue on GitHub.
81+
82+
## License
83+
84+
This package is open-sourced software licensed under the MIT license.
85+

0 commit comments

Comments
 (0)