Cleanup class

Add docs
Add functions
This commit is contained in:
bzick
2013-02-20 18:09:24 +04:00
parent 9ba3ee68f8
commit e86eb1f383

View File

@ -194,27 +194,33 @@ class Aspect {
'type' => self::INLINE_COMPILER, 'type' => self::INLINE_COMPILER,
'parser' => 'Aspect\Compiler::assign' 'parser' => 'Aspect\Compiler::assign'
), ),
'block' => array( // {block ...} {/block} 'block' => array( // {block ...} {parent} {/block}
'type' => self::BLOCK_COMPILER, 'type' => self::BLOCK_COMPILER,
'open' => 'Aspect\Compiler::tagBlockOpen', 'open' => 'Aspect\Compiler::tagBlockOpen',
'close' => 'Aspect\Compiler::tagBlockClose', 'close' => 'Aspect\Compiler::tagBlockClose',
'tags' => array(
'parent' => 'Aspect\Compiler::tagParent'
),
'float_tags' => array('parent' => 1)
), ),
'extends' => array( // {extends ...} 'extends' => array( // {extends ...}
'type' => self::INLINE_COMPILER, 'type' => self::INLINE_COMPILER,
'parser' => 'Aspect\Compiler::tagExtends' 'parser' => 'Aspect\Compiler::tagExtends'
), ),
'capture' => array( // {capture ...} {/capture} 'use' => array( // {use}
'type' => self::BLOCK_FUNCTION, 'type' => self::INLINE_COMPILER,
'open' => 'Aspect\Compiler::stdFuncOpen', 'parser' => 'Aspect\Compiler::tagUse'
'close' => 'Aspect\Compiler::stdFuncClose',
'function' => 'Aspect\Func::capture',
), ),
'mailto' => array( 'capture' => array( // {capture ...} {/capture}
'type' => self::INLINE_FUNCTION, 'type' => self::BLOCK_COMPILER,
'parser' => 'Aspect\Compiler::stdFuncParser', 'open' => 'Aspect\Compiler::captureOpen',
'function' => 'Aspect\Func::mailto', 'close' => 'Aspect\Compiler::captureClose'
),
'filter' => array( // {filter} ... {/filter}
'type' => self::BLOCK_COMPILER,
'open' => 'Aspect\Compiler::filterOpen',
'close' => 'Aspect\Compiler::filterClose'
) )
); );
/** /**
@ -249,27 +255,6 @@ class Aspect {
$this->_provider = $provider; $this->_provider = $provider;
} }
/**
* Set checks template for modifications
* @param $state
* @return Aspect
*/
public function setCompileCheck($state) {
$state && ($this->_options |= self::CHECK_MTIME);
return $this;
}
/**
* Set force template compiling
* @param $state
* @return Aspect
*/
public function setForceCompile($state) {
$state && ($this->_options |= self::FORCE_COMPILE);
$this->_storage = $state ? new Aspect\BlackHole() : array();
return $this;
}
/** /**
* Set compile directory * Set compile directory
* @param string $dir directory to store compiled templates in * @param string $dir directory to store compiled templates in
@ -316,8 +301,10 @@ class Aspect {
} }
/** /**
* Add inline tag compiler
*
* @param string $compiler * @param string $compiler
* @param string $parser * @param callable $parser
* @return Aspect * @return Aspect
*/ */
public function addCompiler($compiler, $parser) { public function addCompiler($compiler, $parser) {
@ -329,9 +316,11 @@ class Aspect {
} }
/** /**
* Add block compiler
*
* @param string $compiler * @param string $compiler
* @param string $open_parser * @param callable $open_parser
* @param string $close_parser * @param callable $close_parser
* @param array $tags * @param array $tags
* @return Aspect * @return Aspect
*/ */
@ -348,7 +337,7 @@ class Aspect {
/** /**
* @param string $function * @param string $function
* @param callable $callback * @param callable $callback
* @param string $parser * @param callable $parser
* @return Aspect * @return Aspect
*/ */
public function addFunction($function, $callback, $parser = self::DEFAULT_FUNC_PARSER) { public function addFunction($function, $callback, $parser = self::DEFAULT_FUNC_PARSER) {
@ -375,10 +364,10 @@ class Aspect {
} }
/** /**
* @param $function * @param string $function
* @param $callback * @param callable $callback
* @param null $parser_open * @param callable $parser_open
* @param null $parser_close * @param callable $parser_close
* @return Aspect * @return Aspect
*/ */
public function addBlockFunction($function, $callback, $parser_open = null, $parser_close = null) { public function addBlockFunction($function, $callback, $parser_open = null, $parser_close = null) {
@ -401,6 +390,8 @@ class Aspect {
} }
/** /**
* Return modifier function
*
* @param $modifier * @param $modifier
* @return mixed * @return mixed
* @throws \Exception * @throws \Exception
@ -416,6 +407,8 @@ class Aspect {
} }
/** /**
* Return function
*
* @param string $function * @param string $function
* @return string|bool * @return string|bool
*/ */
@ -427,6 +420,10 @@ class Aspect {
} }
} }
/**
* @param string $function
* @return bool
*/
public function isAllowedFunction($function) { public function isAllowedFunction($function) {
if($this->_options & self::DENY_INLINE_FUNCS) { if($this->_options & self::DENY_INLINE_FUNCS) {
return isset($this->_allowed_funcs[$function]); return isset($this->_allowed_funcs[$function]);
@ -435,6 +432,7 @@ class Aspect {
} }
} }
public function getTagOwners($tag) { public function getTagOwners($tag) {
$tags = array(); $tags = array();
foreach($this->_actions as $owner => $params) { foreach($this->_actions as $owner => $params) {
@ -445,7 +443,12 @@ class Aspect {
return $tags; return $tags;
} }
/**
* Add source template provider by scheme
*
* @param string $scm scheme name
* @param Aspect\ProviderInterface $provider provider object
*/
public function addProvider($scm, \Aspect\ProviderInterface $provider) { public function addProvider($scm, \Aspect\ProviderInterface $provider) {
$this->_providers[$scm] = $provider; $this->_providers[$scm] = $provider;
} }
@ -463,7 +466,7 @@ class Aspect {
if(is_array($options)) { if(is_array($options)) {
$options = Aspect\Misc::makeMask($options, self::$_option_list); $options = Aspect\Misc::makeMask($options, self::$_option_list);
} }
$this->_storage = ($options & self::FORCE_COMPILE) ? new Aspect\BlackHole() : array(); $this->_storage = array();
$this->_options = $options; $this->_options = $options;
} }
@ -492,6 +495,11 @@ class Aspect {
} }
} }
/**
* Return empty template
*
* @return Aspect\Template
*/
public function getRawTemplate() { public function getRawTemplate() {
return new \Aspect\Template($this); return new \Aspect\Template($this);
} }
@ -499,9 +507,8 @@ class Aspect {
/** /**
* Execute template and write result into stdout * Execute template and write result into stdout
* *
* * @param string $template name of template
* @param string $template * @param array $vars array of data for template
* @param array $vars
* @return Aspect\Render * @return Aspect\Render
*/ */
public function display($template, array $vars = array()) { public function display($template, array $vars = array()) {
@ -510,8 +517,8 @@ class Aspect {
/** /**
* *
* @param string $template * @param string $template name of template
* @param array $vars * @param array $vars array of data for template
* @internal param int $options * @internal param int $options
* @return mixed * @return mixed
*/ */
@ -535,7 +542,7 @@ class Aspect {
return $this->_storage[ $template ]; return $this->_storage[ $template ];
} }
} elseif($this->_options & self::FORCE_COMPILE) { } elseif($this->_options & self::FORCE_COMPILE) {
return $this->compile($template); return $this->compile($template, false);
} else { } else {
return $this->_storage[ $template ] = $this->_load($template); return $this->_storage[ $template ] = $this->_load($template);
} }