/** * {@inheritdoc} */ public function find($path) { if ($this->filesystem->has($path) === false) { throw new NotLoadableException(sprintf('Source image "%s" not found.', $path)); } $mimeType = $this->filesystem->getMimetype($path); return new Binary($this->filesystem->read($path), $mimeType, $this->extensionGuesser->guess($mimeType)); }
public function getContents($spiBinaryFileId) { try { return $this->filesystem->read($spiBinaryFileId); } catch (FlysystemNotFoundException $e) { throw new BinaryFileNotFoundException($spiBinaryFileId, $e); } }
/** * {@inheritdoc} */ public function fromFile($file) : Workout { $content = $this->filesystem->read($file); if ($content === false) { throw new UnreadableFileException(); } return $this->fromString($content); }
/** * {@inheritdoc} */ public function read($path) { try { return $this->filesystem->read($path); } catch (FileNotFoundException $exception) { return false; } }
/** * Get the contents of a file. * * @param string $path * @return string * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function get($path) { try { return $this->driver->read($path); } catch (FileNotFoundException $e) { throw new ContractFileNotFoundException($path, $e->getCode(), $e); } }
/** * Get an item from the storage. * * @param string $key * * @return string|null */ public function get($key) { try { if ($data = $this->flysystem->read($key)) { return $data; } } catch (FileNotFoundException $e) { // } }
/** * @param ServerRequestInterface $request * * @return mixed|null */ public function data(ServerRequestInterface $request) { $url = $request->getUri()->getPath(); $parameters = array_merge($request->getQueryParams(), $request->getParsedBody()); $file = $this->file($url, $parameters); if (!$this->filesystem->has($file)) { $file = $this->defaultFile($url); } if (!$this->filesystem->has($file)) { return null; } return $this->filesystem->read($file); }
/** * {@inheritDoc} */ public function load($path) { try { $contents = $this->filesystem->read($path); } catch (FileNotFoundException $e) { throw new Exception\ImageNotFoundException(sprintf('Source image not found in "%s"', $path)); } $mimeType = $this->filesystem->getMimeType($path); if ($mimeType === false) { // Mime Type could not be detected return $contents; } return new Binary($contents, $mimeType); }
/** * Generate manipulated image. * @param string $path Image path. * @param array $params Image manipulation params. * @return string Cache path. * @throws FileNotFoundException * @throws FilesystemException */ public function makeImage($path, array $params) { $sourcePath = $this->getSourcePath($path); $cachedPath = $this->getCachePath($path, $params); if ($this->cacheFileExists($path, $params) === true) { return $cachedPath; } if ($this->sourceFileExists($path) === false) { throw new FileNotFoundException('Could not find the image `' . $sourcePath . '`.'); } $source = $this->source->read($sourcePath); if ($source === false) { throw new FilesystemException('Could not read the image `' . $sourcePath . '`.'); } // We need to write the image to the local disk before // doing any manipulations. This is because EXIF data // can only be read from an actual file. $tmp = tempnam(sys_get_temp_dir(), 'Glide'); if (file_put_contents($tmp, $source) === false) { throw new FilesystemException('Unable to write temp file for `' . $sourcePath . '`.'); } try { $write = $this->cache->write($cachedPath, $this->api->run($tmp, $this->getAllParams($params))); if ($write === false) { throw new FilesystemException('Could not write the image `' . $cachedPath . '`.'); } } catch (FileExistsException $exception) { // This edge case occurs when the target already exists // because it's currently be written to disk in another // request. It's best to just fail silently. } unlink($tmp); return $cachedPath; }
/** * Read session data * @link http://php.net/manual/en/sessionhandlerinterface.read.php * @param string $session_id The session id to read data for. * @return string <p> * Returns an encoded string of the read data. * If nothing was read, it must return an empty string. * Note this value is returned internally to PHP for processing. * </p> * @since 5.4.0 */ public function read($session_id) { if ($this->driver->has($path = $this->path . $session_id)) { return $this->driver->read($path); } return ''; }
/** * Read a file. * * @param string $path * @return string * @throws IoReadException */ public function read($path) { if (($ret = $this->fs->read($path)) === false) { throw new IoReadException("File {$path} could not be read."); } return $ret; }
/** * Reads settings content of a namespace * * @param string $namespace * @return array */ protected function read($namespace) { $file = $this->adapter->getFileName($namespace); if (!$this->fileSystem->has($file)) { return []; } return $this->adapter->onRead($this->fileSystem->read($file)); }
/** * Read stub file * * @param string $content * @param array $arguments * @return mixed */ protected function read($stub_path) { $content = $this->stubbox->read($stub_path); if ($content === false) { throw new InvalidArgumentException("File '{$stub_path}' is not found."); } return $content; }
/** * @param ReflectionClass $reflection * @param FilesystemInterface $filesystem * @param null $name */ public function __construct(ReflectionClass $reflection, FilesystemInterface $filesystem, $name = null) { $this->reflection = $reflection; $this->template = $filesystem->read("/Console/stubs/method.stub"); $this->name = $name; $this->classParameters = $this->getClassParameters(); $this->uses = $this->getUsages(); $this->methodParameterNames = $this->getMethodParameters(); $this->requestParameters = $this->getRequestParameters(); }
/** * Extracts user defined PHP Type's from a source php file. * * @param string $package * @param string $version * @param string $file * @return array */ private function getTypes($package, $version, $file) { $fullPath = $this->vendorDir . '/' . $package . '/' . $version . '/' . $file; $src = $this->filesystem->read($fullPath); $ast = $this->parser->parse($src); $this->traverser->addVisitor($this->typeExtracator); $this->traverser->traverse($ast); $this->traverser->removeVisitor($this->typeExtracator); return $this->typeExtracator->getTypes(); }
/** * Copies a file to a temporary path and returns that path. * * @param string $fileIdentifier * @return string The temporary path * @throws \RuntimeException */ protected function copyFileToTemporaryPath($fileIdentifier) { $temporaryPath = $this->getTemporaryPathForFile($fileIdentifier); $contents = $this->filesystem->read(ltrim($fileIdentifier, '/')); $res = fopen($temporaryPath, 'w'); $result = fwrite($res, $contents); fclose($res); if (false === $result) { throw new \RuntimeException('Copying file "' . $fileIdentifier . '" to temporary path "' . $temporaryPath . '" failed.', 1320577649); } return $temporaryPath; }
/** @inheritdoc */ public function renameConflicts(array $conflicts) { $replacements = []; $this->traverser->addVisitor($this->reNamer); foreach ($conflicts as $package => $types) { foreach ($types as $type => $versions) { foreach ($versions as $version => $files) { $composer = $this->reader->setPackage($package)->setVersion($version)->getComposerObject(); if ($this->hasNs($type)) { $split = $this->splitNsandClass($type); $fromNs = $split['ns']; $psrNs = $this->getPsrNs($composer, $fromNs); $toNs = $psrNs . $this->sanitizeVersionNo($version); $diff = str_replace($psrNs, '', $fromNs); if ($psrNs != $diff . '\\') { $toNs = $toNs . '\\' . $diff; } $newFullyQualifiedType = $toNs . '\\' . $split['class']; } else { $fromNs = $type; $toNs = $type . '_' . $this->sanitizeVersionNo($version); $newFullyQualifiedType = $toNs; } $this->reNamer->rename($fromNs, $toNs); $replacements[] = ['package' => $package, 'version' => $version, 'originalFullyQualifiedType' => $type, 'originalNamespace' => $fromNs, 'newFullyQualifiedType' => $newFullyQualifiedType, 'newNamespace' => $toNs, 'replacedIn' => $files]; foreach ($files as $file) { $fullPath = $this->vendorDir . '/' . $package . '/' . $version . '/' . $file; $src = $this->filesystem->read($fullPath); $ast = $this->parser->parse($src); $newAst = $this->traverser->traverse($ast); $code = $this->prettyPrinter->prettyPrintFile($newAst); $this->filesystem->update($fullPath, $code); } } } } $this->traverser->removeVisitor($this->reNamer); return $replacements; }
/** * @param string $path * @param FilesystemInterface $remote * @param AdapterInterface $remoteAdapter */ private function mirrorFile($path, FilesystemInterface $remote, AdapterInterface $remoteAdapter) { $masterContent = $this->master->read($path); if (!is_string($masterContent)) { throw new \RuntimeException(sprintf('File %s could not be read on master storage', $path)); } $isOnRemote = $remote->has($path); if ($isOnRemote && !$remote->update($path, $masterContent)) { throw $this->createRuntimeException('File', $path, 'updated', $remoteAdapter); } elseif (!$isOnRemote && !$remote->write($path, $masterContent)) { throw $this->createRuntimeException('File', $path, 'created', $remoteAdapter); } }
private function backupAndUpdate($path, $content) { if ($this->enableBackup) { $oldContent = $this->master->read($path); if ($oldContent !== false) { if ($this->backup->has($path)) { $this->backup->update($path, $oldContent); } else { $this->backup->write($path, $oldContent); } } } $this->master->update($path, $content); }
/** * @override * @inheritDoc */ public function read($path) { $ex = null; $ret = false; try { $ret = $this->fs->read($path); } catch (Error $ex) { } catch (Exception $ex) { } if ($ret === false || $ex !== null) { throw new ReadException("File {$path} could not be read.", $ex); } return $ret; }
/** * Creates a Memory adapter from a Flysystem filesystem. * * @param FilesystemInterface $filesystem The Flysystem filesystem. * * @return self A new memory adapter. */ public static function createFromFilesystem(FilesystemInterface $filesystem) { $filesystem->addPlugin(new ListWith()); $adapter = new static(); $config = new Config(); foreach ($filesystem->listWith(['timestamp', 'visibility'], '', true) as $meta) { if ($meta['type'] === 'dir') { $adapter->createDir($meta['path'], $config); continue; } $adapter->write($meta['path'], (string) $filesystem->read($meta['path']), $config); $adapter->setVisibility($meta['path'], $meta['visibility']); $adapter->setTimestamp($meta['path'], $meta['timestamp']); } return $adapter; }
/** * Given the path to a composer file we return it's json as an array. * * @param string $file * @return array */ private function readFile($file) { $this->cache->setNamespace(sha1(__CLASS__)); $item = $this->cache->getItem(sha1($file)); $data = $item->get(); if ($item->isMiss()) { $item->lock(); if ($this->filesystem->has($file)) { $data = json_decode($this->filesystem->read($file), true); } else { throw new ComposerFileNotFound($this->filesystem->getAdapter()->applyPathPrefix($file)); } $this->cache->save($item->set($data)); } return $data; }
/** * @param string $configFileName The path to the consumer's config file (eg .baleen.yml) relative to the project * filesystem * * @return Config */ public function load($configFileName = null) { $configs = []; // load all local configs (config files that are not user-facing) $localConfig = []; foreach ($this->localConfigStack as $file) { $config = (include $file); $localConfig = array_merge_recursive($localConfig, $config); } if (!empty($localConfig)) { $configs[] = $localConfig; } // load the current project's config file (user-facing) if (null === $configFileName) { $configFileName = $this->defaultFileName; } if ($this->projectFileSystem->has($configFileName)) { $configs[] = Yaml::parse($this->projectFileSystem->read($configFileName)); } // validate and merge all configs $config = $this->processor->processConfiguration($this->definition, $configs); return new $this->configClass($config); }
/** * Get the watermark image. * @param Image $image The source image. * @return Image|null The watermark image. */ public function getImage(Image $image) { if (is_null($this->watermarks)) { return; } if (!is_string($this->mark)) { return; } if ($this->mark === '') { return; } $path = $this->mark; if ($this->watermarksPathPrefix) { $path = $this->watermarksPathPrefix . '/' . $path; } if ($this->watermarks->has($path)) { $source = $this->watermarks->read($path); if ($source === false) { throw new FilesystemException('Could not read the image `' . $path . '`.'); } return $image->getDriver()->init($source); } }
/** * Generate manipulated image. * @return Request The request object. * @throws NotFoundException */ public function makeImage() { $request = $this->resolveRequestObject(func_get_args()); if ($this->cacheFileExists($request) === true) { return $request; } if ($this->sourceFileExists($request) === false) { throw new NotFoundException('Could not find the image `' . $this->getSourcePath($request) . '`.'); } $source = $this->source->read($this->getSourcePath($request)); if ($source === false) { throw new FilesystemException('Could not read the image `' . $this->getSourcePath($request) . '`.'); } try { $write = $this->cache->write($this->getCachePath($request), $this->api->run($request, $source)); } catch (FileExistsException $exception) { // Cache file failed to write. Fail silently. return $request; } if ($write === false) { throw new FilesystemException('Could not write the image `' . $this->getCachePath($request) . '`.'); } return $request; }
/** * @param $file * * @return mixed */ private function getJsonContent($file) { $json = $this->fileSystem->read($file); $data = json_decode($json, true); return $data; }
/** * @param ServerRequestInterface $request * * @return mixed */ public function data(ServerRequestInterface $request) { return $this->filesystem->read($this->file); }
/** * Get file contents * * @param string $path file path * @return string|false **/ protected function _getContents($path) { return $this->fs->read($path); }
/** * Generate an {@see SS_HTTPResponse} for the given file from the source filesystem * @param FilesystemInterface $flysystem * @param string $fileID * @return SS_HTTPResponse */ protected function createResponseFor(FilesystemInterface $flysystem, $fileID) { // Build response body // @todo: gzip / buffer response? $body = $flysystem->read($fileID); $mime = $flysystem->getMimetype($fileID); $response = new SS_HTTPResponse($body, 200); // Add headers $response->addHeader('Content-Type', $mime); $headers = Config::inst()->get(get_class($this), 'file_response_headers'); foreach ($headers as $header => $value) { $response->addHeader($header, $value); } return $response; }
/** * Get the file's content. * * @return string */ public function getContent() { return $this->filesystem->read($this->path); }