/**
     * Overload method access
     *
     * Allows the following method calls:
     * - appendFile($src, $type = 'text/javascript', $attrs = array())
     * - offsetSetFile($index, $src, $type = 'text/javascript', $attrs = array())
     * - prependFile($src, $type = 'text/javascript', $attrs = array())
     * - setFile($src, $type = 'text/javascript', $attrs = array())
     * - appendScript($script, $type = 'text/javascript', $attrs = array())
     * - offsetSetScript($index, $src, $type = 'text/javascript', $attrs = array())
     * - prependScript($script, $type = 'text/javascript', $attrs = array())
     * - setScript($script, $type = 'text/javascript', $attrs = array())
     *
     * @param  string $method Method to call
     * @param  array  $args   Arguments of method
     * @throws Exception\BadMethodCallException if too few arguments or invalid method
     * @return HeadScript
     */
    public function __call($method, $args)
    {
        if (preg_match('/^(?P<action>set|(ap|pre)pend|offsetSet)(?P<mode>File|Script)$/', $method, $matches)) {
            if (1 > count($args)) {
                throw new Exception\BadMethodCallException(sprintf(
                    'Method "%s" requires at least one argument',
                    $method
                ));
            }

            $action  = $matches['action'];
            $mode    = strtolower($matches['mode']);
            $type    = 'text/javascript';
            $attrs   = array();

            if ('offsetSet' == $action) {
                $index = array_shift($args);
                if (1 > count($args)) {
                    throw new Exception\BadMethodCallException(sprintf(
                        'Method "%s" requires at least two arguments, an index and source',
                        $method
                    ));
                }
            }

            $content = $args[0];

            if (isset($args[1])) {
                $type = (string) $args[1];
            }
            if (isset($args[2])) {
                $attrs = (array) $args[2];
            }

            switch ($mode) {
                case 'script':
                    $item = $this->createData($type, $attrs, $content);
                    if ('offsetSet' == $action) {
                        $this->offsetSet($index, $item);
                    } else {
                        $this->$action($item);
                    }
                    break;
                case 'file':
                default:
                    if (!$this->isDuplicate($content)) {
                        $attrs['src'] = $content;
                        $item = $this->createData($type, $attrs);
                        if ('offsetSet' == $action) {
                            $this->offsetSet($index, $item);
                        } else {
                            $this->$action($item);
                        }
                    }
                    break;
            }

            return $this;
        }

        return parent::__call($method, $args);
    }
Ejemplo n.º 2
0
 /**
  * Overload method calls
  *
  * @param  string $method
  * @param  array  $args
  * @throws Exception\BadMethodCallException When no $content provided or invalid method
  * @return void
  */
 public function __call($method, $args)
 {
     if (preg_match('/^(?P<action>set|(ap|pre)pend|offsetSet)(Style)$/', $method, $matches)) {
         $index = null;
         $argc = count($args);
         $action = $matches['action'];
         if ('offsetSet' == $action) {
             if (0 < $argc) {
                 $index = array_shift($args);
                 --$argc;
             }
         }
         if (1 > $argc) {
             throw new Exception\BadMethodCallException(sprintf('Method "%s" requires minimally content for the stylesheet', $method));
         }
         $content = $args[0];
         $attrs = array();
         if (isset($args[1])) {
             $attrs = (array) $args[1];
         }
         $item = $this->createData($content, $attrs);
         if ('offsetSet' == $action) {
             $this->offsetSet($index, $item);
         } else {
             $this->{$action}($item);
         }
         return $this;
     }
     return parent::__call($method, $args);
 }
Ejemplo n.º 3
0
 /**
  * Overload method access
  *
  * @param  string $method
  * @param  array  $args
  * @throws Exception\BadMethodCallException
  * @return HeadMeta
  */
 public function __call($method, $args)
 {
     if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property|Itemprop)$/', $method, $matches)) {
         $action = $matches['action'];
         $type = $this->normalizeType($matches['type']);
         $argc = count($args);
         $index = null;
         if ('offsetSet' == $action) {
             if (0 < $argc) {
                 $index = array_shift($args);
                 --$argc;
             }
         }
         if (2 > $argc) {
             throw new Exception\BadMethodCallException('Too few arguments provided; requires key value, and content');
         }
         if (3 > $argc) {
             $args[] = array();
         }
         $item = $this->createData($type, $args[0], $args[1], $args[2]);
         if ('offsetSet' == $action) {
             return $this->offsetSet($index, $item);
         }
         $this->{$action}($item);
         return $this;
     }
     return parent::__call($method, $args);
 }
Ejemplo n.º 4
0
 /**
  * Overload method access
  *
  * Creates the following virtual methods:
  * - appendStylesheet($href, $media, $conditionalStylesheet, $extras)
  * - offsetSetStylesheet($index, $href, $media, $conditionalStylesheet, $extras)
  * - prependStylesheet($href, $media, $conditionalStylesheet, $extras)
  * - setStylesheet($href, $media, $conditionalStylesheet, $extras)
  * - appendAlternate($href, $type, $title, $extras)
  * - offsetSetAlternate($index, $href, $type, $title, $extras)
  * - prependAlternate($href, $type, $title, $extras)
  * - setAlternate($href, $type, $title, $extras)
  *
  * Items that may be added in the future:
  * - Navigation?  need to find docs on this
  *   - public function appendStart()
  *   - public function appendContents()
  *   - public function appendPrev()
  *   - public function appendNext()
  *   - public function appendIndex()
  *   - public function appendEnd()
  *   - public function appendGlossary()
  *   - public function appendAppendix()
  *   - public function appendHelp()
  *   - public function appendBookmark()
  * - Other?
  *   - public function appendCopyright()
  *   - public function appendChapter()
  *   - public function appendSection()
  *   - public function appendSubsection()
  *
  * @param mixed $method
  * @param mixed $args
  * @return void
  * @throws Exception\BadMethodCallException
  */
 public function __call($method, $args)
 {
     if (preg_match('/^(?P<action>set|(ap|pre)pend|offsetSet)(?P<type>Stylesheet|Alternate)$/', $method, $matches)) {
         $argc = count($args);
         $action = $matches['action'];
         $type = $matches['type'];
         $index = null;
         if ('offsetSet' == $action) {
             if (0 < $argc) {
                 $index = array_shift($args);
                 --$argc;
             }
         }
         if (1 > $argc) {
             throw new Exception\BadMethodCallException(sprintf('%s requires at least one argument', $method));
         }
         if (is_array($args[0])) {
             $item = $this->createData($args[0]);
         } else {
             $dataMethod = 'createData' . $type;
             $item = $this->{$dataMethod}($args);
         }
         if ($item) {
             if ('offsetSet' == $action) {
                 $this->offsetSet($index, $item);
             } else {
                 $this->{$action}($item);
             }
         }
         return $this;
     }
     return parent::__call($method, $args);
 }
Ejemplo n.º 5
0
 /**
  *
  */
 public function __construct()
 {
     parent::__construct();
     $this->environment = getenv('APPLICATION_ENV') ?: 'production';
     $this->setSeparator(PHP_EOL);
 }
Ejemplo n.º 6
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->setSeparator(PHP_EOL);
 }