-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 31a6d16
Showing
13 changed files
with
2,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Hadi Akbarzadeh | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# File Hooker for PHP | ||
|
||
> A simple Hooking System based on files. | ||
> This means that each callback is located in a PHP file. | ||
## 🫡 Usage | ||
|
||
### 🚀 Installation | ||
|
||
You can install the package via composer: | ||
|
||
```bash | ||
composer require nabeghe/file-hooker | ||
``` | ||
|
||
### 📁 Hooks Directory | ||
|
||
Create a directory for your hooks. | ||
|
||
The name of each php file in this directory without suffix (.php) will be the name of your hook. | ||
Subdirectories are also allowed. | ||
|
||
Each file returns a callback. This callback receives two arguments, data and angler. | ||
Data is the items sent to the callback. In filters, it must be an array, but in actions, it can be anything. | ||
Index 0 of data in filters is what is filtered. But in callbacks, the array itself must be returned. | ||
|
||
### Example | ||
|
||
```php | ||
<?php | ||
|
||
use Nabeghe\FileHooker\FileHooker; | ||
|
||
// This is a custom object called angler. It is sent as the second argument to the callbacks. | ||
$angler = new stdClass(); | ||
$angler = new FileHooker($angler); | ||
|
||
// Add a new path where the hooks are located. | ||
$hooker->add(__DIR__.'/hooks'); | ||
|
||
// Action | ||
$hooker->action('print', ['text' => 'Hi']); | ||
|
||
// Filter | ||
$result = $hooker->filter('remove_spaces', ['Hadi Akbarzadeh']); | ||
echo $result; | ||
``` | ||
|
||
Create a file named `print.php` in the hooks directory: | ||
|
||
```php | ||
<?php | ||
|
||
return function ($data, $angler) { | ||
echo $data['text']; | ||
}; | ||
``` | ||
|
||
Create a file named `remove_spaces.php` in the hooks directory: | ||
|
||
```php | ||
<?php | ||
|
||
return function ($data, $angler) { | ||
$data = str_replace(' ', '', $data[0]); | ||
return $data; | ||
}; | ||
``` | ||
|
||
## 📖 License | ||
|
||
Copyright (c) 2024 Hadi Akbarzadeh | ||
|
||
Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "nabeghe/file-hooker", | ||
"description": "Hooking System based on files.", | ||
"type": "library", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/nabeghe/php-file-hooker", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Nabeghe\\FileHooker\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Hadi Akbarzadeh", | ||
"email": "[email protected]", | ||
"homepage": "https://ElaTel.IR", | ||
"role": "Developer" | ||
} | ||
], | ||
"scripts": { | ||
"test": "vendor/bin/phpunit tests" | ||
}, | ||
"require": { | ||
"php": ">=7.4" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.0" | ||
} | ||
} |
Oops, something went wrong.