ActionsProxy.php
41 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ActionsProxy class file. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Proxies; |
| 7 | |
| 8 | /** |
| 9 | * Proxy for interacting with WordPress actions and filters. |
| 10 | * |
| 11 | * This class should be used instead of directly accessing the WordPress functions, to ease unit testing. |
| 12 | */ |
| 13 | class ActionsProxy { |
| 14 | |
| 15 | /** |
| 16 | * Retrieve the number of times an action is fired. |
| 17 | * |
| 18 | * @param string $tag The name of the action hook. |
| 19 | * |
| 20 | * @return int The number of times action hook $tag is fired. |
| 21 | */ |
| 22 | public function did_action( $tag ) { |
| 23 | return did_action( $tag ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Calls the callback functions that have been added to a filter hook. |
| 28 | * |
| 29 | * @param string $tag The name of the filter hook. |
| 30 | * @param mixed $value The value to filter. |
| 31 | * @param mixed ...$parameters Additional parameters to pass to the callback functions. |
| 32 | * |
| 33 | * @return mixed The filtered value after all hooked functions are applied to it. |
| 34 | */ |
| 35 | public function apply_filters( $tag, $value, ...$parameters ) { |
| 36 | return apply_filters( $tag, $value, ...$parameters ); |
| 37 | } |
| 38 | |
| 39 | // TODO: Add the rest of the actions and filters related methods. |
| 40 | } |
| 41 |