Skip to content

Commit

Permalink
v2.x (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
tfirdaus committed May 12, 2024
1 parent 52e389f commit d22ce6a
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 58 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/wp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ on:
- "phpunit.xml.dist"

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Setup Composer cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: php-7.4-composer-${{ hashFiles('**/composer.json') }}
restore-keys: php-7.4-composer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist

- name: Lint codes
run: composer phpcs

test:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -98,7 +128,6 @@ jobs:
- name: Run test
run: |
composer phpcs
composer phpstan
vendor/bin/phpunit --coverage-clover coverage.xml
env:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ composer require syntatis/wp-hook
## Usage

```php
use Syntatis\WP\Hook\Hook;
use Syntatis\WPHook\Hook;

$hook = new Hook();
$hook->addAction( 'init', 'initialise' );
Expand All @@ -51,9 +51,9 @@ $hook->run();
If your WordPress theme or plugin is using PHP 8.0, you can use [PHP Attributes](https://www.php.net/manual/en/language.attributes.overview.php) to add the hooks.

```php
use Syntatis\WP\Hook\Action;
use Syntatis\WP\Hook\Filter;
use Syntatis\WP\Hook\Hook;
use Syntatis\WPHook\Action;
use Syntatis\WPHook\Filter;
use Syntatis\WPHook\Hook;

#[Action(tag: "wp")]
class HelloWorld
Expand Down
2 changes: 1 addition & 1 deletion app/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Syntatis\WP\Hook;
namespace Syntatis\WPHook;

use Attribute;

Expand Down
2 changes: 1 addition & 1 deletion app/Attributes/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Syntatis\WP\Hook\Attributes;
namespace Syntatis\WPHook\Attributes;

abstract class Model
{
Expand Down
8 changes: 4 additions & 4 deletions app/Attributes/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Syntatis\WP\Hook\Attributes;
namespace Syntatis\WPHook\Attributes;

use ReflectionClass;
use Syntatis\WP\Hook\Action;
use Syntatis\WP\Hook\Filter;
use Syntatis\WP\Hook\Hook;
use Syntatis\WPHook\Action;
use Syntatis\WPHook\Filter;
use Syntatis\WPHook\Hook;

use function is_callable;

Expand Down
4 changes: 2 additions & 2 deletions app/Contract/WithHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Syntatis\WP\Hook\Contract;
namespace Syntatis\WPHook\Contract;

use Syntatis\WP\Hook\Hook;
use Syntatis\WPHook\Hook;

interface WithHook
{
Expand Down
4 changes: 2 additions & 2 deletions app/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace Syntatis\WP\Hook;
namespace Syntatis\WPHook;

use Attribute;
use Syntatis\WP\Hook\Attributes\Model;
use Syntatis\WPHook\Attributes\Model;

#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class Filter extends Model
Expand Down
18 changes: 16 additions & 2 deletions app/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Syntatis\WP\Hook;
namespace Syntatis\WPHook;

use Syntatis\WP\Hook\Attributes\Parser;
use Syntatis\WPHook\Attributes\Parser;

/**
* Register all actions and filters for the plugin.
Expand Down Expand Up @@ -99,4 +99,18 @@ public function annotated(object $obj): void
{
new Parser($obj, $this);
}

public function removeAllActions(): void
{
foreach ($this->actions as $hook) {
remove_action($hook['hook'], $hook['callback'], $hook['priority']);
}
}

public function removeAllFilters(?string $group = null): void
{
foreach ($this->filters as $hook) {
remove_filter($hook['hook'], $hook['callback'], $hook['priority']);
}
}
}
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
],
"autoload": {
"psr-4": {
"Syntatis\\WP\\Hook\\": "app/"
"Syntatis\\WPHook\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Syntatis\\WP\\Hook\\Tests\\": "tests/phpunit/"
"Syntatis\\WPHook\\Tests\\": "tests/phpunit/"
}
},
"require": {
"php": "^7.4 || ^8.0"
"php": "^7.4 || ^8.0",
"syntatis/utils": "^1.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
Expand All @@ -37,6 +38,7 @@
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.6",
"roots/wordpress": "^6.5",
"symfony/var-dumper": "^5.4",
"syntatis/coding-standard": "^1.1",
"szepeviktor/phpstan-wordpress": "^1.3",
"wp-phpunit/wp-phpunit": "^6.5",
Expand Down
4 changes: 2 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array">
<element key="app" value="Syntatis\WP\Hook"/>
<element key="tests/phpunit" value="Syntatis\WP\Hook\Tests"/>
<element key="app" value="Syntatis\WPHook"/>
<element key="tests/phpunit" value="Syntatis\WPHook\Tests"/>
</property>
</properties>
</rule>
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/Attributes/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Syntatis\WP\Hook\Tests\Attributes;
namespace Syntatis\WPHook\Tests\Attributes;

use Syntatis\WP\Hook\Action;
use Syntatis\WP\Hook\Contract\WithHook;
use Syntatis\WP\Hook\Filter;
use Syntatis\WP\Hook\Hook;
use Syntatis\WP\Hook\Tests\TestCase;
use Syntatis\WPHook\Action;
use Syntatis\WPHook\Contract\WithHook;
use Syntatis\WPHook\Filter;
use Syntatis\WPHook\Hook;
use Syntatis\WPHook\Tests\TestCase;

use function array_key_first;

Expand Down
Loading

0 comments on commit d22ce6a

Please sign in to comment.