mirror of
https://github.com/fenom-template/fenom.git
synced 2023-08-10 21:13:07 +03:00
fix Render
This commit is contained in:
@@ -8,13 +8,15 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
namespace Fenom;
|
namespace Fenom;
|
||||||
|
|
||||||
use Fenom;
|
use Fenom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Primitive template
|
* Primitive template
|
||||||
* @author Ivan Shalganov <a.cobest@gmail.com>
|
* @author Ivan Shalganov <a.cobest@gmail.com>
|
||||||
*/
|
*/
|
||||||
class Render extends \ArrayObject {
|
class Render extends \ArrayObject
|
||||||
|
{
|
||||||
private static $_props = array(
|
private static $_props = array(
|
||||||
"name" => "runtime",
|
"name" => "runtime",
|
||||||
"base_name" => "",
|
"base_name" => "",
|
||||||
@@ -50,17 +52,14 @@ class Render extends \ArrayObject {
|
|||||||
* @var float
|
* @var float
|
||||||
*/
|
*/
|
||||||
protected $_time = 0.0;
|
protected $_time = 0.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array depends list
|
* @var array depends list
|
||||||
*/
|
*/
|
||||||
protected $_depends = array();
|
protected $_depends = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int tempalte options (see Fenom options)
|
* @var int tempalte options (see Fenom options)
|
||||||
*/
|
*/
|
||||||
protected $_options = 0;
|
protected $_options = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template provider
|
* Template provider
|
||||||
* @var ProviderInterface
|
* @var ProviderInterface
|
||||||
@@ -72,7 +71,8 @@ class Render extends \ArrayObject {
|
|||||||
* @param callable $code template body
|
* @param callable $code template body
|
||||||
* @param array $props
|
* @param array $props
|
||||||
*/
|
*/
|
||||||
public function __construct(Fenom $fenom, \Closure $code, $props = array()) {
|
public function __construct(Fenom $fenom, \Closure $code, $props = array())
|
||||||
|
{
|
||||||
$this->_fenom = $fenom;
|
$this->_fenom = $fenom;
|
||||||
$props += self::$_props;
|
$props += self::$_props;
|
||||||
$this->_name = $props["name"];
|
$this->_name = $props["name"];
|
||||||
@@ -87,34 +87,41 @@ class Render extends \ArrayObject {
|
|||||||
* Get template storage
|
* Get template storage
|
||||||
* @return Fenom
|
* @return Fenom
|
||||||
*/
|
*/
|
||||||
public function getStorage() {
|
public function getStorage()
|
||||||
|
{
|
||||||
return $this->_fenom;
|
return $this->_fenom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDepends() {
|
public function getDepends()
|
||||||
|
{
|
||||||
return $this->_depends;
|
return $this->_depends;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getScm() {
|
public function getScm()
|
||||||
|
{
|
||||||
return $this->_scm;
|
return $this->_scm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProvider() {
|
public function getProvider()
|
||||||
|
{
|
||||||
return $this->_provider;
|
return $this->_provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBaseName() {
|
public function getBaseName()
|
||||||
|
{
|
||||||
return $this->_base_name;
|
return $this->_base_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOptions() {
|
public function getOptions()
|
||||||
|
{
|
||||||
return $this->_options;
|
return $this->_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __toString() {
|
public function __toString()
|
||||||
|
{
|
||||||
return $this->_name;
|
return $this->_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,20 +129,22 @@ class Render extends \ArrayObject {
|
|||||||
* Get template name
|
* Get template name
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getName() {
|
public function getName()
|
||||||
|
{
|
||||||
return $this->_name;
|
return $this->_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTime() {
|
public function getTime()
|
||||||
|
{
|
||||||
return $this->_time;
|
return $this->_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate template
|
* Validate template
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isValid() {
|
public function isValid()
|
||||||
|
{
|
||||||
$provider = $this->_fenom->getProvider(strstr($this->_name, ":"), true);
|
$provider = $this->_fenom->getProvider(strstr($this->_name, ":"), true);
|
||||||
if ($provider->getLastModified($this->_name) >= $this->_time) {
|
if ($provider->getLastModified($this->_name) >= $this->_time) {
|
||||||
return false;
|
return false;
|
||||||
@@ -145,6 +154,7 @@ class Render extends \ArrayObject {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,9 +163,11 @@ class Render extends \ArrayObject {
|
|||||||
* @param array $values for template
|
* @param array $values for template
|
||||||
* @return Render
|
* @return Render
|
||||||
*/
|
*/
|
||||||
public function display(array $values) {
|
public function display(array $values)
|
||||||
|
{
|
||||||
$this->exchangeArray($values);
|
$this->exchangeArray($values);
|
||||||
$this->_code->__invoke($this);
|
$this->_code->__invoke($this);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,10 +177,12 @@ class Render extends \ArrayObject {
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function fetch(array $values) {
|
public function fetch(array $values)
|
||||||
|
{
|
||||||
ob_start();
|
ob_start();
|
||||||
try {
|
try {
|
||||||
$this->display($values);
|
$this->display($values);
|
||||||
|
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
@@ -182,7 +196,8 @@ class Render extends \ArrayObject {
|
|||||||
* @param $args
|
* @param $args
|
||||||
* @throws \BadMethodCallException
|
* @throws \BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public function __call($method, $args) {
|
public function __call($method, $args)
|
||||||
|
{
|
||||||
throw new \BadMethodCallException("Unknown method " . $method);
|
throw new \BadMethodCallException("Unknown method " . $method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user