Exemple #1
0
 /**
  * Build the scripts.
  * 
  * @return void
  * @access public
  */
 public function build()
 {
     $project = $this->getProject();
     $manifest = $project->getManifestData();
     $script_options = $manifest['scripts'];
     if (isset($script_options['libraries'])) {
         \Curator\Console::stdout(' Minifying libraries…');
         foreach ($script_options['libraries'] as $filename) {
             $path = $project->getScriptsLibsDirPath() . DS . $filename;
             $rel_path = str_replace($project->getProjectDirPath() . DS, '', $path);
             $basename = pathinfo($filename, PATHINFO_FILENAME);
             $raw_size = filesize($path);
             $script_data = file_get_contents($path);
             $handler = HandlerFactory::getHandlerForMediaType('text/javascript');
             $script_data = $handler->input($script_data);
             $hash = hash('sha256', $script_data);
             $out_path = $project->getPublicScriptsLibsDirPath() . DS . $basename . '-' . $hash . '.js';
             $out_rel = str_replace($project->getProjectDirPath() . DS, '', $out_path);
             $out_url = str_replace($project->getPublicHtmlDirPath(), '', $out_path);
             if (!file_exists($out_path)) {
                 touch($out_path);
             }
             if (!file_put_contents($out_path, $script_data)) {
                 throw new \Exception('Could not save script library: ' . $out_path);
             }
             $output_size = filesize($out_path);
             $a = sprintf('%d', 100 * ($output_size / $raw_size));
             \Curator\Console::stdout('  Wrote ' . $out_rel . ' (' . $a . '%)');
             $lib_paths[$basename] = $out_url;
         }
         \Curator\TemplateData::setValue('scripts', 'libs', $lib_paths);
         \Curator\Console::stdout('');
     }
     if (isset($script_options['combine'])) {
         \Curator\Console::stdout(' Minifying scripts…');
         $script_data = null;
         foreach ($script_options['combine'] as $filename) {
             $path = $project->getScriptsDirPath() . DS . $filename;
             $rel_path = str_replace($project->getProjectDirPath() . DS, '', $path);
             $raw_size = filesize($path);
             $script_data = $script_data . NL . NL . NL . file_get_contents($path);
         }
         $handler = \Curator\Handler\Factory::getHandlerForMediaType('text/javascript');
         $script_data = $handler->input($script_data);
         $hash = hash('sha256', $script_data);
         $out_path = $project->getPublicScriptsDirPath() . DS . 'combined-' . $hash . '.js';
         $out_rel = str_replace($project->getProjectDirPath() . DS, '', $out_path);
         $out_url = str_replace($project->getPublicHtmlDirPath(), '', $out_path);
         if (!file_exists($out_path)) {
             touch($out_path);
         }
         if (!file_put_contents($out_path, $script_data)) {
             throw new \Exception('Could not save script file: ' . $out_path);
         }
         $output_size = filesize($out_path);
         $a = sprintf('%d', 100 * ($output_size / $raw_size));
         \Curator\Console::stdout('  Wrote ' . $out_rel . ' (' . $a . '%)');
         \Curator\TemplateData::setValue('scripts', 'combined', $out_url);
     }
 }
 /**
  * Acquire a handler instance
  *
  * @param   string key
  * @return  remote.protocol.ProtocolHandler
  * @throws  remote.protocol.UnknownProtocolException
  */
 public function acquire($key, $initialize = FALSE)
 {
     $url = new URL($key);
     $key = new URL($url->getScheme() . '://' . $url->getHost());
     if ($this->pool->containsKey($key)) {
         $instance = $this->pool->get($key);
     } else {
         sscanf($url->getScheme(), '%[^+]+%s', $type, $option);
         $class = HandlerFactory::handlerFor($type);
         $instance = $this->pool($key, $class->newInstance($option));
     }
     // Add logger
     if (NULL !== ($cat = $url->getParam('log'))) {
         $instance->setTrace(Logger::getInstance()->getCategory($cat));
     }
     // Set timeout, defaults to 60 seconds
     $instance->setTimeout($url->getParam('timeout', 60));
     $initialize && $instance->initialize($url);
     return $instance;
 }
 static function __static()
 {
     HandlerFactory::getInstance()->register('mock', XPClass::forName('net.xp_framework.unittest.remote.MockProtocolHandler'));
 }
Exemple #4
0
 public function testCreateWithValidType()
 {
     $this->_objectManagerMock->expects($this->once())->method('create')->with('\\Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper\\Plugin\\Handler\\Composite')->will($this->returnValue('object'));
     $this->assertEquals('object', $this->_model->create('\\Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper\\Plugin\\Handler\\Composite'));
 }
 static function __static()
 {
     self::$instance = new self();
     self::$instance->register('xp', XPClass::forName('remote.protocol.XpProtocolHandler'));
 }