@@ -26,6 +26,6 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | interface ICompilable |
| 28 | 28 | { |
| 29 | - // this replaces the process function |
|
| 30 | - //public static function compile(Compiler $compiler, $arg, $arg, ...); |
|
| 29 | + // this replaces the process function |
|
| 30 | + //public static function compile(Compiler $compiler, $arg, $arg, ...); |
|
| 31 | 31 | } |
@@ -23,30 +23,30 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | abstract class Processor |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * The compiler instance that runs this processor. |
|
| 28 | - * |
|
| 29 | - * @var Core |
|
| 30 | - */ |
|
| 31 | - protected $compiler; |
|
| 26 | + /** |
|
| 27 | + * The compiler instance that runs this processor. |
|
| 28 | + * |
|
| 29 | + * @var Core |
|
| 30 | + */ |
|
| 31 | + protected $compiler; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
| 35 | - * the dwoo instance yourself if you need it. |
|
| 36 | - * |
|
| 37 | - * @param Compiler $compiler the compiler class |
|
| 38 | - */ |
|
| 39 | - public function __construct(Compiler $compiler) |
|
| 40 | - { |
|
| 41 | - $this->compiler = $compiler; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor, if you override it, call parent::__construct($compiler); or assign |
|
| 35 | + * the dwoo instance yourself if you need it. |
|
| 36 | + * |
|
| 37 | + * @param Compiler $compiler the compiler class |
|
| 38 | + */ |
|
| 39 | + public function __construct(Compiler $compiler) |
|
| 40 | + { |
|
| 41 | + $this->compiler = $compiler; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Processes the input and returns it filtered. |
|
| 46 | - * |
|
| 47 | - * @param string $input the template to process |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - abstract public function process($input); |
|
| 44 | + /** |
|
| 45 | + * Processes the input and returns it filtered. |
|
| 46 | + * |
|
| 47 | + * @param string $input the template to process |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + abstract public function process($input); |
|
| 52 | 52 | } |
@@ -25,81 +25,81 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | abstract class Plugin |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * The dwoo instance that runs this plugin. |
|
| 30 | - * |
|
| 31 | - * @var Core |
|
| 32 | - */ |
|
| 33 | - protected $core; |
|
| 28 | + /** |
|
| 29 | + * The dwoo instance that runs this plugin. |
|
| 30 | + * |
|
| 31 | + * @var Core |
|
| 32 | + */ |
|
| 33 | + protected $core; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor, if you override it, call parent::__construct($core); or assign |
|
| 37 | - * the dwoo instance yourself if you need it. |
|
| 38 | - * |
|
| 39 | - * @param Core $core the dwoo instance that runs this plugin |
|
| 40 | - */ |
|
| 41 | - public function __construct(Core $core) |
|
| 42 | - { |
|
| 43 | - $this->core = $core; |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor, if you override it, call parent::__construct($core); or assign |
|
| 37 | + * the dwoo instance yourself if you need it. |
|
| 38 | + * |
|
| 39 | + * @param Core $core the dwoo instance that runs this plugin |
|
| 40 | + */ |
|
| 41 | + public function __construct(Core $core) |
|
| 42 | + { |
|
| 43 | + $this->core = $core; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // plugins should always implement : |
|
| 47 | - // public function process($arg, $arg, ...) |
|
| 48 | - // or for block plugins : |
|
| 49 | - // public function init($arg, $arg, ...) |
|
| 46 | + // plugins should always implement : |
|
| 47 | + // public function process($arg, $arg, ...) |
|
| 48 | + // or for block plugins : |
|
| 49 | + // public function init($arg, $arg, ...) |
|
| 50 | 50 | |
| 51 | - // this could be enforced with : |
|
| 52 | - // abstract public function process(...); |
|
| 53 | - // if my feature request gets enough interest one day |
|
| 54 | - // see => http://bugs.php.net/bug.php?id=44043 |
|
| 51 | + // this could be enforced with : |
|
| 52 | + // abstract public function process(...); |
|
| 53 | + // if my feature request gets enough interest one day |
|
| 54 | + // see => http://bugs.php.net/bug.php?id=44043 |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag |
|
| 58 | - * attributes. this is to be used in preProcessing or postProcessing functions, example : |
|
| 59 | - * $p = $compiler->getCompiledParams($params); |
|
| 60 | - * // get only the rest array as attributes |
|
| 61 | - * $attributes = Plugin::paramsToAttributes($p['*']); |
|
| 62 | - * // get all the parameters as attributes (if there is a rest array, it will be included) |
|
| 63 | - * $attributes = Plugin::paramsToAttributes($p); |
|
| 64 | - * |
|
| 65 | - * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string |
|
| 66 | - * inclusion in a php string |
|
| 67 | - * @param string $delim the string delimiter you want to use (defaults to ') |
|
| 68 | - * @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior) |
|
| 69 | - * escaping behavior) |
|
| 70 | - * |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null) |
|
| 74 | - { |
|
| 75 | - if (isset($params['*'])) { |
|
| 76 | - $params = array_merge($params, $params['*']); |
|
| 77 | - unset($params['*']); |
|
| 78 | - } |
|
| 56 | + /** |
|
| 57 | + * Utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag |
|
| 58 | + * attributes. this is to be used in preProcessing or postProcessing functions, example : |
|
| 59 | + * $p = $compiler->getCompiledParams($params); |
|
| 60 | + * // get only the rest array as attributes |
|
| 61 | + * $attributes = Plugin::paramsToAttributes($p['*']); |
|
| 62 | + * // get all the parameters as attributes (if there is a rest array, it will be included) |
|
| 63 | + * $attributes = Plugin::paramsToAttributes($p); |
|
| 64 | + * |
|
| 65 | + * @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string |
|
| 66 | + * inclusion in a php string |
|
| 67 | + * @param string $delim the string delimiter you want to use (defaults to ') |
|
| 68 | + * @param Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior) |
|
| 69 | + * escaping behavior) |
|
| 70 | + * |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public static function paramsToAttributes(array $params, $delim = '\'', Compiler $compiler = null) |
|
| 74 | + { |
|
| 75 | + if (isset($params['*'])) { |
|
| 76 | + $params = array_merge($params, $params['*']); |
|
| 77 | + unset($params['*']); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - $out = ''; |
|
| 81 | - foreach ($params as $attr => $val) { |
|
| 82 | - $out .= ' ' . $attr . '='; |
|
| 83 | - if (trim($val, '"\'') == '' || $val == 'null') { |
|
| 84 | - $out .= str_replace($delim, '\\' . $delim, '""'); |
|
| 85 | - } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
|
| 86 | - $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
| 87 | - } else { |
|
| 88 | - if (!$compiler) { |
|
| 89 | - // disable double encoding since it can not be determined if it was encoded |
|
| 90 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 91 | - } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
|
| 92 | - // escape if auto escaping is disabled, or there was no variable in the string |
|
| 93 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 94 | - } else { |
|
| 95 | - // print as is |
|
| 96 | - $escapedVal = '.' . $val . '.'; |
|
| 97 | - } |
|
| 80 | + $out = ''; |
|
| 81 | + foreach ($params as $attr => $val) { |
|
| 82 | + $out .= ' ' . $attr . '='; |
|
| 83 | + if (trim($val, '"\'') == '' || $val == 'null') { |
|
| 84 | + $out .= str_replace($delim, '\\' . $delim, '""'); |
|
| 85 | + } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
|
| 86 | + $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
| 87 | + } else { |
|
| 88 | + if (!$compiler) { |
|
| 89 | + // disable double encoding since it can not be determined if it was encoded |
|
| 90 | + $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 91 | + } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
|
| 92 | + // escape if auto escaping is disabled, or there was no variable in the string |
|
| 93 | + $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 94 | + } else { |
|
| 95 | + // print as is |
|
| 96 | + $escapedVal = '.' . $val . '.'; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
| 100 | - } |
|
| 101 | - } |
|
| 99 | + $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - return ltrim($out); |
|
| 104 | - } |
|
| 103 | + return ltrim($out); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -79,24 +79,24 @@ |
||
| 79 | 79 | |
| 80 | 80 | $out = ''; |
| 81 | 81 | foreach ($params as $attr => $val) { |
| 82 | - $out .= ' ' . $attr . '='; |
|
| 82 | + $out .= ' '.$attr.'='; |
|
| 83 | 83 | if (trim($val, '"\'') == '' || $val == 'null') { |
| 84 | - $out .= str_replace($delim, '\\' . $delim, '""'); |
|
| 84 | + $out .= str_replace($delim, '\\'.$delim, '""'); |
|
| 85 | 85 | } elseif (substr($val, 0, 1) === $delim && substr($val, - 1) === $delim) { |
| 86 | - $out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, - 1) . '"'); |
|
| 86 | + $out .= str_replace($delim, '\\'.$delim, '"'.substr($val, 1, - 1).'"'); |
|
| 87 | 87 | } else { |
| 88 | 88 | if (!$compiler) { |
| 89 | 89 | // disable double encoding since it can not be determined if it was encoded |
| 90 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 90 | + $escapedVal = '.(is_string($tmp2='.$val.') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).'; |
|
| 91 | 91 | } elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) { |
| 92 | 92 | // escape if auto escaping is disabled, or there was no variable in the string |
| 93 | - $escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 93 | + $escapedVal = '.(is_string($tmp2='.$val.') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).'; |
|
| 94 | 94 | } else { |
| 95 | 95 | // print as is |
| 96 | - $escapedVal = '.' . $val . '.'; |
|
| 96 | + $escapedVal = '.'.$val.'.'; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"'); |
|
| 99 | + $out .= str_replace($delim, '\\'.$delim, '"').$delim.$escapedVal.$delim.str_replace($delim, '\\'.$delim, '"'); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | interface IDataProvider |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * Returns the data as an associative array that will be used in the template. |
|
| 28 | - * |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function getData(); |
|
| 26 | + /** |
|
| 27 | + * Returns the data as an associative array that will be used in the template. |
|
| 28 | + * |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function getData(); |
|
| 32 | 32 | } |
@@ -28,92 +28,92 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | abstract class Plugin extends DwooPlugin |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * Stores the contents of the block while it runs. |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $buffer = ''; |
|
| 31 | + /** |
|
| 32 | + * Stores the contents of the block while it runs. |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $buffer = ''; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Buffers input, override only if necessary. |
|
| 40 | - * |
|
| 41 | - * @var string the content that must be buffered |
|
| 42 | - */ |
|
| 43 | - public function buffer($input) |
|
| 44 | - { |
|
| 45 | - $this->buffer .= $input; |
|
| 46 | - } |
|
| 38 | + /** |
|
| 39 | + * Buffers input, override only if necessary. |
|
| 40 | + * |
|
| 41 | + * @var string the content that must be buffered |
|
| 42 | + */ |
|
| 43 | + public function buffer($input) |
|
| 44 | + { |
|
| 45 | + $this->buffer .= $input; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // initialization code, receives the parameters from {block param1 param2} |
|
| 49 | - // public function init($arg, $arg, ...); |
|
| 48 | + // initialization code, receives the parameters from {block param1 param2} |
|
| 49 | + // public function init($arg, $arg, ...); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Called when the block ends, this is most of the time followed right away by a call |
|
| 53 | - * of <em>process()</em> but not always, so this should be used to do any shutdown operations on the |
|
| 54 | - * block object, if required. |
|
| 55 | - */ |
|
| 56 | - public function end() |
|
| 57 | - { |
|
| 58 | - } |
|
| 51 | + /** |
|
| 52 | + * Called when the block ends, this is most of the time followed right away by a call |
|
| 53 | + * of <em>process()</em> but not always, so this should be used to do any shutdown operations on the |
|
| 54 | + * block object, if required. |
|
| 55 | + */ |
|
| 56 | + public function end() |
|
| 57 | + { |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Called when the block output is required by a parent block. |
|
| 62 | - * this must read $this->buffer and return it processed |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function process() |
|
| 67 | - { |
|
| 68 | - return $this->buffer; |
|
| 69 | - } |
|
| 60 | + /** |
|
| 61 | + * Called when the block output is required by a parent block. |
|
| 62 | + * this must read $this->buffer and return it processed |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function process() |
|
| 67 | + { |
|
| 68 | + return $this->buffer; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
| 73 | - * block is declared basically this will replace the {block arg arg arg} tag in the template. |
|
| 74 | - * |
|
| 75 | - * @param DwooCompiler $compiler the compiler instance that calls this function |
|
| 76 | - * @param array $params an array containing original and compiled parameters |
|
| 77 | - * @param string $prepend that is just meant to allow a child class to call |
|
| 78 | - * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
| 79 | - * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
| 80 | - * to add a command before the default commands are executed |
|
| 81 | - * @param string $append that is just meant to allow a child class to call |
|
| 82 | - * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
| 83 | - * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
| 84 | - * "foo();") to add a command after the default commands are executed |
|
| 85 | - * @param string $type the type is the plugin class name used |
|
| 86 | - * |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public static function preProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $type) |
|
| 90 | - { |
|
| 91 | - return DwooCompiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . DwooCompiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . DwooCompiler::PHP_CLOSE; |
|
| 92 | - } |
|
| 71 | + /** |
|
| 72 | + * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
| 73 | + * block is declared basically this will replace the {block arg arg arg} tag in the template. |
|
| 74 | + * |
|
| 75 | + * @param DwooCompiler $compiler the compiler instance that calls this function |
|
| 76 | + * @param array $params an array containing original and compiled parameters |
|
| 77 | + * @param string $prepend that is just meant to allow a child class to call |
|
| 78 | + * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
| 79 | + * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
| 80 | + * to add a command before the default commands are executed |
|
| 81 | + * @param string $append that is just meant to allow a child class to call |
|
| 82 | + * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
| 83 | + * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
| 84 | + * "foo();") to add a command after the default commands are executed |
|
| 85 | + * @param string $type the type is the plugin class name used |
|
| 86 | + * |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public static function preProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $type) |
|
| 90 | + { |
|
| 91 | + return DwooCompiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . DwooCompiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . DwooCompiler::PHP_CLOSE; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
| 96 | - * block is ended basically this will replace the {/block} tag in the template. |
|
| 97 | - * |
|
| 98 | - * @see preProcessing |
|
| 99 | - * |
|
| 100 | - * @param DwooCompiler $compiler the compiler instance that calls this function |
|
| 101 | - * @param array $params an array containing original and compiled parameters, see preProcessing() for more |
|
| 102 | - * details more details |
|
| 103 | - * @param string $prepend that is just meant to allow a child class to call |
|
| 104 | - * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
| 105 | - * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
| 106 | - * to add a command before the default commands are executed |
|
| 107 | - * @param string $append that is just meant to allow a child class to call |
|
| 108 | - * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
| 109 | - * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
| 110 | - * "foo();") to add a command after the default commands are executed |
|
| 111 | - * @param string $content the entire content of the block being closed |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public static function postProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $content) |
|
| 116 | - { |
|
| 117 | - return $content . DwooCompiler::PHP_OPEN . $prepend . '$this->delStack();' . $append . DwooCompiler::PHP_CLOSE; |
|
| 118 | - } |
|
| 94 | + /** |
|
| 95 | + * Called at compile time to define what the block should output in the compiled template code, happens when the |
|
| 96 | + * block is ended basically this will replace the {/block} tag in the template. |
|
| 97 | + * |
|
| 98 | + * @see preProcessing |
|
| 99 | + * |
|
| 100 | + * @param DwooCompiler $compiler the compiler instance that calls this function |
|
| 101 | + * @param array $params an array containing original and compiled parameters, see preProcessing() for more |
|
| 102 | + * details more details |
|
| 103 | + * @param string $prepend that is just meant to allow a child class to call |
|
| 104 | + * parent::postProcessing($compiler, $params, "foo();") to add a command before the |
|
| 105 | + * default commands are executed parent::postProcessing($compiler, $params, "foo();") |
|
| 106 | + * to add a command before the default commands are executed |
|
| 107 | + * @param string $append that is just meant to allow a child class to call |
|
| 108 | + * parent::postProcessing($compiler, $params, null, "foo();") to add a command after |
|
| 109 | + * the default commands are executed parent::postProcessing($compiler, $params, null, |
|
| 110 | + * "foo();") to add a command after the default commands are executed |
|
| 111 | + * @param string $content the entire content of the block being closed |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public static function postProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $content) |
|
| 116 | + { |
|
| 117 | + return $content . DwooCompiler::PHP_OPEN . $prepend . '$this->delStack();' . $append . DwooCompiler::PHP_CLOSE; |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public static function preProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $type) |
| 90 | 90 | { |
| 91 | - return DwooCompiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . DwooCompiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . DwooCompiler::PHP_CLOSE; |
|
| 91 | + return DwooCompiler::PHP_OPEN.$prepend.'$this->addStack("'.$type.'", array('.DwooCompiler::implode_r($compiler->getCompiledParams($params)).'));'.$append.DwooCompiler::PHP_CLOSE; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -114,6 +114,6 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public static function postProcessing(DwooCompiler $compiler, array $params, $prepend, $append, $content) |
| 116 | 116 | { |
| 117 | - return $content . DwooCompiler::PHP_OPEN . $prepend . '$this->delStack();' . $append . DwooCompiler::PHP_CLOSE; |
|
| 117 | + return $content.DwooCompiler::PHP_OPEN.$prepend.'$this->delStack();'.$append.DwooCompiler::PHP_CLOSE; |
|
| 118 | 118 | } |
| 119 | 119 | } |
@@ -74,10 +74,10 @@ |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | if ($advance) { |
| 77 | - if ($this->cycles[$name]['index'] >= count($values) - 1) { |
|
| 77 | + if ($this->cycles[$name]['index'] >= count($values)-1) { |
|
| 78 | 78 | $this->cycles[$name]['index'] = 0; |
| 79 | 79 | } else { |
| 80 | - ++ $this->cycles[$name]['index']; |
|
| 80 | + ++$this->cycles[$name]['index']; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
@@ -34,58 +34,58 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class PluginCycle extends Plugin |
| 36 | 36 | { |
| 37 | - protected $cycles = array(); |
|
| 37 | + protected $cycles = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param string $name |
|
| 41 | - * @param null $values |
|
| 42 | - * @param bool $print |
|
| 43 | - * @param bool $advance |
|
| 44 | - * @param string $delimiter |
|
| 45 | - * @param null $assign |
|
| 46 | - * @param bool $reset |
|
| 47 | - * |
|
| 48 | - * @return string|null |
|
| 49 | - */ |
|
| 50 | - public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false) |
|
| 51 | - { |
|
| 52 | - if ($values !== null) { |
|
| 53 | - if (is_string($values)) { |
|
| 54 | - $values = explode($delimiter, $values); |
|
| 55 | - } |
|
| 39 | + /** |
|
| 40 | + * @param string $name |
|
| 41 | + * @param null $values |
|
| 42 | + * @param bool $print |
|
| 43 | + * @param bool $advance |
|
| 44 | + * @param string $delimiter |
|
| 45 | + * @param null $assign |
|
| 46 | + * @param bool $reset |
|
| 47 | + * |
|
| 48 | + * @return string|null |
|
| 49 | + */ |
|
| 50 | + public function process($name = 'default', $values = null, $print = true, $advance = true, $delimiter = ',', $assign = null, $reset = false) |
|
| 51 | + { |
|
| 52 | + if ($values !== null) { |
|
| 53 | + if (is_string($values)) { |
|
| 54 | + $values = explode($delimiter, $values); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) { |
|
| 58 | - $this->cycles[$name]['index'] = 0; |
|
| 59 | - } |
|
| 57 | + if (!isset($this->cycles[$name]) || $this->cycles[$name]['values'] !== $values) { |
|
| 58 | + $this->cycles[$name]['index'] = 0; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $this->cycles[$name]['values'] = array_values($values); |
|
| 62 | - } elseif (isset($this->cycles[$name])) { |
|
| 63 | - $values = $this->cycles[$name]['values']; |
|
| 64 | - } |
|
| 61 | + $this->cycles[$name]['values'] = array_values($values); |
|
| 62 | + } elseif (isset($this->cycles[$name])) { |
|
| 63 | + $values = $this->cycles[$name]['values']; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if ($reset) { |
|
| 67 | - $this->cycles[$name]['index'] = 0; |
|
| 68 | - } |
|
| 66 | + if ($reset) { |
|
| 67 | + $this->cycles[$name]['index'] = 0; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - if ($print) { |
|
| 71 | - $out = $values[$this->cycles[$name]['index']]; |
|
| 72 | - } else { |
|
| 73 | - $out = null; |
|
| 74 | - } |
|
| 70 | + if ($print) { |
|
| 71 | + $out = $values[$this->cycles[$name]['index']]; |
|
| 72 | + } else { |
|
| 73 | + $out = null; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - if ($advance) { |
|
| 77 | - if ($this->cycles[$name]['index'] >= count($values) - 1) { |
|
| 78 | - $this->cycles[$name]['index'] = 0; |
|
| 79 | - } else { |
|
| 80 | - ++ $this->cycles[$name]['index']; |
|
| 81 | - } |
|
| 82 | - } |
|
| 76 | + if ($advance) { |
|
| 77 | + if ($this->cycles[$name]['index'] >= count($values) - 1) { |
|
| 78 | + $this->cycles[$name]['index'] = 0; |
|
| 79 | + } else { |
|
| 80 | + ++ $this->cycles[$name]['index']; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if ($assign === null) { |
|
| 85 | - return $out; |
|
| 86 | - } |
|
| 87 | - $this->core->assignInScope($out, $assign); |
|
| 84 | + if ($assign === null) { |
|
| 85 | + return $out; |
|
| 86 | + } |
|
| 87 | + $this->core->assignInScope($out, $assign); |
|
| 88 | 88 | |
| 89 | - return null; |
|
| 90 | - } |
|
| 89 | + return null; |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -34,61 +34,61 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class PluginCounter extends Plugin |
| 36 | 36 | { |
| 37 | - protected $counters = array(); |
|
| 37 | + protected $counters = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param string $name |
|
| 41 | - * @param null $start |
|
| 42 | - * @param null $skip |
|
| 43 | - * @param null $direction |
|
| 44 | - * @param null $print |
|
| 45 | - * @param null $assign |
|
| 46 | - * |
|
| 47 | - * @return mixed |
|
| 48 | - */ |
|
| 49 | - public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null) |
|
| 50 | - { |
|
| 51 | - // init counter |
|
| 52 | - if (!isset($this->counters[$name])) { |
|
| 53 | - $this->counters[$name] = array( |
|
| 54 | - 'count' => $start === null ? 1 : (int)$start, |
|
| 55 | - 'skip' => $skip === null ? 1 : (int)$skip, |
|
| 56 | - 'print' => $print === null ? true : (bool)$print, |
|
| 57 | - 'assign' => $assign === null ? null : (string)$assign, |
|
| 58 | - 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
| 59 | - ); |
|
| 60 | - } // increment |
|
| 61 | - else { |
|
| 62 | - // override setting if present |
|
| 63 | - if ($skip !== null) { |
|
| 64 | - $this->counters[$name]['skip'] = (int)$skip; |
|
| 65 | - } |
|
| 39 | + /** |
|
| 40 | + * @param string $name |
|
| 41 | + * @param null $start |
|
| 42 | + * @param null $skip |
|
| 43 | + * @param null $direction |
|
| 44 | + * @param null $print |
|
| 45 | + * @param null $assign |
|
| 46 | + * |
|
| 47 | + * @return mixed |
|
| 48 | + */ |
|
| 49 | + public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null) |
|
| 50 | + { |
|
| 51 | + // init counter |
|
| 52 | + if (!isset($this->counters[$name])) { |
|
| 53 | + $this->counters[$name] = array( |
|
| 54 | + 'count' => $start === null ? 1 : (int)$start, |
|
| 55 | + 'skip' => $skip === null ? 1 : (int)$skip, |
|
| 56 | + 'print' => $print === null ? true : (bool)$print, |
|
| 57 | + 'assign' => $assign === null ? null : (string)$assign, |
|
| 58 | + 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
| 59 | + ); |
|
| 60 | + } // increment |
|
| 61 | + else { |
|
| 62 | + // override setting if present |
|
| 63 | + if ($skip !== null) { |
|
| 64 | + $this->counters[$name]['skip'] = (int)$skip; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if ($direction !== null) { |
|
| 68 | - $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
| 69 | - } |
|
| 67 | + if ($direction !== null) { |
|
| 68 | + $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - if ($print !== null) { |
|
| 72 | - $this->counters[$name]['print'] = (bool)$print; |
|
| 73 | - } |
|
| 71 | + if ($print !== null) { |
|
| 72 | + $this->counters[$name]['print'] = (bool)$print; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - if ($assign !== null) { |
|
| 76 | - $this->counters[$name]['assign'] = (string)$assign; |
|
| 77 | - } |
|
| 75 | + if ($assign !== null) { |
|
| 76 | + $this->counters[$name]['assign'] = (string)$assign; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - if ($start !== null) { |
|
| 80 | - $this->counters[$name]['count'] = (int)$start; |
|
| 81 | - } else { |
|
| 82 | - $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
| 83 | - } |
|
| 84 | - } |
|
| 79 | + if ($start !== null) { |
|
| 80 | + $this->counters[$name]['count'] = (int)$start; |
|
| 81 | + } else { |
|
| 82 | + $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - $out = $this->counters[$name]['count']; |
|
| 86 | + $out = $this->counters[$name]['count']; |
|
| 87 | 87 | |
| 88 | - if ($this->counters[$name]['assign'] !== null) { |
|
| 89 | - $this->core->assignInScope($out, $this->counters[$name]['assign']); |
|
| 90 | - } elseif ($this->counters[$name]['print'] === true) { |
|
| 91 | - return $out; |
|
| 92 | - } |
|
| 93 | - } |
|
| 88 | + if ($this->counters[$name]['assign'] !== null) { |
|
| 89 | + $this->core->assignInScope($out, $this->counters[$name]['assign']); |
|
| 90 | + } elseif ($this->counters[$name]['print'] === true) { |
|
| 91 | + return $out; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -51,35 +51,35 @@ |
||
| 51 | 51 | // init counter |
| 52 | 52 | if (!isset($this->counters[$name])) { |
| 53 | 53 | $this->counters[$name] = array( |
| 54 | - 'count' => $start === null ? 1 : (int)$start, |
|
| 55 | - 'skip' => $skip === null ? 1 : (int)$skip, |
|
| 56 | - 'print' => $print === null ? true : (bool)$print, |
|
| 57 | - 'assign' => $assign === null ? null : (string)$assign, |
|
| 58 | - 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
|
| 54 | + 'count' => $start === null ? 1 : (int) $start, |
|
| 55 | + 'skip' => $skip === null ? 1 : (int) $skip, |
|
| 56 | + 'print' => $print === null ? true : (bool) $print, |
|
| 57 | + 'assign' => $assign === null ? null : (string) $assign, |
|
| 58 | + 'direction' => strtolower($direction) === 'down' ? -1 : 1, |
|
| 59 | 59 | ); |
| 60 | 60 | } // increment |
| 61 | 61 | else { |
| 62 | 62 | // override setting if present |
| 63 | 63 | if ($skip !== null) { |
| 64 | - $this->counters[$name]['skip'] = (int)$skip; |
|
| 64 | + $this->counters[$name]['skip'] = (int) $skip; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | if ($direction !== null) { |
| 68 | - $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
|
| 68 | + $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? -1 : 1; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | if ($print !== null) { |
| 72 | - $this->counters[$name]['print'] = (bool)$print; |
|
| 72 | + $this->counters[$name]['print'] = (bool) $print; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | if ($assign !== null) { |
| 76 | - $this->counters[$name]['assign'] = (string)$assign; |
|
| 76 | + $this->counters[$name]['assign'] = (string) $assign; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | if ($start !== null) { |
| 80 | - $this->counters[$name]['count'] = (int)$start; |
|
| 80 | + $this->counters[$name]['count'] = (int) $start; |
|
| 81 | 81 | } else { |
| 82 | - $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
|
| 82 | + $this->counters[$name]['count'] += ($this->counters[$name]['skip']*$this->counters[$name]['direction']); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
@@ -27,47 +27,47 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class PluginForeachelse extends BlockPlugin implements ICompilableBlock |
| 29 | 29 | { |
| 30 | - public function init() |
|
| 31 | - { |
|
| 32 | - } |
|
| 30 | + public function init() |
|
| 31 | + { |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param Compiler $compiler |
|
| 36 | - * @param array $params |
|
| 37 | - * @param string $prepend |
|
| 38 | - * @param string $append |
|
| 39 | - * @param string $type |
|
| 40 | - * |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 44 | - { |
|
| 45 | - $with = &$compiler->findBlock('foreach', true); |
|
| 34 | + /** |
|
| 35 | + * @param Compiler $compiler |
|
| 36 | + * @param array $params |
|
| 37 | + * @param string $prepend |
|
| 38 | + * @param string $append |
|
| 39 | + * @param string $type |
|
| 40 | + * |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 44 | + { |
|
| 45 | + $with = &$compiler->findBlock('foreach', true); |
|
| 46 | 46 | |
| 47 | - $params['initialized'] = true; |
|
| 48 | - $compiler->injectBlock($type, $params); |
|
| 47 | + $params['initialized'] = true; |
|
| 48 | + $compiler->injectBlock($type, $params); |
|
| 49 | 49 | |
| 50 | - return ''; |
|
| 51 | - } |
|
| 50 | + return ''; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param Compiler $compiler |
|
| 55 | - * @param array $params |
|
| 56 | - * @param string $prepend |
|
| 57 | - * @param string $append |
|
| 58 | - * @param string $content |
|
| 59 | - * |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 63 | - { |
|
| 64 | - if (!isset($params['initialized'])) { |
|
| 65 | - return ''; |
|
| 66 | - } |
|
| 53 | + /** |
|
| 54 | + * @param Compiler $compiler |
|
| 55 | + * @param array $params |
|
| 56 | + * @param string $prepend |
|
| 57 | + * @param string $append |
|
| 58 | + * @param string $content |
|
| 59 | + * |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 63 | + { |
|
| 64 | + if (!isset($params['initialized'])) { |
|
| 65 | + return ''; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $block = &$compiler->getCurrentBlock(); |
|
| 69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 68 | + $block = &$compiler->getCurrentBlock(); |
|
| 69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 70 | 70 | |
| 71 | - return ''; |
|
| 72 | - } |
|
| 71 | + return ''; |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $block = &$compiler->getCurrentBlock(); |
| 69 | - $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 69 | + $block['params']['hasElse'] = Compiler::PHP_OPEN."else {\n".Compiler::PHP_CLOSE.$content.Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
| 70 | 70 | |
| 71 | 71 | return ''; |
| 72 | 72 | } |
@@ -41,234 +41,234 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class PluginIf extends BlockPlugin implements ICompilableBlock, IElseable |
| 43 | 43 | { |
| 44 | - /** |
|
| 45 | - * @param array $rest |
|
| 46 | - */ |
|
| 47 | - public function init(array $rest) |
|
| 48 | - { |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @param array $rest |
|
| 46 | + */ |
|
| 47 | + public function init(array $rest) |
|
| 48 | + { |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param array $params |
|
| 53 | - * @param array $tokens |
|
| 54 | - * @param Compiler $compiler |
|
| 55 | - * |
|
| 56 | - * @return array |
|
| 57 | - * @throws CompilationException |
|
| 58 | - */ |
|
| 59 | - public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
| 60 | - { |
|
| 61 | - $p = array(); |
|
| 51 | + /** |
|
| 52 | + * @param array $params |
|
| 53 | + * @param array $tokens |
|
| 54 | + * @param Compiler $compiler |
|
| 55 | + * |
|
| 56 | + * @return array |
|
| 57 | + * @throws CompilationException |
|
| 58 | + */ |
|
| 59 | + public static function replaceKeywords(array $params, array $tokens, Compiler $compiler) |
|
| 60 | + { |
|
| 61 | + $p = array(); |
|
| 62 | 62 | |
| 63 | - reset($params); |
|
| 64 | - while (list($k, $v) = each($params)) { |
|
| 65 | - $v = (string)$v; |
|
| 66 | - if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
| 67 | - $vmod = strtolower(substr($v, 1, - 1)); |
|
| 68 | - } else { |
|
| 69 | - $vmod = strtolower($v); |
|
| 70 | - } |
|
| 71 | - switch ($vmod) { |
|
| 63 | + reset($params); |
|
| 64 | + while (list($k, $v) = each($params)) { |
|
| 65 | + $v = (string)$v; |
|
| 66 | + if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
|
| 67 | + $vmod = strtolower(substr($v, 1, - 1)); |
|
| 68 | + } else { |
|
| 69 | + $vmod = strtolower($v); |
|
| 70 | + } |
|
| 71 | + switch ($vmod) { |
|
| 72 | 72 | |
| 73 | - case 'and': |
|
| 74 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 75 | - $p[] = '&&'; |
|
| 76 | - } else { |
|
| 77 | - $p[] = $v; |
|
| 78 | - } |
|
| 79 | - break; |
|
| 80 | - case 'or': |
|
| 81 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 82 | - $p[] = '||'; |
|
| 83 | - } else { |
|
| 84 | - $p[] = $v; |
|
| 85 | - } |
|
| 86 | - break; |
|
| 87 | - case 'xor': |
|
| 88 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 89 | - $p[] = '^'; |
|
| 90 | - } else { |
|
| 91 | - $p[] = $v; |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - case 'eq': |
|
| 95 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 96 | - $p[] = '=='; |
|
| 97 | - } else { |
|
| 98 | - $p[] = $v; |
|
| 99 | - } |
|
| 100 | - break; |
|
| 101 | - case 'ne': |
|
| 102 | - case 'neq': |
|
| 103 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 104 | - $p[] = '!='; |
|
| 105 | - } else { |
|
| 106 | - $p[] = $v; |
|
| 107 | - } |
|
| 108 | - break; |
|
| 109 | - case 'gte': |
|
| 110 | - case 'ge': |
|
| 111 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 112 | - $p[] = '>='; |
|
| 113 | - } else { |
|
| 114 | - $p[] = $v; |
|
| 115 | - } |
|
| 116 | - break; |
|
| 117 | - case 'lte': |
|
| 118 | - case 'le': |
|
| 119 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 120 | - $p[] = '<='; |
|
| 121 | - } else { |
|
| 122 | - $p[] = $v; |
|
| 123 | - } |
|
| 124 | - break; |
|
| 125 | - case 'gt': |
|
| 126 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 127 | - $p[] = '>'; |
|
| 128 | - } else { |
|
| 129 | - $p[] = $v; |
|
| 130 | - } |
|
| 131 | - break; |
|
| 132 | - case 'lt': |
|
| 133 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 134 | - $p[] = '<'; |
|
| 135 | - } else { |
|
| 136 | - $p[] = $v; |
|
| 137 | - } |
|
| 138 | - break; |
|
| 139 | - case 'mod': |
|
| 140 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 141 | - $p[] = '%'; |
|
| 142 | - } else { |
|
| 143 | - $p[] = $v; |
|
| 144 | - } |
|
| 145 | - break; |
|
| 146 | - case 'not': |
|
| 147 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 148 | - $p[] = '!'; |
|
| 149 | - } else { |
|
| 150 | - $p[] = $v; |
|
| 151 | - } |
|
| 152 | - break; |
|
| 153 | - case '<>': |
|
| 154 | - $p[] = '!='; |
|
| 155 | - break; |
|
| 156 | - case '==': |
|
| 157 | - case '!=': |
|
| 158 | - case '>=': |
|
| 159 | - case '<=': |
|
| 160 | - case '>': |
|
| 161 | - case '<': |
|
| 162 | - case '===': |
|
| 163 | - case '!==': |
|
| 164 | - case '%': |
|
| 165 | - case '!': |
|
| 166 | - case '^': |
|
| 167 | - $p[] = $vmod; |
|
| 168 | - break; |
|
| 169 | - case 'is': |
|
| 170 | - if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
| 171 | - $p[] = $v; |
|
| 172 | - break; |
|
| 173 | - } |
|
| 174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
| 175 | - $negate = true; |
|
| 176 | - next($params); |
|
| 177 | - } else { |
|
| 178 | - $negate = false; |
|
| 179 | - } |
|
| 180 | - $ptr = 1 + (int)$negate; |
|
| 181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 182 | - break; |
|
| 183 | - } |
|
| 184 | - if (!isset($params[$k + $ptr])) { |
|
| 185 | - $params[$k + $ptr] = ''; |
|
| 186 | - } else { |
|
| 187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
| 188 | - } |
|
| 189 | - switch ($params[$k + $ptr]) { |
|
| 73 | + case 'and': |
|
| 74 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 75 | + $p[] = '&&'; |
|
| 76 | + } else { |
|
| 77 | + $p[] = $v; |
|
| 78 | + } |
|
| 79 | + break; |
|
| 80 | + case 'or': |
|
| 81 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 82 | + $p[] = '||'; |
|
| 83 | + } else { |
|
| 84 | + $p[] = $v; |
|
| 85 | + } |
|
| 86 | + break; |
|
| 87 | + case 'xor': |
|
| 88 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 89 | + $p[] = '^'; |
|
| 90 | + } else { |
|
| 91 | + $p[] = $v; |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + case 'eq': |
|
| 95 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 96 | + $p[] = '=='; |
|
| 97 | + } else { |
|
| 98 | + $p[] = $v; |
|
| 99 | + } |
|
| 100 | + break; |
|
| 101 | + case 'ne': |
|
| 102 | + case 'neq': |
|
| 103 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 104 | + $p[] = '!='; |
|
| 105 | + } else { |
|
| 106 | + $p[] = $v; |
|
| 107 | + } |
|
| 108 | + break; |
|
| 109 | + case 'gte': |
|
| 110 | + case 'ge': |
|
| 111 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 112 | + $p[] = '>='; |
|
| 113 | + } else { |
|
| 114 | + $p[] = $v; |
|
| 115 | + } |
|
| 116 | + break; |
|
| 117 | + case 'lte': |
|
| 118 | + case 'le': |
|
| 119 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 120 | + $p[] = '<='; |
|
| 121 | + } else { |
|
| 122 | + $p[] = $v; |
|
| 123 | + } |
|
| 124 | + break; |
|
| 125 | + case 'gt': |
|
| 126 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 127 | + $p[] = '>'; |
|
| 128 | + } else { |
|
| 129 | + $p[] = $v; |
|
| 130 | + } |
|
| 131 | + break; |
|
| 132 | + case 'lt': |
|
| 133 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 134 | + $p[] = '<'; |
|
| 135 | + } else { |
|
| 136 | + $p[] = $v; |
|
| 137 | + } |
|
| 138 | + break; |
|
| 139 | + case 'mod': |
|
| 140 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 141 | + $p[] = '%'; |
|
| 142 | + } else { |
|
| 143 | + $p[] = $v; |
|
| 144 | + } |
|
| 145 | + break; |
|
| 146 | + case 'not': |
|
| 147 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 148 | + $p[] = '!'; |
|
| 149 | + } else { |
|
| 150 | + $p[] = $v; |
|
| 151 | + } |
|
| 152 | + break; |
|
| 153 | + case '<>': |
|
| 154 | + $p[] = '!='; |
|
| 155 | + break; |
|
| 156 | + case '==': |
|
| 157 | + case '!=': |
|
| 158 | + case '>=': |
|
| 159 | + case '<=': |
|
| 160 | + case '>': |
|
| 161 | + case '<': |
|
| 162 | + case '===': |
|
| 163 | + case '!==': |
|
| 164 | + case '%': |
|
| 165 | + case '!': |
|
| 166 | + case '^': |
|
| 167 | + $p[] = $vmod; |
|
| 168 | + break; |
|
| 169 | + case 'is': |
|
| 170 | + if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
| 171 | + $p[] = $v; |
|
| 172 | + break; |
|
| 173 | + } |
|
| 174 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
| 175 | + $negate = true; |
|
| 176 | + next($params); |
|
| 177 | + } else { |
|
| 178 | + $negate = false; |
|
| 179 | + } |
|
| 180 | + $ptr = 1 + (int)$negate; |
|
| 181 | + if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 182 | + break; |
|
| 183 | + } |
|
| 184 | + if (!isset($params[$k + $ptr])) { |
|
| 185 | + $params[$k + $ptr] = ''; |
|
| 186 | + } else { |
|
| 187 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
| 188 | + } |
|
| 189 | + switch ($params[$k + $ptr]) { |
|
| 190 | 190 | |
| 191 | - case 'div': |
|
| 192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
| 194 | - next($params); |
|
| 195 | - next($params); |
|
| 196 | - next($params); |
|
| 197 | - } else { |
|
| 198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
| 199 | - } |
|
| 200 | - break; |
|
| 201 | - case 'even': |
|
| 202 | - $a = array_pop($p); |
|
| 203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 204 | - $b = $params[$k + $ptr + 2]; |
|
| 205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 206 | - next($params); |
|
| 207 | - next($params); |
|
| 208 | - } else { |
|
| 209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 210 | - } |
|
| 211 | - next($params); |
|
| 212 | - break; |
|
| 213 | - case 'odd': |
|
| 214 | - $a = array_pop($p); |
|
| 215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 216 | - $b = $params[$k + $ptr + 2]; |
|
| 217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 218 | - next($params); |
|
| 219 | - next($params); |
|
| 220 | - } else { |
|
| 221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 222 | - } |
|
| 223 | - next($params); |
|
| 224 | - break; |
|
| 225 | - default: |
|
| 226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
| 227 | - } |
|
| 228 | - break; |
|
| 229 | - default: |
|
| 230 | - $p[] = $v; |
|
| 231 | - } |
|
| 232 | - } |
|
| 191 | + case 'div': |
|
| 192 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 193 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
| 194 | + next($params); |
|
| 195 | + next($params); |
|
| 196 | + next($params); |
|
| 197 | + } else { |
|
| 198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
| 199 | + } |
|
| 200 | + break; |
|
| 201 | + case 'even': |
|
| 202 | + $a = array_pop($p); |
|
| 203 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 204 | + $b = $params[$k + $ptr + 2]; |
|
| 205 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 206 | + next($params); |
|
| 207 | + next($params); |
|
| 208 | + } else { |
|
| 209 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 210 | + } |
|
| 211 | + next($params); |
|
| 212 | + break; |
|
| 213 | + case 'odd': |
|
| 214 | + $a = array_pop($p); |
|
| 215 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 216 | + $b = $params[$k + $ptr + 2]; |
|
| 217 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 218 | + next($params); |
|
| 219 | + next($params); |
|
| 220 | + } else { |
|
| 221 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 222 | + } |
|
| 223 | + next($params); |
|
| 224 | + break; |
|
| 225 | + default: |
|
| 226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
| 227 | + } |
|
| 228 | + break; |
|
| 229 | + default: |
|
| 230 | + $p[] = $v; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - return $p; |
|
| 235 | - } |
|
| 234 | + return $p; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * @param Compiler $compiler |
|
| 239 | - * @param array $params |
|
| 240 | - * @param string $prepend |
|
| 241 | - * @param string $append |
|
| 242 | - * @param string $type |
|
| 243 | - * |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 247 | - { |
|
| 248 | - return ''; |
|
| 249 | - } |
|
| 237 | + /** |
|
| 238 | + * @param Compiler $compiler |
|
| 239 | + * @param array $params |
|
| 240 | + * @param string $prepend |
|
| 241 | + * @param string $append |
|
| 242 | + * @param string $type |
|
| 243 | + * |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) |
|
| 247 | + { |
|
| 248 | + return ''; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * @param Compiler $compiler |
|
| 253 | - * @param array $params |
|
| 254 | - * @param string $prepend |
|
| 255 | - * @param string $append |
|
| 256 | - * @param string $content |
|
| 257 | - * |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 261 | - { |
|
| 262 | - $tokens = $compiler->getParamTokens($params); |
|
| 263 | - $params = $compiler->getCompiledParams($params); |
|
| 264 | - $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
| 251 | + /** |
|
| 252 | + * @param Compiler $compiler |
|
| 253 | + * @param array $params |
|
| 254 | + * @param string $prepend |
|
| 255 | + * @param string $append |
|
| 256 | + * @param string $content |
|
| 257 | + * |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) |
|
| 261 | + { |
|
| 262 | + $tokens = $compiler->getParamTokens($params); |
|
| 263 | + $params = $compiler->getCompiledParams($params); |
|
| 264 | + $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
| 265 | 265 | |
| 266 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 266 | + $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 267 | 267 | |
| 268 | - if (isset($params['hasElse'])) { |
|
| 269 | - $post .= $params['hasElse']; |
|
| 270 | - } |
|
| 268 | + if (isset($params['hasElse'])) { |
|
| 269 | + $post .= $params['hasElse']; |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - return $pre . $content . $post; |
|
| 273 | - } |
|
| 272 | + return $pre . $content . $post; |
|
| 273 | + } |
|
| 274 | 274 | } |
@@ -70,164 +70,164 @@ |
||
| 70 | 70 | } |
| 71 | 71 | switch ($vmod) { |
| 72 | 72 | |
| 73 | - case 'and': |
|
| 74 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 75 | - $p[] = '&&'; |
|
| 76 | - } else { |
|
| 77 | - $p[] = $v; |
|
| 78 | - } |
|
| 79 | - break; |
|
| 80 | - case 'or': |
|
| 81 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 82 | - $p[] = '||'; |
|
| 83 | - } else { |
|
| 84 | - $p[] = $v; |
|
| 85 | - } |
|
| 86 | - break; |
|
| 87 | - case 'xor': |
|
| 88 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 89 | - $p[] = '^'; |
|
| 90 | - } else { |
|
| 91 | - $p[] = $v; |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - case 'eq': |
|
| 95 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 96 | - $p[] = '=='; |
|
| 97 | - } else { |
|
| 98 | - $p[] = $v; |
|
| 99 | - } |
|
| 100 | - break; |
|
| 101 | - case 'ne': |
|
| 102 | - case 'neq': |
|
| 103 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 104 | - $p[] = '!='; |
|
| 105 | - } else { |
|
| 106 | - $p[] = $v; |
|
| 107 | - } |
|
| 108 | - break; |
|
| 109 | - case 'gte': |
|
| 110 | - case 'ge': |
|
| 111 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 112 | - $p[] = '>='; |
|
| 113 | - } else { |
|
| 114 | - $p[] = $v; |
|
| 115 | - } |
|
| 116 | - break; |
|
| 117 | - case 'lte': |
|
| 118 | - case 'le': |
|
| 119 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 120 | - $p[] = '<='; |
|
| 121 | - } else { |
|
| 122 | - $p[] = $v; |
|
| 123 | - } |
|
| 124 | - break; |
|
| 125 | - case 'gt': |
|
| 126 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 127 | - $p[] = '>'; |
|
| 128 | - } else { |
|
| 129 | - $p[] = $v; |
|
| 130 | - } |
|
| 131 | - break; |
|
| 132 | - case 'lt': |
|
| 133 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 134 | - $p[] = '<'; |
|
| 135 | - } else { |
|
| 136 | - $p[] = $v; |
|
| 137 | - } |
|
| 138 | - break; |
|
| 139 | - case 'mod': |
|
| 140 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 141 | - $p[] = '%'; |
|
| 142 | - } else { |
|
| 143 | - $p[] = $v; |
|
| 144 | - } |
|
| 145 | - break; |
|
| 146 | - case 'not': |
|
| 147 | - if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 148 | - $p[] = '!'; |
|
| 149 | - } else { |
|
| 150 | - $p[] = $v; |
|
| 151 | - } |
|
| 152 | - break; |
|
| 153 | - case '<>': |
|
| 73 | + case 'and': |
|
| 74 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 75 | + $p[] = '&&'; |
|
| 76 | + } else { |
|
| 77 | + $p[] = $v; |
|
| 78 | + } |
|
| 79 | + break; |
|
| 80 | + case 'or': |
|
| 81 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 82 | + $p[] = '||'; |
|
| 83 | + } else { |
|
| 84 | + $p[] = $v; |
|
| 85 | + } |
|
| 86 | + break; |
|
| 87 | + case 'xor': |
|
| 88 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 89 | + $p[] = '^'; |
|
| 90 | + } else { |
|
| 91 | + $p[] = $v; |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + case 'eq': |
|
| 95 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 96 | + $p[] = '=='; |
|
| 97 | + } else { |
|
| 98 | + $p[] = $v; |
|
| 99 | + } |
|
| 100 | + break; |
|
| 101 | + case 'ne': |
|
| 102 | + case 'neq': |
|
| 103 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 154 | 104 | $p[] = '!='; |
| 105 | + } else { |
|
| 106 | + $p[] = $v; |
|
| 107 | + } |
|
| 108 | + break; |
|
| 109 | + case 'gte': |
|
| 110 | + case 'ge': |
|
| 111 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 112 | + $p[] = '>='; |
|
| 113 | + } else { |
|
| 114 | + $p[] = $v; |
|
| 115 | + } |
|
| 116 | + break; |
|
| 117 | + case 'lte': |
|
| 118 | + case 'le': |
|
| 119 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 120 | + $p[] = '<='; |
|
| 121 | + } else { |
|
| 122 | + $p[] = $v; |
|
| 123 | + } |
|
| 124 | + break; |
|
| 125 | + case 'gt': |
|
| 126 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 127 | + $p[] = '>'; |
|
| 128 | + } else { |
|
| 129 | + $p[] = $v; |
|
| 130 | + } |
|
| 131 | + break; |
|
| 132 | + case 'lt': |
|
| 133 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 134 | + $p[] = '<'; |
|
| 135 | + } else { |
|
| 136 | + $p[] = $v; |
|
| 137 | + } |
|
| 138 | + break; |
|
| 139 | + case 'mod': |
|
| 140 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 141 | + $p[] = '%'; |
|
| 142 | + } else { |
|
| 143 | + $p[] = $v; |
|
| 144 | + } |
|
| 145 | + break; |
|
| 146 | + case 'not': |
|
| 147 | + if ($tokens[$k] === Compiler::T_UNQUOTED_STRING) { |
|
| 148 | + $p[] = '!'; |
|
| 149 | + } else { |
|
| 150 | + $p[] = $v; |
|
| 151 | + } |
|
| 152 | + break; |
|
| 153 | + case '<>': |
|
| 154 | + $p[] = '!='; |
|
| 155 | + break; |
|
| 156 | + case '==': |
|
| 157 | + case '!=': |
|
| 158 | + case '>=': |
|
| 159 | + case '<=': |
|
| 160 | + case '>': |
|
| 161 | + case '<': |
|
| 162 | + case '===': |
|
| 163 | + case '!==': |
|
| 164 | + case '%': |
|
| 165 | + case '!': |
|
| 166 | + case '^': |
|
| 167 | + $p[] = $vmod; |
|
| 168 | + break; |
|
| 169 | + case 'is': |
|
| 170 | + if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
| 171 | + $p[] = $v; |
|
| 155 | 172 | break; |
| 156 | - case '==': |
|
| 157 | - case '!=': |
|
| 158 | - case '>=': |
|
| 159 | - case '<=': |
|
| 160 | - case '>': |
|
| 161 | - case '<': |
|
| 162 | - case '===': |
|
| 163 | - case '!==': |
|
| 164 | - case '%': |
|
| 165 | - case '!': |
|
| 166 | - case '^': |
|
| 167 | - $p[] = $vmod; |
|
| 173 | + } |
|
| 174 | + if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
| 175 | + $negate = true; |
|
| 176 | + next($params); |
|
| 177 | + } else { |
|
| 178 | + $negate = false; |
|
| 179 | + } |
|
| 180 | + $ptr = 1 + (int)$negate; |
|
| 181 | + if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 168 | 182 | break; |
| 169 | - case 'is': |
|
| 170 | - if ($tokens[$k] !== Compiler::T_UNQUOTED_STRING) { |
|
| 171 | - $p[] = $v; |
|
| 172 | - break; |
|
| 173 | - } |
|
| 174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
| 175 | - $negate = true; |
|
| 176 | - next($params); |
|
| 177 | - } else { |
|
| 178 | - $negate = false; |
|
| 179 | - } |
|
| 180 | - $ptr = 1 + (int)$negate; |
|
| 181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 182 | - break; |
|
| 183 | - } |
|
| 184 | - if (!isset($params[$k + $ptr])) { |
|
| 185 | - $params[$k + $ptr] = ''; |
|
| 186 | - } else { |
|
| 187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
| 188 | - } |
|
| 189 | - switch ($params[$k + $ptr]) { |
|
| 183 | + } |
|
| 184 | + if (!isset($params[$k + $ptr])) { |
|
| 185 | + $params[$k + $ptr] = ''; |
|
| 186 | + } else { |
|
| 187 | + $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
| 188 | + } |
|
| 189 | + switch ($params[$k + $ptr]) { |
|
| 190 | 190 | |
| 191 | - case 'div': |
|
| 192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
| 194 | - next($params); |
|
| 195 | - next($params); |
|
| 196 | - next($params); |
|
| 197 | - } else { |
|
| 198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
| 199 | - } |
|
| 200 | - break; |
|
| 201 | - case 'even': |
|
| 202 | - $a = array_pop($p); |
|
| 203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 204 | - $b = $params[$k + $ptr + 2]; |
|
| 205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 206 | - next($params); |
|
| 207 | - next($params); |
|
| 208 | - } else { |
|
| 209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 210 | - } |
|
| 211 | - next($params); |
|
| 212 | - break; |
|
| 213 | - case 'odd': |
|
| 214 | - $a = array_pop($p); |
|
| 215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 216 | - $b = $params[$k + $ptr + 2]; |
|
| 217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 218 | - next($params); |
|
| 219 | - next($params); |
|
| 220 | - } else { |
|
| 221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 222 | - } |
|
| 223 | - next($params); |
|
| 224 | - break; |
|
| 225 | - default: |
|
| 226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
| 227 | - } |
|
| 228 | - break; |
|
| 191 | + case 'div': |
|
| 192 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 193 | + $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
| 194 | + next($params); |
|
| 195 | + next($params); |
|
| 196 | + next($params); |
|
| 197 | + } else { |
|
| 198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
| 199 | + } |
|
| 200 | + break; |
|
| 201 | + case 'even': |
|
| 202 | + $a = array_pop($p); |
|
| 203 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 204 | + $b = $params[$k + $ptr + 2]; |
|
| 205 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 206 | + next($params); |
|
| 207 | + next($params); |
|
| 208 | + } else { |
|
| 209 | + $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 210 | + } |
|
| 211 | + next($params); |
|
| 212 | + break; |
|
| 213 | + case 'odd': |
|
| 214 | + $a = array_pop($p); |
|
| 215 | + if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 216 | + $b = $params[$k + $ptr + 2]; |
|
| 217 | + $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 218 | + next($params); |
|
| 219 | + next($params); |
|
| 220 | + } else { |
|
| 221 | + $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 222 | + } |
|
| 223 | + next($params); |
|
| 224 | + break; |
|
| 229 | 225 | default: |
| 230 | - $p[] = $v; |
|
| 226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
| 227 | + } |
|
| 228 | + break; |
|
| 229 | + default: |
|
| 230 | + $p[] = $v; |
|
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | reset($params); |
| 64 | 64 | while (list($k, $v) = each($params)) { |
| 65 | - $v = (string)$v; |
|
| 65 | + $v = (string) $v; |
|
| 66 | 66 | if (substr($v, 0, 1) === '"' || substr($v, 0, 1) === '\'') { |
| 67 | 67 | $vmod = strtolower(substr($v, 1, - 1)); |
| 68 | 68 | } else { |
@@ -171,59 +171,59 @@ discard block |
||
| 171 | 171 | $p[] = $v; |
| 172 | 172 | break; |
| 173 | 173 | } |
| 174 | - if (isset($params[$k + 1]) && strtolower(trim($params[$k + 1], '"\'')) === 'not' && $tokens[$k + 1] === Compiler::T_UNQUOTED_STRING) { |
|
| 174 | + if (isset($params[$k+1]) && strtolower(trim($params[$k+1], '"\'')) === 'not' && $tokens[$k+1] === Compiler::T_UNQUOTED_STRING) { |
|
| 175 | 175 | $negate = true; |
| 176 | 176 | next($params); |
| 177 | 177 | } else { |
| 178 | 178 | $negate = false; |
| 179 | 179 | } |
| 180 | - $ptr = 1 + (int)$negate; |
|
| 181 | - if ($tokens[$k + $ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 180 | + $ptr = 1+(int) $negate; |
|
| 181 | + if ($tokens[$k+$ptr] !== Compiler::T_UNQUOTED_STRING) { |
|
| 182 | 182 | break; |
| 183 | 183 | } |
| 184 | - if (!isset($params[$k + $ptr])) { |
|
| 185 | - $params[$k + $ptr] = ''; |
|
| 184 | + if (!isset($params[$k+$ptr])) { |
|
| 185 | + $params[$k+$ptr] = ''; |
|
| 186 | 186 | } else { |
| 187 | - $params[$k + $ptr] = trim($params[$k + $ptr], '"\''); |
|
| 187 | + $params[$k+$ptr] = trim($params[$k+$ptr], '"\''); |
|
| 188 | 188 | } |
| 189 | - switch ($params[$k + $ptr]) { |
|
| 189 | + switch ($params[$k+$ptr]) { |
|
| 190 | 190 | |
| 191 | 191 | case 'div': |
| 192 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 193 | - $p[] = ' % ' . $params[$k + $ptr + 2] . ' ' . ($negate ? '!' : '=') . '== 0'; |
|
| 192 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
| 193 | + $p[] = ' % '.$params[$k+$ptr+2].' '.($negate ? '!' : '=').'== 0'; |
|
| 194 | 194 | next($params); |
| 195 | 195 | next($params); |
| 196 | 196 | next($params); |
| 197 | 197 | } else { |
| 198 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found ' . $params[$k - 1] . ' is ' . ($negate ? 'not ' : '') . 'div ' . $params[$k + $ptr + 1] . ' ' . $params[$k + $ptr + 2]); |
|
| 198 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] div by $b", found '.$params[$k-1].' is '.($negate ? 'not ' : '').'div '.$params[$k+$ptr+1].' '.$params[$k+$ptr+2]); |
|
| 199 | 199 | } |
| 200 | 200 | break; |
| 201 | 201 | case 'even': |
| 202 | 202 | $a = array_pop($p); |
| 203 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 204 | - $b = $params[$k + $ptr + 2]; |
|
| 205 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 203 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
| 204 | + $b = $params[$k+$ptr+2]; |
|
| 205 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '!' : '=').'== 0'; |
|
| 206 | 206 | next($params); |
| 207 | 207 | next($params); |
| 208 | 208 | } else { |
| 209 | - $p[] = $a . ' % 2 ' . ($negate ? '!' : '=') . '== 0'; |
|
| 209 | + $p[] = $a.' % 2 '.($negate ? '!' : '=').'== 0'; |
|
| 210 | 210 | } |
| 211 | 211 | next($params); |
| 212 | 212 | break; |
| 213 | 213 | case 'odd': |
| 214 | 214 | $a = array_pop($p); |
| 215 | - if (isset($params[$k + $ptr + 1]) && strtolower(trim($params[$k + $ptr + 1], '"\'')) === 'by') { |
|
| 216 | - $b = $params[$k + $ptr + 2]; |
|
| 217 | - $p[] = '(' . $a . ' / ' . $b . ') % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 215 | + if (isset($params[$k+$ptr+1]) && strtolower(trim($params[$k+$ptr+1], '"\'')) === 'by') { |
|
| 216 | + $b = $params[$k+$ptr+2]; |
|
| 217 | + $p[] = '('.$a.' / '.$b.') % 2 '.($negate ? '=' : '!').'== 0'; |
|
| 218 | 218 | next($params); |
| 219 | 219 | next($params); |
| 220 | 220 | } else { |
| 221 | - $p[] = $a . ' % 2 ' . ($negate ? '=' : '!') . '== 0'; |
|
| 221 | + $p[] = $a.' % 2 '.($negate ? '=' : '!').'== 0'; |
|
| 222 | 222 | } |
| 223 | 223 | next($params); |
| 224 | 224 | break; |
| 225 | 225 | default: |
| 226 | - throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found ' . $params[$k - 1] . ' is ' . $params[$k + $ptr + 1]); |
|
| 226 | + throw new CompilationException($compiler, 'If : Syntax error : syntax should be "if $a is [not] (div|even|odd) [by $b]", found '.$params[$k-1].' is '.$params[$k+$ptr+1]); |
|
| 227 | 227 | } |
| 228 | 228 | break; |
| 229 | 229 | default: |
@@ -261,14 +261,14 @@ discard block |
||
| 261 | 261 | { |
| 262 | 262 | $tokens = $compiler->getParamTokens($params); |
| 263 | 263 | $params = $compiler->getCompiledParams($params); |
| 264 | - $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; |
|
| 264 | + $pre = Compiler::PHP_OPEN.'if ('.implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)).") {\n".Compiler::PHP_CLOSE; |
|
| 265 | 265 | |
| 266 | - $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; |
|
| 266 | + $post = Compiler::PHP_OPEN."\n}".Compiler::PHP_CLOSE; |
|
| 267 | 267 | |
| 268 | 268 | if (isset($params['hasElse'])) { |
| 269 | 269 | $post .= $params['hasElse']; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - return $pre . $content . $post; |
|
| 272 | + return $pre.$content.$post; |
|
| 273 | 273 | } |
| 274 | 274 | } |