initial commit
This commit is contained in:
commit
e869a1cab4
107 changed files with 9029 additions and 0 deletions
77
app/library/ViewHelper/Service.php
Normal file
77
app/library/ViewHelper/Service.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace ViewHelper;
|
||||
|
||||
use Phalcon\DiInterface;
|
||||
use Phalcon\Di\InjectionAwareInterface;
|
||||
|
||||
class Service implements InjectionAwareInterface
|
||||
{
|
||||
protected $_helpers = array();
|
||||
|
||||
protected $_di;
|
||||
|
||||
/**
|
||||
* Sets the dependency injector
|
||||
*
|
||||
* @param mixed $dependencyInjector
|
||||
*/
|
||||
public function setDI(DiInterface $dependencyInjector)
|
||||
{
|
||||
$this->_di = $dependencyInjector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal dependency injector
|
||||
*
|
||||
* @return \Phalcon\DiInterface
|
||||
*/
|
||||
public function getDI()
|
||||
{
|
||||
return $this->_di;
|
||||
}
|
||||
|
||||
public function set($name, AbstractHelper $helper)
|
||||
{
|
||||
$helper->setDI($this->getDI());
|
||||
|
||||
$this->_helpers[$name] = $helper;
|
||||
}
|
||||
|
||||
public function has($name)
|
||||
{
|
||||
return $this->_locateHelper($name) !== false;
|
||||
}
|
||||
|
||||
public function get($name)
|
||||
{
|
||||
if ($this->has($name)) {
|
||||
return $this->_helpers[$name];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __call($name, $args)
|
||||
{
|
||||
$helper = $this->get($name);
|
||||
if ($helper) {
|
||||
return call_user_func_array(array($helper, $name), $args);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function _locateHelper($name)
|
||||
{
|
||||
if (array_key_exists($name, $this->_helpers)) {
|
||||
return $this->_helpers[$name];
|
||||
}
|
||||
|
||||
$class = '\ViewHelper\\' . ucfirst($name);
|
||||
if (class_exists($class)) {
|
||||
$helper = new $class();
|
||||
$this->set($name, $helper);
|
||||
return $helper;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in a new issue