Example #1
0
 /**
  * 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());
 }
Example #2
0
 protected function adapterType()
 {
     if ($this->filesystem instanceof Filesystem) {
         $reflect = new \ReflectionClass($this->filesystem->getAdapter());
         return $reflect->getShortName();
     }
     return 'Unknown';
 }
Example #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 '';
     }
 }
Example #4
0
 /**
  * {@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;
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 /**
  * 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) {
     }
 }
Example #7
0
 /**
  * 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']++;
         }
     }
 }
Example #8
0
 /**
  * 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]));
     }
 }
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
  * 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]));
     }
 }
Example #11
0
 /**
  * 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]));
     }
 }
 /**
  * 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();
         }
     }
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
 {
     $this->prependDir($this->filesystem->getDir($path), $namespace);
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function setVisibility($visibility)
 {
     $this->filesystem->setVisibility($this->path, $visibility);
 }
 /**
  * Actually fetch the listing and return it.
  *
  * @param string $path
  *
  * @return Directory[]|File[]
  */
 protected function doFetch($path)
 {
     return $this->filesystem->listContents($path);
 }
Example #16
0
 protected function createFiles(array $paths)
 {
     foreach ($paths as $path) {
         $this->filesystem->put($path, '');
     }
 }
Example #17
0
 /**
  * @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);
 }
Example #18
0
 /**
  * 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;
 }
Example #19
0
 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();
 }
Example #20
0
 /**
  * {@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;
 }