/**
  * Strategy pattern: Initialize the configuration.
  *
  * Change the script tags that are linked to a file used in the web page
  * according the configuration pararmeters
  *
  * See {@link \Zend_View}
  * See {@link \Zend_View_Helper_HeadScript}
  *
  * @param \Zend_Controller_Request_Abstract $request
  */
 public function init(\Zend_Controller_Request_Abstract $request)
 {
     $this->_headScript = $this->_getView()->headScript();
     foreach ($this->_options as $scriptFileId => $options) {
         if (!isset($options['src'])) {
             require_once 'Exception.php';
             throw new Exception('The definition of a script file element require at least
                         one minimum option parameter:\\"src\\"');
         }
         if (!isset($options['type'])) {
             $type = 'text/javascript';
         } else {
             $type = $options['type'];
         }
         if (isset($options['allowArbitraryAttributes'])) {
             $this->_headScript->setAllowArbitraryAttributes($options['allowArbitraryAttributes']);
         }
         if (!isset($options['attributes'])) {
             $options['attributes'] = array();
         }
         if (!isset($options['placement']) || strcasecmp('APPEND', $options['placement']) == 0) {
             $this->_headScript->appendFile($options['src'], $type, $options['attributes']);
         } else {
             if (strcasecmp('SET', $options['placement']) == 0) {
                 $this->_headScript->setFile($options['src'], $type, $options['attributes']);
             } else {
                 if (strcasecmp('PREPEND', $options['placement']) == 0) {
                     $this->_headScript->prependFile($options['src'], $type, $options['attributes']);
                 } else {
                     $this->_headScript->offsetSetFile(intval($options['placement']), $options['src'], $type, $options['attributes']);
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * @issue ZF-5435
  */
 public function testContainerMaintainsCorrectOrderOfItems()
 {
     $this->helper->offsetSetFile(1, 'test1.js');
     $this->helper->offsetSetFile(20, 'test2.js');
     $this->helper->offsetSetFile(10, 'test3.js');
     $this->helper->offsetSetFile(5, 'test4.js');
     $test = $this->helper->toString();
     $expected = '<script type="text/javascript" src="test1.js"></script>' . PHP_EOL . '<script type="text/javascript" src="test4.js"></script>' . PHP_EOL . '<script type="text/javascript" src="test3.js"></script>' . PHP_EOL . '<script type="text/javascript" src="test2.js"></script>';
     $this->assertEquals($expected, $test);
 }