Optional krutush and more
This commit is contained in:
parent
26e9002369
commit
7bb3b0b3da
30
src/Html.php
30
src/Html.php
|
@ -7,19 +7,33 @@ class Html extends Text{
|
|||
/** @var string */
|
||||
const EXTENTION = '.phtml';
|
||||
|
||||
public function _escape(string $data){
|
||||
return htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
|
||||
public static function _escape(string $data = null){
|
||||
return htmlspecialchars($data ?: '', ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
public function _e(string $data){ return $this->_escape($data); }
|
||||
public static function _e(string $data = null){ return static::_escape($data); }
|
||||
|
||||
public static function filter($data, string $key, string $value){
|
||||
$data = parent::filter($data);
|
||||
if($key == 'escape' && $value == true && is_string($data))
|
||||
return $this->_escape($data);
|
||||
$data = parent::filter($data, $key, $value);
|
||||
switch($key){
|
||||
case 'nl2br':
|
||||
if($value == true && is_string($data))
|
||||
return nl2br($data);
|
||||
break;
|
||||
|
||||
case '2br':
|
||||
if($value == true && is_string($data))
|
||||
return str_replace("<br />\r\n <br />", '<br/>', nl2br($data));
|
||||
break;
|
||||
|
||||
case 'escape':
|
||||
if($value == true && is_string($data))
|
||||
return static::_escape($data);
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function _print(string $key, string $format = null, array $filters = array('type' => 'string', 'escape' => true)): string{
|
||||
public function _print(string $key, string $format = '{?}', array $filters = array('type' => 'string', 'escape' => true)): string{
|
||||
if(!$this->_exist($key))
|
||||
return '';
|
||||
|
||||
|
@ -28,5 +42,5 @@ class Html extends Text{
|
|||
|
||||
return str_replace('{?}', $this->_get($key, $filters), $format);
|
||||
}
|
||||
public function _p(string $key, string $format = null, array $filters = array('type' => 'string', 'escape' => true)){ return $this->_print($key, $format, $filters); }
|
||||
public function _p(string $key, string $format = '{?}', array $filters = array('type' => 'string', 'escape' => true)){ return $this->_print($key, $format, $filters); }
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class Template{
|
|||
$this->path = $this->path($path, $extention, $folder);
|
||||
}
|
||||
|
||||
public function set(string $key, mixed $value): self{
|
||||
public function set(string $key, $value): self{
|
||||
$this->data[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class Template{
|
|||
};
|
||||
$callable($this, $this->path);
|
||||
if(isset($this->layout)){
|
||||
$layout = new self($this->layout, '', false);
|
||||
$layout = new static($this->layout, '', false);
|
||||
$layout->insert($this->extract())->run();
|
||||
}
|
||||
switch($output){
|
||||
|
@ -77,15 +77,15 @@ class Template{
|
|||
}
|
||||
|
||||
public function path(string $path, string $extention = null, bool $folder = true): string{
|
||||
$path .= $extention ?? self::EXTENTION;
|
||||
if($folder == true && class_exists(\Krutush\Path)) //Remove require krutush/krutush
|
||||
$path .= $extention ?? static::EXTENTION;
|
||||
if($folder == true && class_exists('\\Krutush\\Path')) //Remove require krutush/krutush
|
||||
$path = \Krutush\Path::get('template').'/'.$path;
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function _load(string $path, string $extention = null, bool $folder = true): self{
|
||||
$load = new self($path, $extention, $folder);
|
||||
$load = new static($path, $extention, $folder);
|
||||
$load->insert($this->extract())->run();
|
||||
$this->insert($load->extract());
|
||||
return $this;
|
||||
|
@ -157,7 +157,7 @@ class Template{
|
|||
}else{
|
||||
$data = $this->data[$key];
|
||||
foreach($filters as $name => $value){
|
||||
$data = self::filter($data, $name, $value);
|
||||
$data = static::filter($data, $name, $value);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ class Text extends Template{
|
|||
return $data;
|
||||
}
|
||||
|
||||
public function insert(array $data): self{
|
||||
parent::setup();
|
||||
public function insert(array $data): parent{
|
||||
parent::insert($data);
|
||||
$this->contents($data['contents']);
|
||||
return $this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue