File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
55The format is based on [ Keep a Changelog] [ keepachangelog ] and this project adheres to [ Semantic Versioning] [ semver ] .
66
7+ ## v4.5.0
8+
9+ ### Added
10+
11+ - Add trait ` HasPrePostActions `
12+
713## v4.4.2
814
915### Changed
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Php \Support \Traits ;
6+
7+ trait HasPrePostActions
8+ {
9+ /** @var array<string,array<callable>> */
10+ protected array $ executeCallbacks = [];
11+
12+ public function addCallbackAction (string $ key , callable $ action ): self
13+ {
14+ $ this ->executeCallbacks [$ key ][] = $ action ;
15+
16+ return $ this ;
17+ }
18+
19+ public function getCallbackActions (string $ key ): array
20+ {
21+ return (array )($ this ->executeCallbacks [$ key ] ?? []);
22+ }
23+
24+ protected function runActions (string $ actionGroup , ...$ arguments ): bool
25+ {
26+ foreach ($ this ->getCallbackActions ($ actionGroup ) as $ action ) {
27+ $ res = $ action (...$ arguments );
28+ if ($ res === false ) {
29+ return false ;
30+ }
31+ }
32+
33+ return true ;
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments