public function addPath($path)
 {
     $this->scanner->addPath($path = FileUtils::realpath($path));
     $this->pathList[$path] = $path;
     $this->built = false;
     return $this;
 }
 /**
  * @param IConfiguration $configuration
  *
  * @return ICacheStorage
  * @throws FileException
  */
 public static function factory(IConfiguration $configuration)
 {
     if ($configuration->getParameter('cache', !$configuration->isDevelMode()) === false || ($cacheDir = $configuration->getDir('cache', false)) === false) {
         return new MemoryStorage();
     }
     FileUtils::createDir($cacheDir);
     return new FileStorage($cacheDir);
 }
 public function run()
 {
     if (!$this->template->hasResource()) {
         $this->searchLayout();
     }
     $reflectionClass = new \ReflectionClass($this);
     $sourceDir = FileUtils::normalize(dirname($reflectionClass->getFileName()));
     if (file_exists($view = $sourceDir . '/../templates/' . $reflectionClass->getShortName() . '/' . $request->getAction() . '.picco')) {
         $this->template->addResource(new File($view));
     }
     $this->render();
 }
Exemple #4
0
 public function getMimeType()
 {
     return FileUtils::mime($this->file);
 }
Exemple #5
0
 public function __construct($cacheDir = null, $namespace = null)
 {
     FileUtils::createDir($this->cacheDir = sprintf('%s/%s', $cacheDir ?: sys_get_temp_dir() . '/edde', sha1($namespace ?: __DIR__)));
 }
 /**
  * helper method, that treat parameter in "parameters" section as dir and provides aditional checks
  *
  * @param string $name
  * @param bool|true $isDir
  * @param bool|false $writable
  *
  * @return false|string if dir did not passed checks, return false, otherwise dirname
  */
 public function getDir($name, $isDir = true, $writable = false)
 {
     $this->compile();
     if (($dir = $this->parameters->query("\${$name}Dir")) === null) {
         return false;
     }
     $dir = FileUtils::normalize($dir);
     if (($isDir === true || $writable === true) && !is_dir($dir)) {
         return false;
     }
     if ($writable === true && !is_writable($dir)) {
         return false;
     }
     return $dir;
 }
 public function index()
 {
     /**
      * because we can run withou caching, this flag is needed
      */
     if ($this->built === true) {
         return $this;
     }
     /**
      * intentionally first line - built is done even if failature occures
      */
     $this->built = true;
     if ($this->cache->load('index') === true) {
         return $this;
     }
     $exclude = '~(' . implode(')|(', $this->excludeList) . ')~';
     $this->storage->truncate($schema = $this->createScannerFile()->schema());
     $this->storage->createSchema($schema);
     $this->storage->startTransaction(self::class);
     try {
         foreach ($this->pathList as $directory) {
             foreach ($this->createIterator($directory) as $path => $item) {
                 /**
                  * nice line, isn't it ;)?
                  */
                 if (!empty($this->excludeList) && StringUtils::match(($tmp = realpath($path)) ? $path = $tmp : $path, $exclude)) {
                     continue;
                 }
                 $finfo = new \finfo(FILEINFO_MIME);
                 $scannerFile = $this->createScannerFile();
                 $scannerFile->restore(['file' => FileUtils::normalize($item->getRealPath()), 'extension' => ($extension = $item->getExtension()) ? $extension : null, 'mime' => $finfo->file($path), 'size' => (int) $item->getSize(), 'stamp' => DateTimeUtils::create(), 'changed' => DateTimeUtils::from($item->getMTime())]);
                 $this->storage->save($scannerFile);
             }
         }
         $this->storage->commitTransaction(self::class);
         $this->cache->save('index', true);
     } catch (\Exception $e) {
         $this->storage->rollbackTransaction(self::class);
         throw $e;
     }
     return $this;
 }
Exemple #8
0
 /**
  * add given path to search
  *
  * @param string $path
  *
  * @return $this
  */
 public function addPath($path)
 {
     $this->pathList[$path = FileUtils::normalize($path) . '%'] = $path;
     return $this;
 }