initial commit
This commit is contained in:
commit
e869a1cab4
107 changed files with 9029 additions and 0 deletions
31
app/library/ViewHelper/AbstractHelper.php
Normal file
31
app/library/ViewHelper/AbstractHelper.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace ViewHelper;
|
||||
|
||||
use Phalcon\DiInterface;
|
||||
use Phalcon\Di\InjectionAwareInterface;
|
||||
|
||||
abstract class AbstractHelper implements InjectionAwareInterface
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
29
app/library/ViewHelper/Icon.php
Normal file
29
app/library/ViewHelper/Icon.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace ViewHelper;
|
||||
|
||||
/**
|
||||
* Class Icon
|
||||
*
|
||||
* @package ViewHelper
|
||||
*/
|
||||
class Icon extends AbstractHelper
|
||||
{
|
||||
public function icon($name, $args = array())
|
||||
{
|
||||
$classes = array(
|
||||
'icon',
|
||||
'ion-' . $name
|
||||
);
|
||||
|
||||
if (is_array($args)) {
|
||||
|
||||
foreach($args as $arg) {
|
||||
$classes[] .= 'ion-' . $arg;
|
||||
}
|
||||
}
|
||||
|
||||
$classes = implode(' ', $classes);
|
||||
return '<i class="' . $classes . '"></i>';
|
||||
}
|
||||
}
|
||||
57
app/library/ViewHelper/ServerUrl.php
Normal file
57
app/library/ViewHelper/ServerUrl.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace ViewHelper;
|
||||
|
||||
/**
|
||||
* Class ServerUrl
|
||||
*
|
||||
* @package ViewHelper
|
||||
*/
|
||||
class ServerUrl extends AbstractHelper
|
||||
{
|
||||
protected $_request;
|
||||
|
||||
public function getScheme()
|
||||
{
|
||||
return $this->_getRequest()->getScheme();
|
||||
}
|
||||
|
||||
public function getHost()
|
||||
{
|
||||
return $this->_getRequest()->getHttpHost();
|
||||
}
|
||||
|
||||
public function getPort()
|
||||
{
|
||||
return $this->_getRequest()->getPort();
|
||||
}
|
||||
|
||||
public function serverUrl()
|
||||
{
|
||||
$port = $this->getPort();
|
||||
$scheme = $this->getScheme();
|
||||
|
||||
// remove port if it's the default port.
|
||||
if (($scheme == 'http' && $port == 80)
|
||||
|| ($scheme == 'https' && $port == 443)) {
|
||||
$port = null;
|
||||
}
|
||||
|
||||
$url = $scheme . '://' . $this->getHost();
|
||||
if ($port !== null) {
|
||||
$url .= ':' . $port;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Phalcon\Http\RequestInterface
|
||||
*/
|
||||
protected function _getRequest()
|
||||
{
|
||||
if ($this->_request === null) {
|
||||
$this->_request = $this->getDI()->getRequest();
|
||||
}
|
||||
return $this->_request;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
56
app/library/ViewHelper/Volt/Extension.php
Normal file
56
app/library/ViewHelper/Volt/Extension.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace ViewHelper\Volt;
|
||||
|
||||
use \Phalcon\Di\InjectionAwareInterface;
|
||||
|
||||
class Extension implements InjectionAwareInterface
|
||||
{
|
||||
protected $_serviceKey = 'viewHelper';
|
||||
|
||||
/**
|
||||
* @var \Phalcon\DiInterface
|
||||
*/
|
||||
protected $_di;
|
||||
|
||||
public function __construct(\Phalcon\DiInterface $dependencyInjector)
|
||||
{
|
||||
$this->_di = $dependencyInjector;
|
||||
|
||||
if (!$this->_di->has($this->_serviceKey)) {
|
||||
$this->_di->set($this->_serviceKey, '\ViewHelper\Service', true);
|
||||
}
|
||||
}
|
||||
|
||||
public function compileFunction($name, $args)
|
||||
{
|
||||
// Get the view helper service.
|
||||
$service = $this->_di->getShared($this->_serviceKey);
|
||||
|
||||
// Search for the helper in service.
|
||||
if ($service->has($name)) {
|
||||
return "\$this->{$this->_serviceKey}->{$name}({$args})";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the dependency injector
|
||||
*
|
||||
* @param mixed $dependencyInjector
|
||||
*/
|
||||
public function setDI(\Phalcon\DiInterface $dependencyInjector)
|
||||
{
|
||||
$this->_di = $dependencyInjector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal dependency injector
|
||||
*
|
||||
* @return \Phalcon\DiInterface
|
||||
*/
|
||||
public function getDI()
|
||||
{
|
||||
return $this->_di;
|
||||
}
|
||||
}
|
||||
Reference in a new issue