| 1 |
<?php |
| 2 |
/** |
| 3 |
* ForwardCalls Trait |
| 4 |
* |
| 5 |
* @package Timetics |
| 6 |
*/ |
| 7 |
namespace Timetics\Base; |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || exit; |
| 10 |
|
| 11 |
use BadMethodCallException; |
| 12 |
use Timetics\Base\PostModel; |
| 13 |
|
| 14 |
/** |
| 15 |
* ForwardCalls Trait |
| 16 |
*/ |
| 17 |
trait ForwardCalls { |
| 18 |
/** |
| 19 |
* Handle dynamic method |
| 20 |
* |
| 21 |
* @param PostModel $model |
| 22 |
* @param string $method |
| 23 |
* @param mixed $params |
| 24 |
* |
| 25 |
* @return mixed |
| 26 |
*/ |
| 27 |
protected static function forwardCallToStatic( PostModel $model, $method, $params ) { |
| 28 |
try { |
| 29 |
$post = new Post( $model ); |
| 30 |
|
| 31 |
return $post->$method( ...$params ); |
| 32 |
|
| 33 |
} catch ( BadMethodCallException $e ) { |
| 34 |
static::throwBadMethodCallException( $method ); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Throw a bad method call exception for the given method. |
| 40 |
* |
| 41 |
* @param string $method |
| 42 |
* @return void |
| 43 |
* |
| 44 |
* @throws \BadMethodCallException |
| 45 |
*/ |
| 46 |
protected static function throwBadMethodCallException( $method ) { |
| 47 |
throw new BadMethodCallException( sprintf( |
| 48 |
/* translators: %1$s: Class name, %2$s: Method name */ |
| 49 |
esc_html__( 'Call to undefined method %1$s::%2$s()', 'timetics' ), static::class, esc_html( $method ) |
| 50 |
) ); |
| 51 |
} |
| 52 |
} |
| 53 |
|