This repository has been archived by the owner on Jul 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* @author: Patsura Dmitry @ovr <talk@dmtry.me> | ||
*/ | ||
|
||
namespace Phalcony; | ||
|
||
/** | ||
* Class HeadMeta | ||
* @package Phalcony | ||
*/ | ||
class HeadMeta | ||
{ | ||
/** | ||
* Types of attributes | ||
* @var array | ||
*/ | ||
protected $_typeKeys = array('name', 'http-equiv', 'charset', 'property'); | ||
protected $_requiredKeys = array('content'); | ||
protected $_modifierKeys = array('lang', 'scheme'); | ||
|
||
protected $_register = []; | ||
|
||
/** | ||
* @param null $content | ||
* @param null $keyValue | ||
* @param string $keyType | ||
*/ | ||
public function append($content = null, $keyValue = null, $keyType = 'name') | ||
{ | ||
$this->_register[] = [ | ||
strtolower($keyType) => $keyValue, | ||
'content' => $content | ||
]; | ||
} | ||
|
||
/** | ||
* @param null $content | ||
* @param null $keyValue | ||
* @param string $keyType | ||
*/ | ||
public function prepend($content = null, $keyValue = null, $keyType = 'name') | ||
{ | ||
/** | ||
* @todo Сделать | ||
*/ | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @param $content | ||
*/ | ||
public function appendName($name, $content) | ||
{ | ||
$this->_register[] = [ | ||
'name' => $name, | ||
'content' => $content | ||
]; | ||
} | ||
|
||
protected function _normalizeType($type) | ||
{ | ||
switch ($type) { | ||
case 'Name': | ||
case 'name': | ||
return 'name'; | ||
case 'HttpEquiv': | ||
return 'http-equiv'; | ||
case 'Property': | ||
return 'property'; | ||
default: | ||
exit(); | ||
} | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$html = ''; | ||
|
||
if (count($this->_register) == 0) { | ||
return $html; | ||
} | ||
|
||
foreach ($this->_register as $tag) { | ||
$html .= "\t" . \Phalcon\Tag::tagHtml('meta', $tag) . "\n"; | ||
} | ||
|
||
return $html; | ||
} | ||
} |