コード例 #1
0
ファイル: Matcher.php プロジェクト: bolt/bolt
 /**
  * Same as {@see getFile} for images.
  *
  * @param ImageInterface|string $path
  *
  * @throws FileNotFoundException If file was not found.
  *
  * @return ImageInterface
  */
 public function getImage($path)
 {
     if ($path instanceof ImageInterface) {
         return $path;
     }
     $file = $this->getFile($path);
     return $this->filesystem->getImage($file->getFullPath());
 }
コード例 #2
0
ファイル: AdapterPlugin.php プロジェクト: gandalf3/bolt
 protected function adapterType()
 {
     if ($this->filesystem instanceof Filesystem) {
         $reflect = new \ReflectionClass($this->filesystem->getAdapter());
         return $reflect->getShortName();
     }
     return 'Unknown';
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getVersion($path)
 {
     $file = $this->filesystem->getFile($path);
     try {
         return substr(md5($this->baseSalt . $file->getFullPath() . $file->getTimestamp()), 0, 10);
     } catch (IOException $e) {
         return '';
     }
 }
コード例 #4
0
ファイル: UploadContainer.php プロジェクト: atiarda/bolt
 /**
  * {@inheritdoc}
  *
  * This is called from \Sirius\Upload\Handler::processSingleFile() which expects a boolean return value,
  * and as \Bolt\FilesystemInterface::putStream only returns void or throws an error, we catch
  * IOExceptions here and return a false on exception.
  */
 public function moveUploadedFile($localFile, $destination)
 {
     try {
         $this->filesystem->putStream($destination, fopen($localFile, 'r+'));
     } catch (IOException $e) {
         return false;
     }
     return true;
 }
コード例 #5
0
ファイル: GlobIterator.php プロジェクト: pkdevboxy/filesystem
 /**
  * Constructor.
  *
  * @param FilesystemInterface $filesystem The filesystem to search
  * @param string              $glob       The glob pattern
  * @param int                 $flags      A bitwise combination of the flag constants in {@see Glob}
  */
 public function __construct(FilesystemInterface $filesystem, $glob, $flags = 0)
 {
     // Glob code requires absolute paths, so prefix path
     // with leading slash, but not before mount point
     if (strpos($glob, '://') > 0) {
         $glob = str_replace('://', ':///', $glob);
     } else {
         $glob = '/' . ltrim($glob, '/');
     }
     if (!Glob::isDynamic($glob)) {
         // If the glob is a file path, return that path.
         $innerIterator = new \ArrayIterator([$glob => $filesystem->get($glob)]);
     } else {
         $basePath = Glob::getBasePath($glob);
         $innerIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filesystem, $basePath, RecursiveDirectoryIterator::KEY_FOR_GLOB), RecursiveIteratorIterator::SELF_FIRST);
     }
     parent::__construct($glob, $innerIterator, static::FILTER_KEY, $flags);
 }
コード例 #6
0
ファイル: Responder.php プロジェクト: pkdevboxy/bolt-thumbs
 /**
  * Saves a static copy of the thumbnail to the web folder.
  *
  * @param string $requestPath
  * @param string $imageContent
  */
 protected function saveStaticThumbnail($requestPath, $imageContent)
 {
     if ($this->webFs === null || $requestPath === null) {
         return;
     }
     try {
         $this->webFs->write($requestPath, $imageContent);
     } catch (Exception $e) {
     }
 }
コード例 #7
0
ファイル: Cache.php プロジェクト: MenZil-Team/bolt
 /**
  * Helper function for doFlush().
  *
  * @param FilesystemInterface $filesystem
  * @param array               $result
  */
 private function flushFilesystemCache(FilesystemInterface $filesystem, &$result)
 {
     $files = $filesystem->find()->files()->notName('index.html')->ignoreDotFiles()->ignoreVCS();
     /** @var HandlerInterface $file */
     foreach ($files as $file) {
         try {
             $file->delete();
             $result['successfiles']++;
         } catch (IOException $e) {
             $result['failedfiles']++;
             $result['failed'][] = $file->getPath();
         }
     }
     $dirs = $filesystem->find()->directories()->depth('< 1');
     /** @var HandlerInterface $dir */
     foreach ($dirs as $dir) {
         try {
             $dir->delete();
             $result['successfolders']++;
         } catch (IOException $e) {
             $result['failedfolders']++;
         }
     }
 }
コード例 #8
0
ファイル: Manager.php プロジェクト: bolt/bolt
 /**
  * Load a single extension.
  *
  * @param PackageDescriptor $descriptor
  */
 private function addManagedExtension(PackageDescriptor $descriptor)
 {
     $className = $descriptor->getClass();
     if ($this->isClassLoadable($className) === false) {
         $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         return;
     }
     /** @var ExtensionInterface $extension */
     $extension = new $className();
     if ($extension instanceof ExtensionInterface) {
         $baseDir = $this->extFs->getDir($descriptor->getPath());
         $webDir = $this->webFs->getDir($descriptor->getWebPath());
         $this->add($extension, $baseDir, $webDir, $descriptor->getName())->setDescriptor($descriptor);
     } else {
         $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
     }
 }
コード例 #9
0
ファイル: Finder.php プロジェクト: pkdevboxy/filesystem
 /**
  * Appends an existing set of files/directories to the finder.
  *
  * The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
  *
  * @param mixed $iterator
  *
  * @throws InvalidArgumentException When the given argument is not iterable.
  *
  * @return Finder The finder
  */
 public function append($iterator)
 {
     if ($iterator instanceof \IteratorAggregate) {
         $this->iterators[] = $iterator->getIterator();
     } elseif ($iterator instanceof \Iterator) {
         $this->iterators[] = $iterator;
     } elseif ($iterator instanceof \Traversable || is_array($iterator)) {
         $it = new \ArrayIterator();
         foreach ($iterator as $file) {
             $it->append($file instanceof Flysystem\Handler ? $file : $this->filesystem->get($file));
         }
         $this->iterators[] = $it;
     } else {
         throw new InvalidArgumentException('Finder::append() method wrong argument type.');
     }
     return $this;
 }
コード例 #10
0
ファイル: Manager.php プロジェクト: johndotcat/bolt
 /**
  * Load a single extension.
  *
  * @param PackageDescriptor $descriptor
  */
 private function addManagedExtension(PackageDescriptor $descriptor)
 {
     $className = $descriptor->getClass();
     if (class_exists($className) === false) {
         if ($descriptor->getType() === 'local' && class_exists('Wikimedia\\Composer\\MergePlugin') === false) {
             $this->flashLogger->error(Trans::__("Local extension set up incomplete. Please run 'Install all packages' on the Extensions page.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         } else {
             $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         }
         return;
     }
     /** @var ExtensionInterface $extension */
     $extension = new $className();
     if ($extension instanceof ExtensionInterface) {
         $baseDir = $this->filesystem->getDir($descriptor->getPath());
         $relativeUrl = sprintf('/extensions/%s/web/', $descriptor->getPath());
         $this->add($extension, $baseDir, $relativeUrl, $descriptor->getName())->setDescriptor($descriptor);
     } else {
         $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
     }
 }
コード例 #11
0
ファイル: Manager.php プロジェクト: gandalf3/bolt
 /**
  * Load a single extension.
  *
  * @param PackageDescriptor $descriptor
  */
 private function addManagedExtension(PackageDescriptor $descriptor)
 {
     $className = $descriptor->getClass();
     if ($this->isClassLoadable($className) === false) {
         if ($descriptor->getType() === 'local' && $this->isClassLoadable('Wikimedia\\Composer\\MergePlugin') === false) {
             $this->flashLogger->error(Trans::__('general.phrase.error-local-extension-set-up-incomplete', ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         } else {
             $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         }
         return;
     }
     /** @var ExtensionInterface $extension */
     $extension = new $className();
     if ($extension instanceof ExtensionInterface) {
         $baseDir = $this->extFs->getDir($descriptor->getPath());
         $webDir = $this->webFs->getDir($descriptor->getWebPath());
         $this->add($extension, $baseDir, $webDir, $descriptor->getName())->setDescriptor($descriptor);
     } else {
         $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
     }
 }
コード例 #12
0
 /**
  * Delete active session files for a user.
  *
  * @param Entity\Users $user
  */
 private function deleteSessions(Entity\Users $user)
 {
     $savePath = $this->sessionStorage->getOptions()->get('save_path');
     try {
         $sessionFiles = $this->filesystem->find()->files()->in($savePath);
     } catch (FileNotFoundException $e) {
         return;
     }
     /** @var \Bolt\Filesystem\Handler\File $sessionFile */
     foreach ($sessionFiles as $sessionFile) {
         $data = unserialize($sessionFile->read());
         if (!isset($data['_sf2_attributes']['authentication'])) {
             continue;
         }
         if (!$data['_sf2_attributes']['authentication'] instanceof \Bolt\AccessControl\Token\Token) {
             continue;
         }
         /** @var \Bolt\AccessControl\Token\Token $token */
         $token = $data['_sf2_attributes']['authentication'];
         if ($token->getUser()->getId() === $user->getId()) {
             $sessionFile->delete();
         }
     }
 }
コード例 #13
0
ファイル: FilesystemLoader.php プロジェクト: bolt/bolt
 /**
  * {@inheritdoc}
  */
 public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
 {
     $this->prependDir($this->filesystem->getDir($path), $namespace);
 }
コード例 #14
0
ファイル: BaseHandler.php プロジェクト: bolt/filesystem
 /**
  * {@inheritdoc}
  */
 public function setVisibility($visibility)
 {
     $this->filesystem->setVisibility($this->path, $visibility);
 }
コード例 #15
0
 /**
  * Actually fetch the listing and return it.
  *
  * @param string $path
  *
  * @return Directory[]|File[]
  */
 protected function doFetch($path)
 {
     return $this->filesystem->listContents($path);
 }
コード例 #16
0
ファイル: StackTest.php プロジェクト: bolt/bolt
 protected function createFiles(array $paths)
 {
     foreach ($paths as $path) {
         $this->filesystem->put($path, '');
     }
 }
コード例 #17
0
ファイル: Config.php プロジェクト: nbehier/bolt
 /**
  * @internal Do not use
  *
  * @param FilesystemInterface $cacheFs
  * @param string              $environment
  * @param bool                $force
  */
 public function cacheConfig(FilesystemInterface $cacheFs, $environment, $force = false)
 {
     $cacheFileName = $environment . '/config-cache.json';
     if ($cacheFs->has($cacheFileName) && $force === false) {
         return;
     }
     $cacheFile = new JsonFile($cacheFs, $cacheFileName);
     $cacheFile->dump($this->data);
 }
コード例 #18
0
ファイル: FileManager.php プロジェクト: robbert-vdh/bolt
 /**
  * Gather the 'similar' files, if present.
  *
  * i.e., if we're editing config.yml, we also want to check for
  * config.yml.dist and config_local.yml
  *
  * @param FilesystemInterface $filesystem
  * @param File                $file
  *
  * @return array
  */
 private function getFileGroup(FilesystemInterface $filesystem, File $file)
 {
     $basename = str_replace('.yml', '', str_replace('_local', '', $file->getPath()));
     $filegroup = [];
     if ($filesystem->has($basename . '.yml')) {
         $filegroup[] = basename($basename . '.yml');
     }
     if ($filesystem->has($basename . '_local.yml')) {
         $filegroup[] = basename($basename . '_local.yml');
     }
     return $filegroup;
 }
コード例 #19
0
ファイル: Manager.php プロジェクト: bolt/filesystem
 private function doCopy(FilesystemInterface $fsOrigin, FilesystemInterface $fsTarget, $origin, $target, $override)
 {
     if ($fsTarget->has($target) && ($override === false || $override === null && $fsOrigin->getTimestamp($origin) <= $fsTarget->getTimestamp($target))) {
         return;
     }
     $buffer = $fsOrigin->readStream($origin);
     $fsTarget->putStream($target, $buffer);
     $buffer->close();
 }
コード例 #20
0
ファイル: UploadContainer.php プロジェクト: bolt/bolt
 /**
  * {@inheritdoc}
  *
  * @throws IOException
  *
  * This is called from \Sirius\Upload\Handler::processSingleFile() which expects a boolean return value,
  * and as \Bolt\FilesystemInterface::putStream only returns void or throws an error, we catch
  * IOExceptions here and return a false on exception.
  */
 public function moveUploadedFile($localFile, $destination)
 {
     $this->filesystem->putStream($destination, fopen($localFile, 'r+'));
     return true;
 }