Rename Cytro to Fenom

This commit is contained in:
bzick
2013-06-28 11:53:53 +04:00
parent f36cecaaea
commit b9ac24bb5b
44 changed files with 479 additions and 641 deletions

View File

@ -1,20 +1,20 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
use Cytro\Tokenizer;
use Cytro\Template;
use Cytro\Scope;
namespace Fenom;
use Fenom\Tokenizer;
use Fenom\Template;
use Fenom\Scope;
/**
* Compilers collection
* @package Cytro
* @package Fenom
*/
class Compiler {
/**
@ -30,7 +30,7 @@ class Compiler {
$cname = $tpl->parsePlainArg($tokens, $name);
$p = $tpl->parseParams($tokens);
if($p) { // if we have additionally variables
if($name && ($tpl->getStorage()->getOptions() & \Cytro::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
if($name && ($tpl->getStorage()->getOptions() & \Fenom::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
$inc = $tpl->getStorage()->compile($name, false);
$tpl->addDepend($inc);
return '$_tpl = (array)$tpl; $tpl->exchangeArray('.self::toArray($p).'+$_tpl); ?>'.$inc->_body.'<?php $tpl->exchangeArray($_tpl); unset($_tpl);';
@ -38,7 +38,7 @@ class Compiler {
return '$tpl->getStorage()->getTemplate('.$cname.')->display('.self::toArray($p).'+(array)$tpl);';
}
} else {
if($name && ($tpl->getStorage()->getOptions() & \Cytro::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
if($name && ($tpl->getStorage()->getOptions() & \Fenom::FORCE_INCLUDE)) { // if FORCE_INCLUDE enabled and template name known
$inc = $tpl->getStorage()->compile($name, false);
$tpl->addDepend($inc);
return '$_tpl = (array)$tpl; ?>'.$inc->_body.'<?php $tpl->exchangeArray($_tpl); unset($_tpl);';
@ -399,7 +399,7 @@ class Compiler {
$tpl->_compatible = true;
}
$tpl->_extends = $tpl_name;
return '$parent = $tpl->getStorage()->getTemplate('.$tpl_name.', \Cytro\Template::EXTENDED);';
return '$parent = $tpl->getStorage()->getTemplate('.$tpl_name.', \Fenom\Template::EXTENDED);';
}
}
@ -416,7 +416,7 @@ class Compiler {
while(isset($t->_extends)) {
$t = $t->_extends;
if(is_object($t)) {
/* @var \Cytro\Template $t */
/* @var \Fenom\Template $t */
$t->_extended = true;
$tpl->addDepend($t);
$t->_compatible = &$tpl->_compatible;
@ -470,7 +470,7 @@ class Compiler {
return '?>'.$donor->getBody().'<?php ';
} else {
$tpl->_compatible = true;
return '$donor = $tpl->getStorage()->getTemplate('.$cname.', \Cytro\Template::EXTENDED);'.PHP_EOL.
return '$donor = $tpl->getStorage()->getTemplate('.$cname.', \Fenom\Template::EXTENDED);'.PHP_EOL.
'$donor->fetch((array)$tpl);'.PHP_EOL.
'$tpl->b += (array)$donor->b';
// throw new ImproperUseException('template name must be given explicitly');

View File

@ -1,13 +1,13 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
namespace Fenom;
/**
* Collection of modifiers

View File

@ -1,20 +1,20 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
namespace Fenom;
use Cytro\ProviderInterface;
use Fenom\ProviderInterface;
/**
* Templates provider
* @author Ivan Shalganov
*/
class FSProvider implements ProviderInterface {
class Provider implements ProviderInterface {
private $_path;
/**

View File

@ -1,13 +1,13 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
namespace Fenom;
interface ProviderInterface {
/**

View File

@ -1,14 +1,14 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
use Cytro;
namespace Fenom;
use Fenom;
/**
* Primitive template
@ -41,9 +41,9 @@ class Render extends \ArrayObject {
*/
protected $_base_name = 'runtime';
/**
* @var Cytro
* @var Fenom
*/
protected $_cytro;
protected $_fenom;
/**
* Timestamp of compilation
* @var float
@ -56,7 +56,7 @@ class Render extends \ArrayObject {
protected $_depends = array();
/**
* @var int tempalte options (see Cytro options)
* @var int tempalte options (see Fenom options)
*/
protected $_options = 0;
@ -67,15 +67,15 @@ class Render extends \ArrayObject {
protected $_provider;
/**
* @param Cytro $cytro
* @param Fenom $fenom
* @param callable $code template body
* @param array $props
*/
public function __construct(Cytro $cytro, \Closure $code, $props = array()) {
$this->_cytro = $cytro;
public function __construct(Fenom $fenom, \Closure $code, $props = array()) {
$this->_fenom = $fenom;
$props += self::$_props;
$this->_name = $props["name"];
$this->_provider = $this->_cytro->getProvider($props["scm"]);
$this->_provider = $this->_fenom->getProvider($props["scm"]);
$this->_scm = $props["scm"];
$this->_time = $props["time"];
$this->_depends = $props["depends"];
@ -84,10 +84,10 @@ class Render extends \ArrayObject {
/**
* Get template storage
* @return Cytro
* @return Fenom
*/
public function getStorage() {
return $this->_cytro;
return $this->_fenom;
}
public function getDepends() {
@ -135,12 +135,12 @@ class Render extends \ArrayObject {
* @return bool
*/
public function isValid() {
$provider = $this->_cytro->getProvider(strstr($this->_name, ":"), true);
$provider = $this->_fenom->getProvider(strstr($this->_name, ":"), true);
if($provider->getLastModified($this->_name) >= $this->_time) {
return false;
}
foreach($this->_depends as $tpl => $time) {
if($this->_cytro->getTemplate($tpl)->getTime() !== $time) {
if($this->_fenom->getTemplate($tpl)->getTime() !== $time) {
return false;
}
}

View File

@ -1,13 +1,13 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
namespace Fenom;
/**
* Scope for blocks tags

View File

@ -1,19 +1,19 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
use Cytro;
namespace Fenom;
use Fenom;
/**
* Template compiler
*
* @package Cytro
* @package Fenom
* @author Ivan Shalganov <owner@bzick.net>
*/
class Template extends Render {
@ -88,21 +88,21 @@ class Template extends Render {
/**
* Just factory
*
* @param \Cytro $cytro
* @param \Fenom $fenom
* @param $options
* @return Template
*/
public static function factory(Cytro $cytro, $options) {
return new static($cytro, $options);
public static function factory(Fenom $fenom, $options) {
return new static($fenom, $options);
}
/**
* @param Cytro $cytro Template storage
* @param Fenom $fenom Template storage
* @param int $options
* @return \Cytro\Template
* @return \Fenom\Template
*/
public function __construct(Cytro $cytro, $options) {
$this->_cytro = $cytro;
public function __construct(Fenom $fenom, $options) {
$this->_fenom = $fenom;
$this->_options = $options;
}
@ -120,7 +120,7 @@ class Template extends Render {
} else {
$this->_base_name = $name;
}
$this->_provider = $this->_cytro->getProvider($provider);
$this->_provider = $this->_fenom->getProvider($provider);
$this->_src = $this->_provider->getSource($this->_base_name, $this->_time);
if($compile) {
$this->compile();
@ -133,7 +133,7 @@ class Template extends Render {
* @param string $name template name
* @param string $src template source
* @param bool $compile
* @return \Cytro\Template
* @return \Fenom\Template
*/
public function source($name, $src, $compile = true) {
$this->_name = $name;
@ -177,7 +177,7 @@ class Template extends Render {
if($end === false) { // if unexpected end of template
throw new CompileException("Unclosed tag in line {$this->_line}", 0, 1, $this->_name, $this->_line);
}
$tag = substr($this->_src, $start, $end - $start + 1); // variable $tag contains cytro tag '{...}'
$tag = substr($this->_src, $start, $end - $start + 1); // variable $tag contains fenom tag '{...}'
$_tag = substr($tag, 1, -1); // strip delimiters '{' and '}'
@ -321,8 +321,8 @@ class Template extends Render {
*/
public function getTemplateCode() {
return "<?php \n".
"/** Cytro template '".$this->_name."' compiled at ".date('Y-m-d H:i:s')." */\n".
"return new Cytro\\Render(\$cytro, ".$this->_getClosureSource().", ".var_export(array(
"/** Fenom template '".$this->_name."' compiled at ".date('Y-m-d H:i:s')." */\n".
"return new Fenom\\Render(\$fenom, ".$this->_getClosureSource().", ".var_export(array(
"options" => $this->_options,
"provider" => $this->_scm,
"name" => $this->_name,
@ -466,20 +466,20 @@ class Template extends Render {
return $this->parseMacro($tokens, $name);
}
if($act = $this->_cytro->getFunction($action)) { // call some function
if($act = $this->_fenom->getFunction($action)) { // call some function
switch($act["type"]) {
case Cytro::BLOCK_COMPILER:
case Fenom::BLOCK_COMPILER:
$scope = new Scope($action, $this, $this->_line, $act, count($this->_stack), $this->_body);
$code = $scope->open($tokens);
if(!$scope->is_closed) {
array_push($this->_stack, $scope);
}
return $code;
case Cytro::INLINE_COMPILER:
case Fenom::INLINE_COMPILER:
return call_user_func($act["parser"], $tokens, $this);
case Cytro::INLINE_FUNCTION:
case Fenom::INLINE_FUNCTION:
return call_user_func($act["parser"], $act["function"], $tokens, $this);
case Cytro::BLOCK_FUNCTION:
case Fenom::BLOCK_FUNCTION:
$scope = new Scope($action, $this, $this->_line, $act, count($this->_stack), $this->_body);
$scope->setFuncName($act["function"]);
array_push($this->_stack, $scope);
@ -494,7 +494,7 @@ class Template extends Render {
return $this->_stack[$i]->tag($action, $tokens);
}
}
if($tags = $this->_cytro->getTagOwners($action)) { // unknown template tag
if($tags = $this->_fenom->getTagOwners($action)) { // unknown template tag
throw new TokenizeException("Unexpected tag '$action' (this tag can be used with '".implode("', '", $tags)."')");
} else {
throw new TokenizeException("Unexpected tag $action");
@ -548,7 +548,7 @@ class Template extends Render {
if($tokens->isSpecialVal()) {
$_exp .= $tokens->getAndNext();
} elseif($tokens->isNext("(")) {
$func = $this->_cytro->getModifier($tokens->current());
$func = $this->_fenom->getModifier($tokens->current());
$tokens->next();
$_exp .= $func.$this->parseArgs($tokens);
} else {
@ -687,7 +687,7 @@ class Template extends Render {
} elseif($t === T_OBJECT_OPERATOR) {
$prop = $tokens->getNext(T_STRING);
if($tokens->isNext("(")) {
if($this->_options & Cytro::DENY_METHODS) {
if($this->_options & Fenom::DENY_METHODS) {
throw new \LogicException("Forbidden to call methods");
}
$pure_var = false;
@ -844,7 +844,7 @@ class Template extends Render {
*/
public function parseModifier(Tokenizer $tokens, $value) {
while($tokens->is("|")) {
$mods = $this->_cytro->getModifier( $modifier_name = $tokens->getNext(Tokenizer::MACRO_STRING) );
$mods = $this->_fenom->getModifier( $modifier_name = $tokens->getNext(Tokenizer::MACRO_STRING) );
$tokens->next();
$args = array();

View File

@ -1,13 +1,13 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
namespace Cytro;
namespace Fenom;
/**
* for <PHP 5.4 compatible
@ -32,7 +32,7 @@ defined('T_YIELD') || define('T_YIELD', 370);
* @property array $curr the current token
* @property array $next the next token
*
* @package Cytro
* @package Fenom
*/
class Tokenizer {
const TOKEN = 0;

View File

@ -1,19 +1,19 @@
<?php
/*
* This file is part of Cytro.
* This file is part of Fenom.
*
* (c) 2013 Ivan Shalganov
*
* For the full copyright and license information, please view the license.md
* file that was distributed with this source code.
*/
use Cytro\Template,
Cytro\ProviderInterface;
use Fenom\Template,
Fenom\ProviderInterface;
/**
* Cytro Template Engine
* Fenom Template Engine
*/
class Cytro {
class Fenom {
const VERSION = '1.0';
/* Compiler types */
@ -32,11 +32,11 @@ class Cytro {
const DISABLE_CACHE = 0x1F0;
/* Default parsers */
const DEFAULT_CLOSE_COMPILER = 'Cytro\Compiler::stdClose';
const DEFAULT_FUNC_PARSER = 'Cytro\Compiler::stdFuncParser';
const DEFAULT_FUNC_OPEN = 'Cytro\Compiler::stdFuncOpen';
const DEFAULT_FUNC_CLOSE = 'Cytro\Compiler::stdFuncClose';
const SMART_FUNC_PARSER = 'Cytro\Compiler::smartFuncParser';
const DEFAULT_CLOSE_COMPILER = 'Fenom\Compiler::stdClose';
const DEFAULT_FUNC_PARSER = 'Fenom\Compiler::stdFuncParser';
const DEFAULT_FUNC_OPEN = 'Fenom\Compiler::stdFuncOpen';
const DEFAULT_FUNC_CLOSE = 'Fenom\Compiler::stdFuncClose';
const SMART_FUNC_PARSER = 'Fenom\Compiler::smartFuncParser';
/**
* @var int[] of possible options, as associative array
@ -52,7 +52,7 @@ class Cytro {
);
/**
* @var Cytro\Render[] Templates storage
* @var Fenom\Render[] Templates storage
*/
protected $_storage = array();
/**
@ -74,7 +74,7 @@ class Cytro {
*/
private $_provider;
/**
* @var Cytro\ProviderInterface[]
* @var Fenom\ProviderInterface[]
*/
protected $_providers = array();
@ -86,15 +86,15 @@ class Cytro {
"up" => 'strtoupper',
"lower" => 'strtolower',
"low" => 'strtolower',
"date_format" => 'Cytro\Modifier::dateFormat',
"date" => 'Cytro\Modifier::date',
"truncate" => 'Cytro\Modifier::truncate',
"escape" => 'Cytro\Modifier::escape',
"e" => 'Cytro\Modifier::escape', // alias of escape
"unescape" => 'Cytro\Modifier::unescape',
"strip" => 'Cytro\Modifier::strip',
"length" => 'Cytro\Modifier::length',
"default" => 'Cytro\Modifier::defaultValue'
"date_format" => 'Fenom\Modifier::dateFormat',
"date" => 'Fenom\Modifier::date',
"truncate" => 'Fenom\Modifier::truncate',
"escape" => 'Fenom\Modifier::escape',
"e" => 'Fenom\Modifier::escape', // alias of escape
"unescape" => 'Fenom\Modifier::unescape',
"strip" => 'Fenom\Modifier::strip',
"length" => 'Fenom\Modifier::length',
"default" => 'Fenom\Modifier::defaultValue'
);
/**
@ -112,137 +112,137 @@ class Cytro {
protected $_actions = array(
'foreach' => array( // {foreach ...} {break} {continue} {foreachelse} {/foreach}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::foreachOpen',
'close' => 'Cytro\Compiler::foreachClose',
'open' => 'Fenom\Compiler::foreachOpen',
'close' => 'Fenom\Compiler::foreachClose',
'tags' => array(
'foreachelse' => 'Cytro\Compiler::foreachElse',
'break' => 'Cytro\Compiler::tagBreak',
'continue' => 'Cytro\Compiler::tagContinue',
'foreachelse' => 'Fenom\Compiler::foreachElse',
'break' => 'Fenom\Compiler::tagBreak',
'continue' => 'Fenom\Compiler::tagContinue',
),
'float_tags' => array('break' => 1, 'continue' => 1)
),
'if' => array( // {if ...} {elseif ...} {else} {/if}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::ifOpen',
'close' => 'Cytro\Compiler::stdClose',
'open' => 'Fenom\Compiler::ifOpen',
'close' => 'Fenom\Compiler::stdClose',
'tags' => array(
'elseif' => 'Cytro\Compiler::tagElseIf',
'else' => 'Cytro\Compiler::tagElse',
'elseif' => 'Fenom\Compiler::tagElseIf',
'else' => 'Fenom\Compiler::tagElse',
)
),
'switch' => array( // {switch ...} {case ...} {break} {default} {/switch}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::switchOpen',
'close' => 'Cytro\Compiler::stdClose',
'open' => 'Fenom\Compiler::switchOpen',
'close' => 'Fenom\Compiler::stdClose',
'tags' => array(
'case' => 'Cytro\Compiler::tagCase',
'default' => 'Cytro\Compiler::tagDefault',
'break' => 'Cytro\Compiler::tagBreak',
'case' => 'Fenom\Compiler::tagCase',
'default' => 'Fenom\Compiler::tagDefault',
'break' => 'Fenom\Compiler::tagBreak',
),
'float_tags' => array('break' => 1)
),
'for' => array( // {for ...} {break} {continue} {/for}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::forOpen',
'close' => 'Cytro\Compiler::forClose',
'open' => 'Fenom\Compiler::forOpen',
'close' => 'Fenom\Compiler::forClose',
'tags' => array(
'forelse' => 'Cytro\Compiler::forElse',
'break' => 'Cytro\Compiler::tagBreak',
'continue' => 'Cytro\Compiler::tagContinue',
'forelse' => 'Fenom\Compiler::forElse',
'break' => 'Fenom\Compiler::tagBreak',
'continue' => 'Fenom\Compiler::tagContinue',
),
'float_tags' => array('break' => 1, 'continue' => 1)
),
'while' => array( // {while ...} {break} {continue} {/while}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::whileOpen',
'close' => 'Cytro\Compiler::stdClose',
'open' => 'Fenom\Compiler::whileOpen',
'close' => 'Fenom\Compiler::stdClose',
'tags' => array(
'break' => 'Cytro\Compiler::tagBreak',
'continue' => 'Cytro\Compiler::tagContinue',
'break' => 'Fenom\Compiler::tagBreak',
'continue' => 'Fenom\Compiler::tagContinue',
),
'float_tags' => array('break' => 1, 'continue' => 1)
),
'include' => array( // {include ...}
'type' => self::INLINE_COMPILER,
'parser' => 'Cytro\Compiler::tagInclude'
'parser' => 'Fenom\Compiler::tagInclude'
),
'var' => array( // {var ...}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::varOpen',
'close' => 'Cytro\Compiler::varClose'
'open' => 'Fenom\Compiler::varOpen',
'close' => 'Fenom\Compiler::varClose'
),
'block' => array( // {block ...} {parent} {/block}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::tagBlockOpen',
'close' => 'Cytro\Compiler::tagBlockClose',
'open' => 'Fenom\Compiler::tagBlockOpen',
'close' => 'Fenom\Compiler::tagBlockClose',
'tags' => array(
'parent' => 'Cytro\Compiler::tagParent'
'parent' => 'Fenom\Compiler::tagParent'
),
'float_tags' => array('parent' => 1)
),
'extends' => array( // {extends ...}
'type' => self::INLINE_COMPILER,
'parser' => 'Cytro\Compiler::tagExtends'
'parser' => 'Fenom\Compiler::tagExtends'
),
'use' => array( // {use}
'type' => self::INLINE_COMPILER,
'parser' => 'Cytro\Compiler::tagUse'
'parser' => 'Fenom\Compiler::tagUse'
),
'capture' => array( // {capture ...} {/capture}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::captureOpen',
'close' => 'Cytro\Compiler::captureClose'
'open' => 'Fenom\Compiler::captureOpen',
'close' => 'Fenom\Compiler::captureClose'
),
'filter' => array( // {filter} ... {/filter}
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::filterOpen',
'close' => 'Cytro\Compiler::filterClose'
'open' => 'Fenom\Compiler::filterOpen',
'close' => 'Fenom\Compiler::filterClose'
),
'macro' => array(
'type' => self::BLOCK_COMPILER,
'open' => 'Cytro\Compiler::macroOpen',
'close' => 'Cytro\Compiler::macroClose'
'open' => 'Fenom\Compiler::macroOpen',
'close' => 'Fenom\Compiler::macroClose'
),
'import' => array(
'type' => self::INLINE_COMPILER,
'parser' => 'Cytro\Compiler::tagImport'
'parser' => 'Fenom\Compiler::tagImport'
),
'cycle' => array(
'type' => self::INLINE_COMPILER,
'parser' => 'Cytro\Compiler::tagCycle'
'parser' => 'Fenom\Compiler::tagCycle'
)
);
/**
* Just factory
*
* @param string|Cytro\ProviderInterface $source path to templates or custom provider
* @param string|Fenom\ProviderInterface $source path to templates or custom provider
* @param string $compile_dir path to compiled files
* @param int $options
* @throws InvalidArgumentException
* @return Cytro
* @return Fenom
*/
public static function factory($source, $compile_dir = '/tmp', $options = 0) {
if(is_string($source)) {
$provider = new Cytro\FSProvider($source);
$provider = new Fenom\Provider($source);
} elseif($source instanceof ProviderInterface) {
$provider = $source;
} else {
throw new InvalidArgumentException("Source must be a valid path or provider object");
}
$cytro = new static($provider);
/* @var Cytro $cytro */
$cytro->setCompileDir($compile_dir);
$fenom = new static($provider);
/* @var Fenom $fytro */
$fenom->setCompileDir($compile_dir);
if($options) {
$cytro->setOptions($options);
$fenom->setOptions($options);
}
return $cytro;
return $fenom;
}
/**
* @param Cytro\ProviderInterface $provider
* @param Fenom\ProviderInterface $provider
*/
public function __construct(Cytro\ProviderInterface $provider) {
public function __construct(Fenom\ProviderInterface $provider) {
$this->_provider = $provider;
}
@ -250,7 +250,7 @@ class Cytro {
* Set compile directory
*
* @param string $dir directory to store compiled templates in
* @return Cytro
* @return Fenom
*/
public function setCompileDir($dir) {
$this->_compile_dir = $dir;
@ -285,7 +285,7 @@ class Cytro {
*
* @param string $modifier the modifier name
* @param string $callback the modifier callback
* @return Cytro
* @return Fenom
*/
public function addModifier($modifier, $callback) {
$this->_modifiers[$modifier] = $callback;
@ -297,7 +297,7 @@ class Cytro {
*
* @param string $compiler
* @param callable $parser
* @return Cytro
* @return Fenom
*/
public function addCompiler($compiler, $parser) {
$this->_actions[$compiler] = array(
@ -329,7 +329,7 @@ class Cytro {
* @param callable $open_parser
* @param callable|string $close_parser
* @param array $tags
* @return Cytro
* @return Fenom
*/
public function addBlockCompiler($compiler, $open_parser, $close_parser = self::DEFAULT_CLOSE_COMPILER, array $tags = array()) {
$this->_actions[$compiler] = array(
@ -347,7 +347,7 @@ class Cytro {
* @param array $tags
* @param array $floats
* @throws LogicException
* @return Cytro
* @return Fenom
*/
public function addBlockCompilerSmart($compiler, $storage, array $tags, array $floats = array()) {
$c = array(
@ -383,7 +383,7 @@ class Cytro {
* @param string $function
* @param callable $callback
* @param callable|string $parser
* @return Cytro
* @return Fenom
*/
public function addFunction($function, $callback, $parser = self::DEFAULT_FUNC_PARSER) {
$this->_actions[$function] = array(
@ -397,7 +397,7 @@ class Cytro {
/**
* @param string $function
* @param callable $callback
* @return Cytro
* @return Fenom
*/
public function addFunctionSmart($function, $callback) {
$this->_actions[$function] = array(
@ -413,7 +413,7 @@ class Cytro {
* @param callable $callback
* @param callable|string $parser_open
* @param callable|string $parser_close
* @return Cytro
* @return Fenom
*/
public function addBlockFunction($function, $callback, $parser_open = self::DEFAULT_FUNC_OPEN, $parser_close = self::DEFAULT_FUNC_CLOSE) {
$this->_actions[$function] = array(
@ -427,7 +427,7 @@ class Cytro {
/**
* @param array $funcs
* @return Cytro
* @return Fenom
*/
public function addAllowedFunctions(array $funcs) {
$this->_allowed_funcs = $this->_allowed_funcs + array_flip($funcs);
@ -495,9 +495,9 @@ class Cytro {
* Add source template provider by scheme
*
* @param string $scm scheme name
* @param Cytro\ProviderInterface $provider provider object
* @param Fenom\ProviderInterface $provider provider object
*/
public function addProvider($scm, \Cytro\ProviderInterface $provider) {
public function addProvider($scm, \Fenom\ProviderInterface $provider) {
$this->_providers[$scm] = $provider;
}
@ -528,7 +528,7 @@ class Cytro {
/**
* @param bool|string $scm
* @return Cytro\ProviderInterface
* @return Fenom\ProviderInterface
* @throws InvalidArgumentException
*/
public function getProvider($scm = false) {
@ -546,10 +546,10 @@ class Cytro {
/**
* Return empty template
*
* @return Cytro\Template
* @return Fenom\Template
*/
public function getRawTemplate() {
return new \Cytro\Template($this, $this->_options);
return new \Fenom\Template($this, $this->_options);
}
/**
@ -557,7 +557,7 @@ class Cytro {
*
* @param string $template name of template
* @param array $vars array of data for template
* @return Cytro\Render
* @return Fenom\Render
*/
public function display($template, array $vars = array()) {
return $this->getTemplate($template)->display($vars);
@ -580,8 +580,8 @@ class Cytro {
* @param array $vars
* @param $callback
* @param float $chunk
* @return \Cytro\Render
* @example $cytro->pipe("products.yml.tpl", $iterators, [new SplFileObject("/tmp/products.yml"), "fwrite"], 512*1024)
* @return \Fenom\Render
* @example $fenom->pipe("products.yml.tpl", $iterators, [new SplFileObject("/tmp/products.yml"), "fwrite"], 512*1024)
*/
public function pipe($template, array $vars, $callback, $chunk = 1e6) {
ob_start($callback, $chunk, true);
@ -595,12 +595,12 @@ class Cytro {
*
* @param string $template template name with schema
* @param int $options additional options and flags
* @return Cytro\Template
* @return Fenom\Template
*/
public function getTemplate($template, $options = 0) {
$key = dechex($this->_options | $options)."@".$template;
if(isset($this->_storage[ $key ])) {
/** @var Cytro\Template $tpl */
/** @var Fenom\Template $tpl */
$tpl = $this->_storage[ $key ];
if(($this->_options & self::AUTO_RELOAD) && !$tpl->isValid()) {
return $this->_storage[ $key ] = $this->compile($template, true, $options);
@ -617,9 +617,9 @@ class Cytro {
/**
* Add custom template into storage
*
* @param Cytro\Render $template
* @param Fenom\Render $template
*/
public function addTemplate(Cytro\Render $template) {
public function addTemplate(Fenom\Render $template) {
$this->_storage[dechex($template->getOptions()).'@'. $template->getName() ] = $template;
}
@ -628,14 +628,14 @@ class Cytro {
*
* @param string $tpl
* @param int $opts
* @return Cytro\Render
* @return Fenom\Render
*/
protected function _load($tpl, $opts) {
$file_name = $this->_getCacheName($tpl, $opts);
if(!is_file($this->_compile_dir."/".$file_name)) {
return $this->compile($tpl, true, $opts);
} else {
$cytro = $this;
$fenom = $this;
return include($this->_compile_dir."/".$file_name);
}
}
@ -659,7 +659,7 @@ class Cytro {
* @param bool $store store template on disk
* @param int $options
* @throws RuntimeException
* @return \Cytro\Template
* @return \Fenom\Template
*/
public function compile($tpl, $store = true, $options = 0) {
$options = $this->_options | $options;
@ -692,7 +692,7 @@ class Cytro {
* Remove all compiled templates
*/
public function clearAllCompiles() {
\Cytro\FSProvider::clean($this->_compile_dir);
\Fenom\Provider::clean($this->_compile_dir);
}
/**
@ -700,7 +700,7 @@ class Cytro {
*
* @param string $code
* @param string $name
* @return Cytro\Template
* @return Fenom\Template
*/
public function compileCode($code, $name = 'Runtime compile') {
return Template::factory($this, $this->_options)->source($name, $code);