Example #1
0
 /**
  * Module initialization stage.
  *
  * @see ModuleConnector::init()
  *
  * @param array $params Initialization parameters
  *
  * @return bool True if resource successfully initialized
  */
 public function init(array $params = array())
 {
     // Subscribe to core template rendering event
     Event::subscribe('core.rendered', [$this, 'renderTemplate']);
     Event::subscribe(Compressor::E_CREATE_RESOURCE_LIST, [$this, 'getResources']);
     // Set default dependency as local file manager
     $this->fileManager = $this->fileManager ?: new LocalFileManager();
     $this->resourceManager = new ResourceManager($this->fileManager);
     ResourceManager::$cacheRoot = $this->cache_path;
     ResourceManager::$webRoot = getcwd();
     ResourceManager::$projectRoot = dirname(ResourceManager::$webRoot) . '/';
     // Get loaded modules
     $moduleList = $this->system->getContainer()->getServices('module');
     // Event for modification of resource list
     Event::fire(self::E_MODULES, [&$moduleList]);
     $appResourcePaths = $this->getAssets($moduleList);
     // Get assets
     $this->resources = $this->resourceManager->manage($appResourcePaths);
     // Fire completion event
     Event::fire(self::E_FINISHED, [&$this->resources]);
     // Get asset URLs
     $this->resourceUrls = array_map([$this, 'getAssetCachedUrl'], $this->resources);
     // Continue parent initialization
     return parent::init($params);
 }
Example #2
0
 /**	@see ModuleConnector::init() */
 public function init(array $params = array())
 {
     // Pointer to resourcerouter
     $rr = m('resourcer');
     // If CSS resource has been updated
     if (isset($rr->updated['css'])) {
         try {
             $less = new \lessc();
             // Read updated CSS resource file and compile it
             $css = $less->compile(file_get_contents($rr->updated['css']));
             // Write to the same place
             file_put_contents($rr->updated['css'], $css);
         } catch (Exception $e) {
             e('Ошибка обработки CSS: ' . $e->getMessage());
         }
     }
     // Вызовем родительский метод
     parent::init($params);
 }
Example #3
0
 /**	@see ModuleConnector::init() */
 public function init(array $params = array())
 {
     // Pointer to resourcerouter
     $rr = m('resourcer');
     try {
         if (isset($rr->updated['js'])) {
             // Запишем новое содержание JS
             file_put_contents($rr->updated['js'], JSMin::minify(file_get_contents($rr->updated['js'])));
         }
         if (isset($rr->updated['css'])) {
             // Запишем новое содержание JS
             file_put_contents($rr->updated['css'], CSSMin::process(file_get_contents($rr->updated['css'])));
         }
     } catch (Exception $e) {
         e('Error minifying resource: ' . $e->getMessage());
     }
     // Вызовем родительский метод
     parent::init($params);
 }
 /**	@see ModuleConnector::init() */
 public function init(array $params = array())
 {
     // Pointer to resourcerouter
     $rr = m('resourcer');
     // If we have coffee resource in project
     if (isset($rr->cached['coffee'])) {
         // Change coffee file to js and store it as current js resource
         $newJS = str_replace('.coffee', '.js', str_replace(__SAMSON_PUBLIC_PATH, '', $rr->cached['coffee']));
         // If .coffee resource has been updated
         $file =& $rr->updated['coffee'];
         if (isset($file)) {
             try {
                 // Read coffee file
                 $coffee = file_get_contents($file);
                 // Initialize coffee compiler
                 \CoffeeScript\Init::load();
                 // Read updated .coffee resource file and compile it
                 $js = \CoffeeScript\Compiler::compile($coffee, array('filename' => $file));
                 // Compile coffee script to js and save to the same location
                 file_put_contents($file, $js);
             } catch (Exception $e) {
                 e('Ошибка обработки CoffeeScript: ' . $e->getMessage());
             }
         }
         // If regular JS has been updated or coffee script has been updated
         if (isset($rr->updated['js']) || isset($rr->updated['coffee'])) {
             // Read gathered js
             $oldJS = file_get_contents(str_replace(__SAMSON_PUBLIC_PATH, '', $rr->cached['js']));
             // Read gathered coffee
             $coffee = file_get_contents(str_replace(__SAMSON_PUBLIC_PATH, '', $rr->cached['coffee']));
             // Concatenate regular js and compiled coffee script js to a new javascript file
             file_put_contents($newJS, $oldJS . $coffee);
         }
         // Change old js resource to new one
         //$rr->cached['js'] = $newJS;
     }
     // Call parent method
     parent::init($params);
 }
 /**    @see ModuleConnector::init() */
 public function init(array $params = array())
 {
     parent::init($params);
     // Создадим имя файла содержащего пути к модулям
     $map_file = md5(implode('', array_keys(s()->module_stack))) . '.map';
     // Если такого файла нет
     if ($this->cache_refresh($map_file)) {
         // Fill in routes collection
         foreach ($this->system->module_stack as $id => $module) {
             self::$routes[$id] = $module->path();
         }
         // Save routes to file
         file_put_contents($map_file, serialize(self::$routes));
     }
     $moduleList = $this->system->module_stack;
     Event::fire(self::EVENT_START_GENERATE_RESOURCES, array(&$moduleList));
     //trace(array_keys($moduleList));die;
     $this->generateResources($moduleList);
     //$this->generateResources($this->system->module_stack);
     // Subscribe to core rendered event
     s()->subscribe('core.rendered', array($this, 'renderer'));
 }
Example #6
0
 /**	@see ModuleConnector::init() */
 public function init(array $params = array())
 {
     // Subscribe to core rendered event
     s()->subscribe('core.rendered', array($this, 'renderer'));
     // Вызовем родительский метод
     parent::init($params);
 }
Example #7
0
 /**	@see ModuleConnector::init() */
 public function init(array $params = array())
 {
     parent::init($params);
     // Создадим имя файла содержащего пути к модулям
     $map_file = md5(implode('', array_keys(s()->module_stack))) . '.map';
     // Если такого файла нет
     if ($this->cache_refresh($map_file)) {
         // Fill in routes collection
         foreach (s()->module_stack as $id => $module) {
             self::$routes[$id] = $module->path();
         }
         // Save routes to file
         file_put_contents($map_file, serialize(self::$routes));
     }
     // Cache main web resources
     foreach (array(array('js'), array('css', 'less'), array('coffee')) as $rts) {
         // Get first resource type as extension
         $rt = $rts[0];
         $hash_name = '';
         // Iterate gathered namespaces for their resources
         foreach (s()->load_stack as $ns => &$data) {
             // If necessary resources has been collected
             foreach ($rts as $_rt) {
                 if (isset($data['resources'][$_rt])) {
                     foreach ($data['resources'][$_rt] as &$resource) {
                         // Created string with last resource modification time
                         $hash_name .= filemtime($resource);
                     }
                 }
             }
         }
         // Get hash that's describes resource status
         $hash_name = md5($hash_name) . '.' . $rt;
         $path = $hash_name;
         // Check if cache file has to be updated
         if ($this->cache_refresh($path)) {
             // Read content of resource files
             $content = '';
             foreach (s()->load_module_stack as $id => $data) {
                 $this->c_module =& m($id);
                 // If this ns has resources of specified type
                 foreach ($rts as $_rt) {
                     if (isset($data['resources'][$_rt])) {
                         //TODO: If you will remove & from iterator - system will fail at last element
                         foreach ($data['resources'][$_rt] as &$resource) {
                             // Store current processing resource
                             $this->cResource = $resource;
                             // Read resource file
                             $c = file_get_contents($resource);
                             // Rewrite url in css
                             if ($rt == 'css') {
                                 $c = preg_replace_callback('/url\\s*\\(\\s*(\'|\\")?([^\\)\\s\'\\"]+)(\'|\\")?\\s*\\)/i', array($this, 'src_replace_callback'), $c);
                             }
                             // Gather processed resource text together
                             $content .= "\n\r" . $c;
                         }
                     }
                 }
             }
             // Fix updated resource file with new path to it
             $this->updated[$rt] = $path;
             // Запишем содержание нового "собранного" ресурса
             file_put_contents($path, $content);
         }
         // Save path to resource cache
         $this->cached[$rt] = __SAMSON_CACHE_PATH . $this->id . '/' . $hash_name;
     }
     // Subscribe to core rendered event
     s()->subscribe('core.rendered', array($this, 'renderer'));
     // Register view renderer
     //s()->renderer( array( $this, 'renderer') );
 }