Esempio n. 1
0
 /**
  * Recursively replace import in content of the LESS file
  *
  * @param string $resource Resource full path
  * @param string $content  less file content
  *
  * @return string Content of LESS file with included imported resources
  * @throws ResourceNotFound If importing resource could not be found
  */
 protected function readImport($resource, $content)
 {
     // Rewrite imports
     $matches = [];
     if (preg_match_all(self::P_IMPORT_DECLARATION, $content, $matches)) {
         for ($i = 0, $size = count($matches[0]); $i < $size; $i++) {
             // Build absolute path to imported resource
             $path = dirname($resource) . DIRECTORY_SEPARATOR . $matches['path'][$i];
             // Append .less extension according to standard
             if (false === ($path = realpath($this->fileManager->exists($path) ? $path : $path . '.less'))) {
                 throw new ResourceNotFound('Cannot import file: ' . $matches['path'][$i]);
             }
             // Add parent to child dependency
             $this->dependencies[$path][$resource] = [];
             // Replace path in LESS @import command with recursive call to this function
             $content = str_replace($matches[0][$i], $this->readImport($path, $this->fileManager->read($path)), $content);
         }
     }
     return $content;
 }
Esempio n. 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;
         }
     }
 }
Esempio n. 3
0
 /**
  * Define if asset is not valid.
  *
  * @param string $asset       Full path to asset
  *
  * @param string $cachedAsset Full path to cached asset
  *
  * @return bool True if cached asset is valid
  */
 protected function isValid($asset, $cachedAsset)
 {
     // If cached asset does not exists or is invalid
     return $this->fileManager->exists($cachedAsset) !== false && $this->fileManager->lastModified($cachedAsset) === $this->fileManager->lastModified($asset);
 }