Skip to content

Commit 6388e07

Browse files
committed
Merge branch 'release/1.1.0'
2 parents 7acb823 + 45b8fb5 commit 6388e07

File tree

15 files changed

+614
-177
lines changed

15 files changed

+614
-177
lines changed

.actionspanel/buttons.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
buttons:
2+
- title: Release new version
3+
action: "release"
4+
description: Releases new version
5+
arguments:
6+
- name: new_version

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on: repository_dispatch
4+
5+
jobs:
6+
release:
7+
if: github.event.action == 'release'
8+
name: Release
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout master
12+
uses: actions/checkout@v1
13+
with:
14+
ref: 'master'
15+
- name: Checkout develop
16+
uses: actions/checkout@v1
17+
with:
18+
ref: 'develop'
19+
clean: false
20+
- name: Install git-flow
21+
run: sudo apt-get install git-flow -y
22+
- name: Configure commiter
23+
run: |
24+
git config --local user.email "${{ secrets.WORKER_EMAIL }}"
25+
git config --local user.name "${{ secrets.WORKER_NAME }}"
26+
- name: Init git-flow
27+
run: git flow init -d
28+
- name: Start release
29+
run: git flow release start ${{ github.event.client_payload.new_version }}
30+
- name: Replace [Next] tags with new version number
31+
uses: jacobtomlinson/gha-find-replace@master
32+
with:
33+
find: "(?i)\\[Next\\]"
34+
replace: "${{ github.event.client_payload.new_version }}"
35+
- name: Commit version bump
36+
run: git commit -am "Version bump"
37+
- name: Finish release
38+
run: git flow release finish ${{ github.event.client_payload.new_version }} -m "v${{ github.event.client_payload.new_version }}"
39+
- name: Push develop and tags
40+
uses: ad-m/github-push-action@master
41+
with:
42+
github_token: ${{ secrets.WORKER_TOKEN }}
43+
branch: 'develop'
44+
- name: Push master
45+
uses: ad-m/github-push-action@master
46+
with:
47+
github_token: ${{ secrets.WORKER_TOKEN }}
48+
branch: 'master'

.github/workflows/stable.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Stable
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
10+
# Release on GitHub
11+
github-release:
12+
name: Release on GitHub
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Parse changelog
18+
run: |
19+
START="## ${{ steps.vars.outputs.version }}"
20+
END="## [0-9]+.[0-9]+.[0-9]+|\$"
21+
grep -oPz "(?s)${START}.*?\n\K.*?(?=${END})" CHANGELOG.md > changelog.txt
22+
truncate -s-3 changelog.txt
23+
sed -i '1d' changelog.txt
24+
- name: Release
25+
uses: softprops/action-gh-release@v1
26+
with:
27+
body_path: changelog.txt
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Test
2+
3+
on: ['pull_request', 'push']
4+
5+
jobs:
6+
phpcs:
7+
name: WordPress Coding Standards
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
- name: Install dependencies
13+
run: composer install --no-progress
14+
- name: Coding Standards
15+
run: composer phpcs

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [1.0.0] - 07.01.2020
4+
## 1.1.0
5+
6+
### Added
7+
- Central Hooks class storing hooked objects
8+
- `dump-hooks` binary
9+
10+
## 1.0.2
11+
12+
### Added
13+
- HookTrait Trait
14+
15+
### Changed
16+
- HookAnnotations now uses HookTrait
17+
18+
## 1.0.1
19+
20+
### Fixed
21+
- AnnotationTest class giving a fatal error because of a wrong file name, issue #1
22+
23+
## 1.0.0
524

625
Initial release

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
[![Total Downloads](https://poser.pugx.org/micropackage/dochooks/downloads)](https://packagist.org/packages/micropackage/dochooks)
77
[![License](https://poser.pugx.org/micropackage/dochooks/license)](https://packagist.org/packages/micropackage/dochooks)
88

9+
<p align="center">
10+
<img src="https://bracketspace.com/extras/micropackage/micropackage-small.png" alt="Micropackage logo"/>
11+
</p>
12+
913
## 🧬 About DocHooks
1014

1115
The Laravel or Symfony projects are using method annotations for various things. This helps to have the project organized without too much code. WordPress has no implementation of such concept and this package is a remedy.
@@ -82,7 +86,11 @@ use Micropackage\DocHooks\Helper;
8286

8387
### Using within the class
8488

89+
You can extend the HookAnnotations class:
90+
8591
```php
92+
use Micropackage\DocHooks\HookAnnotations;
93+
8694
class Example extends HookAnnotations {
8795

8896
/**
@@ -96,6 +104,26 @@ $example = new Example();
96104
$example->add_hooks();
97105
```
98106

107+
Or use the Trait:
108+
109+
```php
110+
use Micropackage\DocHooks\HookTrait;
111+
112+
class Example {
113+
114+
use HookTrait;
115+
116+
/**
117+
* @action test
118+
*/
119+
public function test_action() {}
120+
121+
}
122+
123+
$example = new Example();
124+
$example->add_hooks();
125+
```
126+
99127
### Using as a standalone object
100128

101129
```php

bin/dump-hooks

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* This file uses wp-cli to run real hook dumper.
5+
*
6+
* @package micropackage/dochooks
7+
*/
8+
9+
$file = __DIR__ . '/dump-hooks.php';
10+
11+
$output_file = $_SERVER['argc'] >= 2 ? $_SERVER['argv'][1] : null;
12+
13+
if ( $output_file ) {
14+
$output_file = realpath( __DIR__ . '../../../../../' . $output_file );
15+
}
16+
17+
echo shell_exec( "wp eval-file {$file} {$output_file}" );

bin/dump-hooks.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* This file dumps all the Dochooks to an external file: /src/inc/hooks.php
4+
* It's used only when OP Cache has `save_comments` setting saved to false.
5+
*
6+
* @usage: wp eval-file dump-hooks.php
7+
* @usage: wp eval-file wp-content/plugins/{plugin-name}/vendor/bin/dump-hooks.php
8+
*
9+
* @package micropackage/dochooks
10+
*/
11+
12+
use Micropackage\DocHooks\Hooks;
13+
14+
if ( ! isset( $args[0] ) ) {
15+
WP_CLI::error( 'Output file not specified.' );
16+
return;
17+
}
18+
19+
$hooks_file = $args[0];
20+
21+
$hooks = Hooks::get();
22+
$objects = $hooks->get_hooked_objects();
23+
24+
$hook_functions = [];
25+
26+
// Loop over each class who added own hooks.
27+
foreach ( $objects as $class_name => $data ) {
28+
$count = 0;
29+
30+
$callback_object_name = '$this->objects[\'' . $class_name . '\'][\'instance\']';
31+
32+
foreach ( $data['hooks'] as $hook ) {
33+
$hook_functions[] = sprintf(
34+
"add_%s( '%s', [ %s, '%s' ], %d, %d );",
35+
$hook['type'],
36+
$hook['name'],
37+
$callback_object_name,
38+
$hook['callback'],
39+
$hook['priority'],
40+
$hook['arg_count']
41+
);
42+
43+
$count++;
44+
}
45+
46+
WP_CLI::log( "{$class_name} added {$count} hooks" );
47+
}
48+
49+
// // Clear the hooks file.
50+
// $hooks_file = EW_DIR_PATH . '/src/inc/hooks.php';
51+
52+
if ( file_exists( $hooks_file ) ) {
53+
unlink( $hooks_file );
54+
}
55+
56+
$hook_functions = implode( "\n", $hook_functions );
57+
58+
// Save the content.
59+
$file_content = <<<EOT
60+
<?php
61+
/**
62+
* Hooks compatibilty file.
63+
*
64+
* Automatically generated with bin/dump-hooks.php file.
65+
*/
66+
67+
// phpcs:disable
68+
69+
{$hook_functions}
70+
71+
EOT;
72+
73+
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
74+
file_put_contents( $hooks_file, $file_content );
75+
WP_CLI::success( 'All the hooks dumped!' );

composer.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
"phpcbf": "phpcbf"
1414
},
1515
"require": {
16-
"php": ">=5.6"
16+
"php": ">=5.6",
17+
"micropackage/singleton": "^1.1"
1718
},
1819
"require-dev": {
19-
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
20-
"phpcompatibility/php-compatibility": "^9.1",
21-
"wp-coding-standards/wpcs": "^2.0"
20+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
21+
"phpcompatibility/php-compatibility": "^9.3",
22+
"wp-coding-standards/wpcs": "^2.3"
2223
},
2324
"autoload": {
2425
"psr-4" : {
2526
"Micropackage\\DocHooks\\" : "src"
2627
}
27-
}
28+
},
29+
"bin": ["bin/dump-hooks"]
2830
}

0 commit comments

Comments
 (0)