Skip to content

Commit 31a6d16

Browse files
committed
Initial commit
0 parents  commit 31a6d16

File tree

13 files changed

+2124
-0
lines changed

13 files changed

+2124
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
/vendor/

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Hadi Akbarzadeh
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# File Hooker for PHP
2+
3+
> A simple Hooking System based on files.
4+
> This means that each callback is located in a PHP file.
5+
6+
## 🫡 Usage
7+
8+
### 🚀 Installation
9+
10+
You can install the package via composer:
11+
12+
```bash
13+
composer require nabeghe/file-hooker
14+
```
15+
16+
### 📁 Hooks Directory
17+
18+
Create a directory for your hooks.
19+
20+
The name of each php file in this directory without suffix (.php) will be the name of your hook.
21+
Subdirectories are also allowed.
22+
23+
Each file returns a callback. This callback receives two arguments, data and angler.
24+
Data is the items sent to the callback. In filters, it must be an array, but in actions, it can be anything.
25+
Index 0 of data in filters is what is filtered. But in callbacks, the array itself must be returned.
26+
27+
### Example
28+
29+
```php
30+
<?php
31+
32+
use Nabeghe\FileHooker\FileHooker;
33+
34+
// This is a custom object called angler. It is sent as the second argument to the callbacks.
35+
$angler = new stdClass();
36+
$angler = new FileHooker($angler);
37+
38+
// Add a new path where the hooks are located.
39+
$hooker->add(__DIR__.'/hooks');
40+
41+
// Action
42+
$hooker->action('print', ['text' => 'Hi']);
43+
44+
// Filter
45+
$result = $hooker->filter('remove_spaces', ['Hadi Akbarzadeh']);
46+
echo $result;
47+
```
48+
49+
Create a file named `print.php` in the hooks directory:
50+
51+
```php
52+
<?php
53+
54+
return function ($data, $angler) {
55+
echo $data['text'];
56+
};
57+
```
58+
59+
Create a file named `remove_spaces.php` in the hooks directory:
60+
61+
```php
62+
<?php
63+
64+
return function ($data, $angler) {
65+
$data = str_replace(' ', '', $data[0]);
66+
return $data;
67+
};
68+
```
69+
70+
## 📖 License
71+
72+
Copyright (c) 2024 Hadi Akbarzadeh
73+
74+
Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "nabeghe/file-hooker",
3+
"description": "Hooking System based on files.",
4+
"type": "library",
5+
"version": "1.0.0",
6+
"homepage": "https://github.com/nabeghe/php-file-hooker",
7+
"license": "MIT",
8+
"autoload": {
9+
"psr-4": {
10+
"Nabeghe\\FileHooker\\": "src/"
11+
}
12+
},
13+
"authors": [
14+
{
15+
"name": "Hadi Akbarzadeh",
16+
"email": "[email protected]",
17+
"homepage": "https://ElaTel.IR",
18+
"role": "Developer"
19+
}
20+
],
21+
"scripts": {
22+
"test": "vendor/bin/phpunit tests"
23+
},
24+
"require": {
25+
"php": ">=7.4"
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "^9.0"
29+
}
30+
}

0 commit comments

Comments
 (0)