Commit b98089d5 authored by Taddeus Kroes's avatar Taddeus Kroes

Updated code style to C-like standards

parent 34788e78
...@@ -170,7 +170,7 @@ class Autoloader extends Base { ...@@ -170,7 +170,7 @@ class Autoloader extends Base {
private function strip_root_namespace($classname) { private function strip_root_namespace($classname) {
$begin = substr($classname, 0, strlen($this->root_namespace)); $begin = substr($classname, 0, strlen($this->root_namespace));
if( $begin == $this->root_namespace ) if ($begin == $this->root_namespace)
$classname = substr($classname, strlen($this->root_namespace)); $classname = substr($classname, strlen($this->root_namespace));
return $classname; return $classname;
...@@ -189,7 +189,7 @@ class Autoloader extends Base { ...@@ -189,7 +189,7 @@ class Autoloader extends Base {
$dirs = array_map('self::classname_to_filename', $namespaces); $dirs = array_map('self::classname_to_filename', $namespaces);
$path = $this->root_directory; $path = $this->root_directory;
if( count($dirs) > 1 ) if (count($dirs) > 1)
$path .= implode('/', array_slice($dirs, 0, count($dirs) - 1)).'/'; $path .= implode('/', array_slice($dirs, 0, count($dirs) - 1)).'/';
$path .= end($dirs).'.php'; $path .= end($dirs).'.php';
...@@ -211,8 +211,8 @@ class Autoloader extends Base { ...@@ -211,8 +211,8 @@ class Autoloader extends Base {
$classname = $this->strip_root_namespace($classname); $classname = $this->strip_root_namespace($classname);
$path = $this->create_path($classname); $path = $this->create_path($classname);
if( !file_exists($path) ) { if (!file_exists($path)) {
if( $throw || ($throw === null && $this->throw_errors) ) if ($throw || ($throw === null && $this->throw_errors))
throw new FileNotFoundError($path); throw new FileNotFoundError($path);
return false; return false;
......
...@@ -99,7 +99,7 @@ class FileNotFoundError extends \RuntimeException { ...@@ -99,7 +99,7 @@ class FileNotFoundError extends \RuntimeException {
function asprintf($format, array $params) { function asprintf($format, array $params) {
return preg_replace_callback( return preg_replace_callback(
'/%\(([a-z-_ ]*)\)/i', '/%\(([a-z-_ ]*)\)/i',
function ($matches) use ($params) { function($matches) use ($params) {
return (string)$params[$matches[1]]; return (string)$params[$matches[1]];
}, },
$format $format
......
...@@ -77,11 +77,11 @@ class Collection extends Base { ...@@ -77,11 +77,11 @@ class Collection extends Base {
* @throws \InvalidArgumentException If the added index already exists, and is non-numeric. * @throws \InvalidArgumentException If the added index already exists, and is non-numeric.
*/ */
function insert($item, $index) { function insert($item, $index) {
if( isset($this->items[$index]) ) { if (isset($this->items[$index])) {
if( !is_int($index) ) if (!is_int($index))
throw new \InvalidArgumentException(sprintf('Index "%s" already exists in this collection.', $index)); throw new \InvalidArgumentException(sprintf('Index "%s" already exists in this collection.', $index));
for( $i = count($this->items) - 1; $i >= $index; $i--) for ($i = count($this->items) - 1; $i >= $index; $i--)
$this->items[$i + 1] = $this->items[$i]; $this->items[$i + 1] = $this->items[$i];
} }
...@@ -104,7 +104,7 @@ class Collection extends Base { ...@@ -104,7 +104,7 @@ class Collection extends Base {
* @throws \OutOfBoundsException if the collection is empty. * @throws \OutOfBoundsException if the collection is empty.
*/ */
function first() { function first() {
if( !$this->count() ) if (!$this->count())
throw new \OutOfBoundsException(sprintf('Cannot get first item: collection is empty.')); throw new \OutOfBoundsException(sprintf('Cannot get first item: collection is empty.'));
return $this->items[0]; return $this->items[0];
...@@ -117,7 +117,7 @@ class Collection extends Base { ...@@ -117,7 +117,7 @@ class Collection extends Base {
* @throws \OutOfBoundsException if the collection is empty. * @throws \OutOfBoundsException if the collection is empty.
*/ */
function last() { function last() {
if( !$this->count() ) if (!$this->count())
throw new \OutOfBoundsException(sprintf('Cannot get last item: collection is empty.')); throw new \OutOfBoundsException(sprintf('Cannot get last item: collection is empty.'));
return end($this->items); return end($this->items);
...@@ -179,7 +179,7 @@ class Collection extends Base { ...@@ -179,7 +179,7 @@ class Collection extends Base {
* @return Collection A collection with the new item set. * @return Collection A collection with the new item set.
*/ */
private function set_items(array $items, $clone=true) { private function set_items(array $items, $clone=true) {
if( $clone ) if ($clone)
return new self($items); return new self($items);
$this->items = $items; $this->items = $items;
...@@ -225,14 +225,14 @@ class Collection extends Base { ...@@ -225,14 +225,14 @@ class Collection extends Base {
*/ */
function find(array $conditions, $clone=true) { function find(array $conditions, $clone=true) {
return $this->filter(function($item) use ($conditions) { return $this->filter(function($item) use ($conditions) {
if( is_object($item) ) { if (is_object($item)) {
// Object, match property values // Object, match property values
foreach( $conditions as $property => $value ) foreach( $conditions as $property => $value )
if( $item->{$property} != $value ) if( $item->{$property} != $value )
return false; return false;
} elseif( is_array($item) ) { } elseif (is_array($item)) {
// Array item, match array values // Array item, match array values
foreach( $conditions as $property => $value ) foreach ($conditions as $property => $value)
if( $item[$property] != $value ) if( $item[$property] != $value )
return false; return false;
} else { } else {
...@@ -302,7 +302,7 @@ class Collection extends Base { ...@@ -302,7 +302,7 @@ class Collection extends Base {
function map_method($method_name, array $args=array(), $clone=true) { function map_method($method_name, array $args=array(), $clone=true) {
$items = array(); $items = array();
foreach( $this->items as $item ) foreach ($this->items as $item)
$items[] = call_user_func_array(array($item, $method_name), $args); $items[] = call_user_func_array(array($item, $method_name), $args);
return $this->set_items($items); return $this->set_items($items);
......
...@@ -40,7 +40,7 @@ class Logger extends Base { ...@@ -40,7 +40,7 @@ class Logger extends Base {
} }
function set_dump_format($format) { function set_dump_format($format) {
if( !in_array($format, self::$allowed_dump_formats) ) if (!in_array($format, self::$allowed_dump_formats))
throw new \InvalidArgumentException(sprintf('', $format)); throw new \InvalidArgumentException(sprintf('', $format));
$this->dump_format = $format; $this->dump_format = $format;
...@@ -63,16 +63,16 @@ class Logger extends Base { ...@@ -63,16 +63,16 @@ class Logger extends Base {
} }
function set_level($level) { function set_level($level) {
if( is_string($level) ) { if (is_string($level)) {
$level = strtoupper($level); $level = strtoupper($level);
if( !defined('self::'.$level) ) if (!defined('self::'.$level))
throw new \InvalidArgumentException(sprintf('Invalid debug level %s.', $level)); throw new \InvalidArgumentException(sprintf('Invalid debug level %s.', $level));
$level = constant('self::'.$level); $level = constant('self::'.$level);
} }
if( $level < self::CRITICAL || $level > self::DEBUG ) if ($level < self::CRITICAL || $level > self::DEBUG)
throw new \InvalidArgumentException(sprintf('Invalid debug level %d.', $level)); throw new \InvalidArgumentException(sprintf('Invalid debug level %d.', $level));
$this->level = $level; $this->level = $level;
...@@ -111,7 +111,7 @@ class Logger extends Base { ...@@ -111,7 +111,7 @@ class Logger extends Base {
} }
private function process($message, $level) { private function process($message, $level) {
if( $level <= $this->level ) if ($level <= $this->level)
$this->output[] = array($message, $level); $this->output[] = array($message, $level);
} }
...@@ -119,18 +119,18 @@ class Logger extends Base { ...@@ -119,18 +119,18 @@ class Logger extends Base {
$logger = $this; $logger = $this;
$output = ''; $output = '';
foreach( $this->output as $i => $tuple ) { foreach ($this->output as $i => $tuple) {
list($message, $level) = $tuple; list($message, $level) = $tuple;
$i && $output .= "\n"; $i && $output .= "\n";
$output .= preg_replace_callback( $output .= preg_replace_callback(
'/%\(([a-z-_ ]*)\)/i', '/%\(([a-z-_ ]*)\)/i',
function ($matches) use ($logger, $message, $level) { function($matches) use ($logger, $message, $level) {
$name = $matches[1]; $name = $matches[1];
if( $name == 'message' ) if ($name == 'message')
return $message; return $message;
if( $name == 'level' ) if ($name == 'level')
return Logger::$level_names[$level]; return Logger::$level_names[$level];
return $logger->get_formatted_property($matches[1]); return $logger->get_formatted_property($matches[1]);
...@@ -143,7 +143,7 @@ class Logger extends Base { ...@@ -143,7 +143,7 @@ class Logger extends Base {
} }
function dump($file_prefix='log') { function dump($file_prefix='log') {
switch( $this->dump_format ) { switch ($this->dump_format) {
case 'none': case 'none':
return; return;
case 'plain': case 'plain':
...@@ -163,7 +163,7 @@ class Logger extends Base { ...@@ -163,7 +163,7 @@ class Logger extends Base {
} }
function save($path) { function save($path) {
if( $this->log_directory && !is_dir($this->log_directory) ) if ($this->log_directory && !is_dir($this->log_directory))
mkdir($this->log_directory, 0777, true); mkdir($this->log_directory, 0777, true);
file_put_contents($this->log_directory . $path, $this->dumps()); file_put_contents($this->log_directory . $path, $this->dumps());
...@@ -184,7 +184,7 @@ class Logger extends Base { ...@@ -184,7 +184,7 @@ class Logger extends Base {
} }
function get_formatted_property($property) { function get_formatted_property($property) {
if( isset($this->properties[$property]) ) if (isset($this->properties[$property]))
return $this->properties[$property]; return $this->properties[$property];
switch( $property ) { switch( $property ) {
......
...@@ -183,7 +183,7 @@ class Node extends Base { ...@@ -183,7 +183,7 @@ class Node extends Base {
* @param Node &$child The node to remove. * @param Node &$child The node to remove.
*/ */
function remove_child(Node &$child) { function remove_child(Node &$child) {
foreach( $this->children as $i => $node ) foreach ($this->children as $i => $node)
$node->is($child) && array_splice($this->children, $i, 1); $node->is($child) && array_splice($this->children, $i, 1);
} }
...@@ -194,12 +194,12 @@ class Node extends Base { ...@@ -194,12 +194,12 @@ class Node extends Base {
* @return Node This node. * @return Node This node.
*/ */
function remove() { function remove() {
if( $this->is_root() ) if ($this->is_root())
throw new \RuntimeException('Cannot remove the root node of a tree.'); throw new \RuntimeException('Cannot remove the root node of a tree.');
$this->parent_node->remove_child($this); $this->parent_node->remove_child($this);
foreach( $this->children as $child ) foreach ($this->children as $child)
$child->set_parent(null); $child->set_parent(null);
return $this; return $this;
...@@ -215,7 +215,7 @@ class Node extends Base { ...@@ -215,7 +215,7 @@ class Node extends Base {
* @return Node This node. * @return Node This node.
*/ */
function set_parent($parent) { function set_parent($parent) {
if( $this->parent_node !== null ) if ($this->parent_node !== null)
$this->parent_node->remove_child($this); $this->parent_node->remove_child($this);
$this->parent_node = &$parent; $this->parent_node = &$parent;
...@@ -231,8 +231,8 @@ class Node extends Base { ...@@ -231,8 +231,8 @@ class Node extends Base {
* @return Node This node. * @return Node This node.
*/ */
function set($name, $value=null) { function set($name, $value=null) {
if( is_array($name) ) { if (is_array($name)) {
foreach( $name as $var => $val ) foreach ($name as $var => $val)
$this->variables[$var] = $val; $this->variables[$var] = $val;
} else { } else {
$this->variables[$name] = $value; $this->variables[$name] = $value;
...@@ -249,7 +249,7 @@ class Node extends Base { ...@@ -249,7 +249,7 @@ class Node extends Base {
*/ */
function get($name) { function get($name) {
// Variable inside this node? // Variable inside this node?
if( isset($this->variables[$name]) ) if (isset($this->variables[$name]))
return $this->variables[$name]; return $this->variables[$name];
// Variable in one of ancestors? // Variable in one of ancestors?
...@@ -311,8 +311,8 @@ class Node extends Base { ...@@ -311,8 +311,8 @@ class Node extends Base {
$copy = new self($this->name, $this->parent_node, $this->id); $copy = new self($this->name, $this->parent_node, $this->id);
$copy->set($this->variables); $copy->set($this->variables);
foreach( $this->children as $child ) { foreach ($this->children as $child) {
if( $deep ) { if ($deep) {
$child_copy = $child->copy(true); $child_copy = $child->copy(true);
$copy->add_child($child_copy); $copy->add_child($child_copy);
} else { } else {
......
...@@ -69,7 +69,7 @@ class Router extends Base { ...@@ -69,7 +69,7 @@ class Router extends Base {
* @param array $routes An initial list of routes to set. * @param array $routes An initial list of routes to set.
*/ */
function __construct(array $routes=array()) { function __construct(array $routes=array()) {
foreach( $routes as $pattern => $handler ) foreach ($routes as $pattern => $handler)
$this->add_route($pattern, $handler); $this->add_route($pattern, $handler);
} }
...@@ -88,10 +88,10 @@ class Router extends Base { ...@@ -88,10 +88,10 @@ class Router extends Base {
* @throws \InvalidArgumentException If $handler is not callable. * @throws \InvalidArgumentException If $handler is not callable.
*/ */
function add_route($pattern, $handler) { function add_route($pattern, $handler) {
if( !is_callable($handler) ) if (!is_callable($handler))
throw new \InvalidArgumentException(sprintf('Handler for patterns "%s" is not callable.', $pattern)); throw new \InvalidArgumentException(sprintf('Handler for patterns "%s" is not callable.', $pattern));
$this->routes[self::DELIMITER.'^'.$pattern.'$'.self::DELIMITER] = $handler; $this->routes[self::DELIMITER . '^' . $pattern . '$' . self::DELIMITER] = $handler;
} }
/** /**
...@@ -108,12 +108,12 @@ class Router extends Base { ...@@ -108,12 +108,12 @@ class Router extends Base {
* corresponding handler function otherwise. * corresponding handler function otherwise.
*/ */
function call_handler($url) { function call_handler($url) {
foreach( $this->routes as $pattern => $handler ) { foreach ($this->routes as $pattern => $handler) {
if( preg_match($pattern, $url, $matches) ) { if (preg_match($pattern, $url, $matches)) {
array_shift($matches); array_shift($matches);
$result = call_user_func_array($handler, $matches); $result = call_user_func_array($handler, $matches);
if( $result !== false ) if ($result !== false)
return $result; return $result;
} }
} }
......
...@@ -146,10 +146,10 @@ class Template extends Node { ...@@ -146,10 +146,10 @@ class Template extends Node {
$look_in = count(self::$include_path) ? self::$include_path : array('.'); $look_in = count(self::$include_path) ? self::$include_path : array('.');
$found = false; $found = false;
foreach( $look_in as $root ) { foreach ($look_in as $root) {
$path = $root.$filename; $path = $root.$filename;
if( file_exists($path) ) { if (file_exists($path)) {
$this->path = $path; $this->path = $path;
$this->file_content = file_get_contents($path); $this->file_content = file_get_contents($path);
$found = true; $found = true;
...@@ -157,7 +157,7 @@ class Template extends Node { ...@@ -157,7 +157,7 @@ class Template extends Node {
} }
} }
if( !$found ) { if (!$found) {
throw new \RuntimeException( throw new \RuntimeException(
sprintf("Could not find template file \"%s\", looked in folders:\n%s", sprintf("Could not find template file \"%s\", looked in folders:\n%s",
$filename, implode("\n", $look_in)) $filename, implode("\n", $look_in))
...@@ -187,25 +187,25 @@ class Template extends Node { ...@@ -187,25 +187,25 @@ class Template extends Node {
$after = $this->file_content; $after = $this->file_content;
$line_count = 0; $line_count = 0;
while( preg_match('/(.*?)\{([^}]+)}(.*)/s', $after, $matches) ) { while (preg_match('/(.*?)\{([^}]+)}(.*)/s', $after, $matches)) {
list($before, $brackets_content, $after) = array_slice($matches, 1); list($before, $brackets_content, $after) = array_slice($matches, 1);
$line_count += substr_count($before, "\n"); $line_count += substr_count($before, "\n");
// Everything before the new block belongs to its parent // Everything before the new block belongs to its parent
$html = $current->add('html')->set('content', $before); $html = $current->add('html')->set('content', $before);
if( $brackets_content == 'end' ) { if ($brackets_content == 'end') {
// {end} encountered, go one level up in the tree // {end} encountered, go one level up in the tree
if( $current->is_root() ) if ($current->is_root())
throw new ParseError($this, 'unexpected {end}', $line_count + 1); throw new ParseError($this, 'unexpected {end}', $line_count + 1);
$current = $current->get_parent(); $current = $current->get_parent();
} elseif( substr($brackets_content, 0, 6) == 'block:' ) { } elseif(substr($brackets_content, 0, 6) == 'block:') {
// {block:...} encountered // {block:...} encountered
$block_name = substr($brackets_content, 6); $block_name = substr($brackets_content, 6);
// Go one level deeper into the tree // Go one level deeper into the tree
$current = $current->add('block')->set('name', $block_name); $current = $current->add('block')->set('name', $block_name);
} elseif( strpos($brackets_content, "\n") !== false ) { } elseif (strpos($brackets_content, "\n") !== false) {
// Bracket content contains newlines, so it is probably JavaScript or CSS // Bracket content contains newlines, so it is probably JavaScript or CSS
$html->set('content', $before . '{' . $brackets_content . '}'); $html->set('content', $before . '{' . $brackets_content . '}');
} else { } else {
...@@ -216,7 +216,7 @@ class Template extends Node { ...@@ -216,7 +216,7 @@ class Template extends Node {
$line_count += substr_count($after, "\n"); $line_count += substr_count($after, "\n");
if( $current !== $root ) if ($current !== $root)
throw new ParseError($this, 'missing {end}', $line_count + 1); throw new ParseError($this, 'missing {end}', $line_count + 1);
// Add the last remaining content to the root node // Add the last remaining content to the root node
...@@ -246,15 +246,15 @@ class Template extends Node { ...@@ -246,15 +246,15 @@ class Template extends Node {
private static function render_block(Node $block, Node $data) { private static function render_block(Node $block, Node $data) {
$html = ''; $html = '';
foreach( $block->get_children() as $child ) { foreach ($block->get_children() as $child) {
switch( $child->get_name() ) { switch ($child->get_name()) {
case 'html': case 'html':
$html .= $child->get('content'); $html .= $child->get('content');
break; break;
case 'block': case 'block':
$block_name = $child->get('name'); $block_name = $child->get('name');
foreach( $data->find($block_name) as $child_data ) foreach ($data->find($block_name) as $child_data)
$html .= self::render_block($child, $child_data); $html .= self::render_block($child, $child_data);
break; break;
...@@ -284,11 +284,11 @@ class Template extends Node { ...@@ -284,11 +284,11 @@ class Template extends Node {
$variable = $matches[3]; $variable = $matches[3];
$value = $data->get($variable); $value = $data->get($variable);
if( count($matches) == 5 ) { if (count($matches) == 5) {
// $<name>.<name> // $<name>.<name>
$attribute = $matches[4]; $attribute = $matches[4];
if( $value === null ) { if ($value === null) {
throw new \UnexpectedValueException( throw new \UnexpectedValueException(
sprintf('Cannot get attribute "%s.%s": value is NULL', $variable, $attribute) sprintf('Cannot get attribute "%s.%s": value is NULL', $variable, $attribute)
); );
...@@ -300,20 +300,20 @@ class Template extends Node { ...@@ -300,20 +300,20 @@ class Template extends Node {
); );
}; };
if( is_array($value) ) { if (is_array($value)) {
isset($value[$attribute]) || $attr_error('no such key', '\OutOfBoundsException'); isset($value[$attribute]) || $attr_error('no such key', '\OutOfBoundsException');
$value = $value[$attribute]; $value = $value[$attribute];
} elseif( is_object($value) ) { } elseif (is_object($value)) {
isset($value->$attribute) || $attr_error('no such attribute'); isset($value->$attribute) || $attr_error('no such attribute');
$value = $value->$attribute; $value = $value->$attribute;
} else { } else {
$attr_error('variable is no array or object'); $attr_error('variable is no array or object');
} }
} elseif( count($matches) == 6 ) { } elseif (count($matches) == 6) {
// $<name>.<name>() // $<name>.<name>()
$method = $matches[4]; $method = $matches[4];
if( $value === null ) { if ($value === null) {
throw new \UnexpectedValueException( throw new \UnexpectedValueException(
sprintf('Cannot call method "%s.%s()": object is NULL', $variable, $method) sprintf('Cannot call method "%s.%s()": object is NULL', $variable, $method)
); );
...@@ -325,7 +325,7 @@ class Template extends Node { ...@@ -325,7 +325,7 @@ class Template extends Node {
); );
}; };
if( is_object($value) ) { if (is_object($value)) {
method_exists($value, $method) || $method_error('no such method'); method_exists($value, $method) || $method_error('no such method');
$value = $value->$method(); $value = $value->$method();
} else { } else {
...@@ -334,7 +334,7 @@ class Template extends Node { ...@@ -334,7 +334,7 @@ class Template extends Node {
} }
// Escape value // Escape value
if( is_string($value) && !$noescape_sign ) if (is_string($value) && !$noescape_sign)
$value = self::escape_variable_value($value); $value = self::escape_variable_value($value);
return $before . $value; return $before . $value;
...@@ -363,10 +363,10 @@ class Template extends Node { ...@@ -363,10 +363,10 @@ class Template extends Node {
* @return string The evaluation of the condition. * @return string The evaluation of the condition.
*/ */
private static function evaluate_condition(array $matches, Node $data) { private static function evaluate_condition(array $matches, Node $data) {
if( self::evaluate_expression($matches[1], $data, false) ) { if (self::evaluate_expression($matches[1], $data, false)) {
// Condition evaluates to true: return 'if' evaluation // Condition evaluates to true: return 'if' evaluation
return self::evaluate_expression($matches[2], $data, false); return self::evaluate_expression($matches[2], $data, false);
} elseif( count($matches) == 4 ) { } elseif (count($matches) == 4) {
// <nested_exp>?<nested_exp>:<nested_exp> // <nested_exp>?<nested_exp>:<nested_exp>
return self::evaluate_expression($matches[3], $data, false); return self::evaluate_expression($matches[3], $data, false);
} }
...@@ -390,7 +390,7 @@ class Template extends Node { ...@@ -390,7 +390,7 @@ class Template extends Node {
$function = $matches[1]; $function = $matches[1];
$parameter = $matches[2]; $parameter = $matches[2];
if( !is_callable($function) ) { if (!is_callable($function)) {
throw new \BadFunctionCallException( throw new \BadFunctionCallException(
sprintf('Cannot call function "%s": function is not callable', $function) sprintf('Cannot call function "%s": function is not callable', $function)
); );
...@@ -413,7 +413,7 @@ class Template extends Node { ...@@ -413,7 +413,7 @@ class Template extends Node {
* original constant name otherwise. * original constant name otherwise.
*/ */
private static function evaluate_constant($constant, $root_level) { private static function evaluate_constant($constant, $root_level) {
if( defined($constant) ) if (defined($constant))
return constant($constant); return constant($constant);
return $root_level ? '{' . $constant . '}' : $constant; return $root_level ? '{' . $constant . '}' : $constant;
...@@ -434,24 +434,24 @@ class Template extends Node { ...@@ -434,24 +434,24 @@ class Template extends Node {
* original string enclosed in curly brackets otherwise. * original string enclosed in curly brackets otherwise.
*/ */
private static function evaluate_expression($expression, Node $data, $root_level=true) { private static function evaluate_expression($expression, Node $data, $root_level=true) {
if( $expression ) { if ($expression) {
$name = '[a-zA-Z0-9-_]+'; $name = '[a-zA-Z0-9-_]+';
$function = "$name(?:::$name)?"; $function = "$name(?:::$name)?";
if( preg_match("/^([^?]*?)\s*\?([^:]*)(?::(.*))?$/", $expression, $matches) ) { if (preg_match("/^([^?]*?)\s*\?([^:]*)(?::(.*))?$/", $expression, $matches)) {
// <nested_exp>?<nested_exp> | <nested_exp>?<nested_exp>:<nested_exp> // <nested_exp>?<nested_exp> | <nested_exp>?<nested_exp>:<nested_exp>
return self::evaluate_condition($matches, $data); return self::evaluate_condition($matches, $data);
} elseif( preg_match("/^(.*?)\\$(\\$?)($name)(?:\.($name)(\(\))?)?$/", $expression, $matches) ) { } elseif (preg_match("/^(.*?)\\$(\\$?)($name)(?:\.($name)(\(\))?)?$/", $expression, $matches)) {
// $<name> | $<name>.<name> | $<name>.<name>() // $<name> | $<name>.<name> | $<name>.<name>()
// | $$<name> | $$<name>.<name> | $$<name>.<name>() // | $$<name> | $$<name>.<name> | $$<name>.<name>()
return self::evaluate_variable($matches, $data); return self::evaluate_variable($matches, $data);
} elseif( preg_match("/^($function)\((.+?)\)?$/", $expression, $matches) ) { } elseif (preg_match("/^($function)\((.+?)\)?$/", $expression, $matches)) {
// <function>(<nested_exp>) // <function>(<nested_exp>)
return self::evaluate_function($matches, $data); return self::evaluate_function($matches, $data);
} elseif( preg_match("/^([A-Z0-9_]+)$/", $expression, $matches) ) { } elseif (preg_match("/^([A-Z0-9_]+)$/", $expression, $matches)) {
// <constant> // <constant>
return self::evaluate_constant($expression, $root_level); return self::evaluate_constant($expression, $root_level);
} elseif( ($split_at = strpos($expression, '||', 1)) !== false ) { } elseif (($split_at = strpos($expression, '||', 1)) !== false) {
// <nested_exp>||<nested_exp> // <nested_exp>||<nested_exp>
try { try {
return self::evaluate_expression(substr($expression, 0, $split_at), $data, false); return self::evaluate_expression(substr($expression, 0, $split_at), $data, false);
...@@ -490,10 +490,10 @@ class Template extends Node { ...@@ -490,10 +490,10 @@ class Template extends Node {
* @throws FileNotFoundError If the path does not exist. * @throws FileNotFoundError If the path does not exist.
*/ */
static function add_root($path) { static function add_root($path) {
if( $path[strlen($path) - 1] != '/' ) if ($path[strlen($path) - 1] != '/')
$path .= '/'; $path .= '/';
if( !is_dir($path) ) if (!is_dir($path))
throw new FileNotFoundError($path, true); throw new FileNotFoundError($path, true);
self::$include_path[] = $path; self::$include_path[] = $path;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment