Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluent-smtp/includes/Support/MacroableTrait.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace FluentMail\Includes\Support;
4 +
5 + trait MacroableTrait {
6 +
7 + /**
8 + * The registered string macros.
9 + *
10 + * @var array
11 + */
12 + protected static $macros = array();
13 +
14 + /**
15 + * Register a custom macro.
16 + *
17 + * @param string $name
18 + * @param callable $macro
19 + * @return void
20 + */
21 + public static function macro($name, callable $macro)
22 + {
23 + static::$macros[$name] = $macro;
24 + }
25 +
26 + /**
27 + * Checks if macro is registered
28 + *
29 + * @param string $name
30 + * @return boolean
31 + */
32 + public static function hasMacro($name)
33 + {
34 + return isset(static::$macros[$name]);
35 + }
36 +
37 + /**
38 + * Dynamically handle calls to the class.
39 + *
40 + * @param string $method
41 + * @param array $parameters
42 + * @return mixed
43 + *
44 + * @throws \BadMethodCallException
45 + */
46 + public static function __callStatic($method, $parameters)
47 + {
48 + if (static::hasMacro($method))
49 + {
50 + return call_user_func_array(static::$macros[$method], $parameters);
51 + }
52 +
53 + throw new \BadMethodCallException("Method {$method} does not exist."); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
54 + }
55 +
56 + /**
57 + * Dynamically handle calls to the class.
58 + *
59 + * @param string $method
60 + * @param array $parameters
61 + * @return mixed
62 + *
63 + * @throws \BadMethodCallException
64 + */
65 + public function __call($method, $parameters)
66 + {
67 + return static::__callStatic($method, $parameters);
68 + }
69 +
70 + }
71 +