123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- /**
- *
- * Cube Framework $Id$ suicBAfwCUlOBFGfhVGUjHWDU1zF1nn+6pBi+ho1ZlA=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2014 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.0
- */
- /**
- * create head title html tag
- */
- namespace Cube\View\Helper;
- class HeadTitle extends AbstractHelper
- {
- /**
- * default separator
- */
- const DEFAULT_SEPARATOR = ' / ';
- /**
- * title operation types
- */
- const SET = 'set';
- const APPEND = 'append';
- const PREPEND = 'prepend';
- /**
- *
- * separator
- *
- * @var string
- */
- protected $_separator = self::DEFAULT_SEPARATOR;
- /**
- *
- * page container container
- *
- * @var array
- */
- protected $_container = array();
- /**
- *
- * head title method
- *
- * @param string $title
- * @param string $type
- *
- * @return $this
- */
- public function headTitle($title = null, $type = null)
- {
- if ($title !== null && !empty($title)) {
- switch ($type) {
- case self::PREPEND:
- $this->prepend($title);
- break;
- case self::SET:
- $this->set($title);
- break;
- default:
- $this->append($title);
- break;
- }
- }
- return $this;
- }
- /**
- *
- * append string to title container
- *
- * @param string $title
- *
- * @return $this
- */
- public function append($title)
- {
- array_push($this->_container, $title);
- return $this;
- }
- /**
- *
- * prepend string to title container
- *
- * @param string $title
- *
- * @return $this
- */
- public function prepend($title)
- {
- array_unshift($this->_container, $title);
- return $this;
- }
- /**
- *
- * set new title
- *
- * @param $title
- *
- * @return $this
- */
- public function set($title)
- {
- $this->clearContainer()
- ->append($title);
- return $this;
- }
- /**
- *
- * clear title container
- *
- * @return $this
- */
- public function clearContainer()
- {
- $this->_container = array();
- return $this;
- }
- /**
- *
- * set title separator
- *
- * @param string $separator
- *
- * @return $this
- */
- public function setSeparator($separator)
- {
- $this->_separator = $separator;
- return $this;
- }
- /**
- *
- * get title separator
- *
- * @return string
- */
- public function getSeparator()
- {
- return $this->_separator;
- }
- /**
- *
- * to string magic method
- *
- * enables <code>echo $this->headTitle(); </code>
- *
- * @return string
- */
- public function __toString()
- {
- return '<title>' . implode($this->_separator, $this->_container) . '</title>';
- }
- }
|