Exemple #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);
 }
Exemple #2
0
 public function setUp()
 {
     $this->fileManager = new LocalFileManager();
     $this->resource = new ResourceManager($this->fileManager);
     // Switch paths to testing environment
     ResourceManager::$excludeFolders = ['*/tests/cache/*'];
     ResourceManager::$projectRoot = __DIR__ . '/';
     ResourceManager::$webRoot = __DIR__ . '/www/';
     ResourceManager::$cacheRoot = __DIR__ . '/cache/';
     // Remove cache folder
     if ($this->fileManager->exists(ResourceManager::$cacheRoot)) {
         $this->fileManager->remove(ResourceManager::$cacheRoot);
     }
     // Create files
     for ($i = 1; $i < 3; $i++) {
         $parent = implode('/', array_fill(0, $i, 'folder'));
         foreach (ResourceManager::TYPES as $type) {
             $file = $parent . '/test' . $i . '.' . $type;
             $this->fileManager->write(__DIR__ . '/' . $file, '/** TEST */');
             $this->files[] = $file;
         }
     }
 }