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();
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 /**
  * add given path to search
  *
  * @param string $path
  *
  * @return $this
  */
 public function addPath($path)
 {
     $this->pathList[$path = FileUtils::normalize($path) . '%'] = $path;
     return $this;
 }