Exemplo n.º 1
0
 /**
  * @param	string	$src	file path or url to script
  * @param	mixed	$data	$content
  * @param	string	$sep	content separator
  * @param	string	$type	mime type
  * @return	ScriptTag
  */
 public function __construct($src = null, $data = null, $sep = null, $type = null)
 {
     $content = null;
     if (null !== $src && null !== $data) {
         $err = 'It is a runtime error to set both script source and ';
         $err .= 'content';
         throw new RunTimeException($err);
     }
     $attrs = new TagAttributes(array('async', 'charset', 'defer', 'src', 'type'));
     if (null === $type || !is_string($type)) {
         $type = 'text/javascript';
     }
     $attrs->add('type', $type);
     /* 
      * when a source is available there is no need for content
      */
     if (null !== $src && is_string($src) && ($src = trim($src))) {
         $attrs->add('src', $src);
     } else {
         /* default content separator for script */
         if (null === $sep) {
             $sep = PHP_EOL;
         }
         $content = new TagContent($data, $sep);
     }
     parent::__construct('script', $content, $attrs);
     $this->disableRenderWhenEmpty();
 }
Exemplo n.º 2
0
 /**
  * @param	string	$data	content for the title
  * @return	Title
  */
 public function __construct($sep = null)
 {
     if (null === $sep) {
         $sep = PHP_EOL;
     }
     parent::__construct('head');
     $this->setContentSeparator($sep)->setTitle(new TitleTag());
 }
Exemplo n.º 3
0
 /**
  * Only has two valid attributes href and target
  *
  * @return	base
  */
 public function __construct($data = null, $sep = null)
 {
     if (null === $sep) {
         $sep = PHP_EOL;
     }
     $content = new TagContent($data, $sep);
     $attrs = new TagAttributes(array('onafterprint', 'onbeforeprint', 'onbeforeunload', 'onblur', 'onerror', 'onfocus', 'onhashchange', 'onload', 'onmessage', 'onoffline', 'ononline', 'onpagehide', 'onpageshow', 'onpopstate', 'onresize', 'onscroll', 'onstorage', 'onunload'));
     parent::__construct('body', $content, $attrs);
 }
Exemplo n.º 4
0
 /**
  * Only has two valid attributes href and target
  *
  * @return	base
  */
 public function __construct(HeadTagInterface $head = null, GenericTagInterface $body = null)
 {
     $content = $this->createTagContent(null, PHP_EOL);
     $attrs = $this->createTagAttributes(array('manifest'));
     parent::__construct('html', $content, $attrs);
     if (null === $head) {
         $head = new HeadTag();
     }
     $this->setHead($head);
     if (null === $body) {
         $body = new BodyTag();
     }
     $this->setBody($body);
 }
Exemplo n.º 5
0
 /**
  * Only has two valid attributes href and target
  *
  * @return	base
  */
 public function __construct($href = null, $target = null)
 {
     parent::__construct('base');
     $this->disableClosingTag();
     $attrs = $this->getTagAttributes();
     $attrs->loadWhiteList(array('href', 'target'));
     if (null === $href && null === $target) {
         $err = 'both params href and target can not be empty';
         throw new RunTimeException($err);
     }
     if (is_string($href) && !empty($href)) {
         $attrs->add('href', $href);
     }
     if (is_string($target) && !empty($target)) {
         $attrs->add('target', $target);
     }
 }