示例#1
0
 /**
  * {@inheritdoc}
  */
 public function gc($maxlifetime)
 {
     $files = $this->directory->find()->files()->ignoreDotFiles(false)->date("< now - {$maxlifetime} seconds");
     foreach ($files as $file) {
         /** @var $file FileInterface */
         $file->delete();
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function getVersion($path)
 {
     $file = $this->directory->getFile($path);
     try {
         return substr(md5($this->baseSalt . $file->getFullPath() . $file->getTimestamp()), 0, 10);
     } catch (IOException $e) {
         return '';
     }
 }
示例#3
0
文件: Cache.php 项目: bolt/bolt
 /**
  * Helper function for doFlush().
  *
  * @param DirectoryInterface $directory
  */
 private function flushDirectory(DirectoryInterface $directory)
 {
     if (!$directory->exists()) {
         return;
     }
     $files = $directory->find()->ignoreDotFiles()->ignoreVCS();
     /** @var HandlerInterface $file */
     foreach ($files as $file) {
         try {
             $file->delete();
         } catch (IOException $e) {
         }
     }
 }
示例#4
0
 /**
  * Prepends a directory where templates are stored.
  *
  * @param DirectoryInterface $dir
  * @param string             $namespace
  *
  * @throws LoaderError
  */
 public function prependDir(DirectoryInterface $dir, $namespace = self::MAIN_NAMESPACE)
 {
     // invalidate the cache
     $this->cache = $this->errorCache = [];
     if (!$dir->exists()) {
         throw new LoaderError(sprintf('The "%s" directory does not exist.', $dir->getFullPath()));
     }
     if (!$dir->isDir()) {
         throw new LoaderError(sprintf('The path "%s" is not a directory.', $dir->getFullPath()));
     }
     if (!isset($this->paths[$namespace])) {
         $this->paths[$namespace][] = $dir;
     } else {
         array_unshift($this->paths[$namespace], $dir);
     }
 }
示例#5
0
 public static function castDirectory(DirectoryInterface $directory, array $a, Stub $stub, $isNested, $filter = 0)
 {
     $a[Caster::PREFIX_VIRTUAL . 'root'] = $directory->isRoot();
     return $a;
 }
示例#6
0
文件: FileManager.php 项目: bolt/bolt
 /**
  * Process an individual file upload.
  *
  * @param DirectoryInterface $directory
  * @param string             $filename
  * @param array              $fileToProcess
  */
 private function processUpload(DirectoryInterface $directory, $filename, array $fileToProcess)
 {
     $this->app['upload.namespace'] = $directory->getMountPoint();
     $handler = $this->app['upload'];
     $handler->setPrefix($directory->getPath() . '/');
     try {
         $result = $handler->process($fileToProcess);
     } catch (IOException $e) {
         $message = Trans::__('page.file-management.message.upload-not-writable', ['%TARGET%' => $directory->getPath()]);
         $this->flashes()->error($message);
         return;
     }
     if ($result->isValid()) {
         $this->flashes()->info(Trans::__('page.file-management.message.upload-success', ['%file%' => $filename]));
         // Add the file to our stack.
         try {
             $this->app['stack']->add($directory->getFile($filename));
         } catch (FileNotStackableException $e) {
             // Doesn't matter. Just trying to help the user.
         }
         $result->confirm();
     } else {
         foreach ($result->getMessages() as $message) {
             $this->flashes()->error((string) $message);
         }
     }
 }