@@ -27,19 +27,19 @@ |
||
| 27 | 27 | * @param mixed $v (default: null) The array of values exposed in template. |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public static function render($t,$v=null){ |
|
| 31 | - if (empty($v)) return preg_replace('/{{[^}]+}}/','',$t); |
|
| 32 | - for( // Init |
|
| 33 | - $r = $ox = $x = false; |
|
| 34 | - // While |
|
| 35 | - false !== ($x = $y = strpos($t,'{{',$x)); |
|
| 36 | - // Do |
|
| 37 | - $r .= substr($t, $ox, $x-$ox), |
|
| 38 | - $c = substr($t, $x += 2, $l = ( $y = strpos($t,'}}', $x) ) - $x), |
|
| 39 | - $ox = $x += $l + 2, |
|
| 40 | - $r .= Object::fetch(trim($c),$v)?:'' |
|
| 41 | - ); |
|
| 42 | - return $r===false ? $t : $r.substr($t,$ox); |
|
| 43 | - } |
|
| 30 | + public static function render($t,$v=null){ |
|
| 31 | + if (empty($v)) return preg_replace('/{{[^}]+}}/','',$t); |
|
| 32 | + for( // Init |
|
| 33 | + $r = $ox = $x = false; |
|
| 34 | + // While |
|
| 35 | + false !== ($x = $y = strpos($t,'{{',$x)); |
|
| 36 | + // Do |
|
| 37 | + $r .= substr($t, $ox, $x-$ox), |
|
| 38 | + $c = substr($t, $x += 2, $l = ( $y = strpos($t,'}}', $x) ) - $x), |
|
| 39 | + $ox = $x += $l + 2, |
|
| 40 | + $r .= Object::fetch(trim($c),$v)?:'' |
|
| 41 | + ); |
|
| 42 | + return $r===false ? $t : $r.substr($t,$ox); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | } /* End of class */ |
@@ -27,19 +27,19 @@ |
||
| 27 | 27 | * @param mixed $v (default: null) The array of values exposed in template. |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public static function render($t,$v=null){ |
|
| 31 | - if (empty($v)) return preg_replace('/{{[^}]+}}/','',$t); |
|
| 32 | - for( // Init |
|
| 30 | + public static function render($t, $v = null) { |
|
| 31 | + if (empty($v)) return preg_replace('/{{[^}]+}}/', '', $t); |
|
| 32 | + for ( // Init |
|
| 33 | 33 | $r = $ox = $x = false; |
| 34 | 34 | // While |
| 35 | - false !== ($x = $y = strpos($t,'{{',$x)); |
|
| 35 | + false !== ($x = $y = strpos($t, '{{', $x)); |
|
| 36 | 36 | // Do |
| 37 | - $r .= substr($t, $ox, $x-$ox), |
|
| 38 | - $c = substr($t, $x += 2, $l = ( $y = strpos($t,'}}', $x) ) - $x), |
|
| 37 | + $r .= substr($t, $ox, $x - $ox), |
|
| 38 | + $c = substr($t, $x += 2, $l = ($y = strpos($t, '}}', $x)) - $x), |
|
| 39 | 39 | $ox = $x += $l + 2, |
| 40 | - $r .= Object::fetch(trim($c),$v)?:'' |
|
| 40 | + $r .= Object::fetch(trim($c), $v) ?: '' |
|
| 41 | 41 | ); |
| 42 | - return $r===false ? $t : $r.substr($t,$ox); |
|
| 42 | + return $r === false ? $t : $r.substr($t, $ox); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | } /* End of class */ |
@@ -27,8 +27,10 @@ |
||
| 27 | 27 | * @param mixed $v (default: null) The array of values exposed in template. |
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | - public static function render($t,$v=null){ |
|
| 31 | - if (empty($v)) return preg_replace('/{{[^}]+}}/','',$t); |
|
| 30 | + public static function render($t,$v=null) { |
|
| 31 | + if (empty($v)) { |
|
| 32 | + return preg_replace('/{{[^}]+}}/','',$t); |
|
| 33 | + } |
|
| 32 | 34 | for( // Init |
| 33 | 35 | $r = $ox = $x = false; |
| 34 | 36 | // While |
@@ -21,12 +21,12 @@ discard block |
||
| 21 | 21 | * @param mixed $input The object/array/json_encoded object to wrap |
| 22 | 22 | * @param boolean $deep Wrap also deep branches as Objects |
| 23 | 23 | */ |
| 24 | - public function __construct($input=[], $deep=true){ |
|
| 25 | - $data = is_string($input) ? json_decode($input,true) : (array)$input; |
|
| 26 | - if (is_array($data)){ |
|
| 24 | + public function __construct($input = [], $deep = true) { |
|
| 25 | + $data = is_string($input) ? json_decode($input, true) : (array) $input; |
|
| 26 | + if (is_array($data)) { |
|
| 27 | 27 | if ($deep) { |
| 28 | 28 | foreach ($data as $key => &$value) { |
| 29 | - if (is_array($value) || is_a($value,'stdClass')){ |
|
| 29 | + if (is_array($value) || is_a($value, 'stdClass')) { |
|
| 30 | 30 | $value = new self($value); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * ArrayObject::offsetSet |
| 44 | 44 | */ |
| 45 | - public function offsetSet($key, $value){ |
|
| 46 | - if ( is_array($value) ) |
|
| 45 | + public function offsetSet($key, $value) { |
|
| 46 | + if (is_array($value)) |
|
| 47 | 47 | parent::offsetSet($key, new static($value)); |
| 48 | 48 | else |
| 49 | 49 | parent::offsetSet($key, $value); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * ArrayObject::offsetGet |
| 54 | 54 | */ |
| 55 | - public function offsetGet($key){ |
|
| 55 | + public function offsetGet($key) { |
|
| 56 | 56 | $raw = parent::offsetGet($key); |
| 57 | 57 | return is_callable($raw) ? call_user_func($raw) : $raw; |
| 58 | 58 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | /** |
| 61 | 61 | * Emulate object methods |
| 62 | 62 | */ |
| 63 | - public function __call($method, $args){ |
|
| 63 | + public function __call($method, $args) { |
|
| 64 | 64 | $raw = parent::offsetGet($method); |
| 65 | 65 | if (is_callable($raw)) { |
| 66 | 66 | if ($raw instanceof \Closure) $raw->bindTo($this); |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * If casted as a string, return a JSON rappresentation of the wrapped payload |
| 73 | 73 | * @return string |
| 74 | 74 | */ |
| 75 | - public function __toString(){ |
|
| 76 | - return json_encode($this,JSON_NUMERIC_CHECK); |
|
| 75 | + public function __toString() { |
|
| 76 | + return json_encode($this, JSON_NUMERIC_CHECK); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -84,22 +84,22 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | |
| 86 | 86 | public static function fetch($path, $root) { |
| 87 | - $_ = (array)$root; |
|
| 88 | - if (strpos($path,'.') === false) { |
|
| 87 | + $_ = (array) $root; |
|
| 88 | + if (strpos($path, '.') === false) { |
|
| 89 | 89 | return isset($_[$path]) ? $_[$path] : null; |
| 90 | 90 | } else { |
| 91 | - list($frag,$rest) = explode('.', $path, 2); |
|
| 91 | + list($frag, $rest) = explode('.', $path, 2); |
|
| 92 | 92 | if ($rest) { |
| 93 | 93 | return isset($_[$frag]) ? self::fetch($rest, $_[$frag]) : null; |
| 94 | 94 | } elseif ($frag) { |
| 95 | - return (array)$_[$frag]; |
|
| 95 | + return (array) $_[$frag]; |
|
| 96 | 96 | } else { |
| 97 | 97 | return null; |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - public static function create($class, $args = null){ |
|
| 102 | + public static function create($class, $args = null) { |
|
| 103 | 103 | return is_array($args) ? (new ReflectionClass($class))->newInstanceArgs($args) : new $class; |
| 104 | 104 | } |
| 105 | 105 | |