本文整理汇总了PHP中Gaufrette\Filesystem::read方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::read方法的具体用法?PHP Filesystem::read怎么用?PHP Filesystem::read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaufrette\Filesystem
的用法示例。
在下文中一共展示了Filesystem::read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* @return mixed
*/
public function read()
{
if (!$this->gaufrette->has($this->filePath)) {
return '';
}
return $this->gaufrette->read($this->filePath);
}
示例2: showAction
/**
* @param Request $request
* @param string $filename
*
* @throws NotFoundHttpException If media is not found
*
* @return Response
*/
public function showAction(Request $request, $filename)
{
if (!$this->filesystem->has($filename)) {
throw new NotFoundHttpException(sprintf('Media "%s" not found', $filename));
}
$response = new Response($content = $this->filesystem->read($filename));
$mime = $this->filesystem->mimeType($filename);
if (($filter = $request->query->get('filter')) && null !== $mime && 0 === strpos($mime, 'image')) {
try {
$cachePath = $this->cacheManager->resolve($request, $filename, $filter);
if ($cachePath instanceof Response) {
$response = $cachePath;
} else {
$image = $this->imagine->load($content);
$response = $this->filterManager->get($request, $filter, $image, $filename);
$response = $this->cacheManager->store($response, $cachePath, $filter);
}
} catch (\RuntimeException $e) {
if (0 === strpos($e->getMessage(), 'Filter not defined')) {
throw new HttpException(404, sprintf('The filter "%s" cannot be found', $filter), $e);
}
throw $e;
}
}
if ($mime) {
$response->headers->set('Content-Type', $mime);
}
return $response;
}
示例3: generateThumbnail
/**
* @param string $fileKey
* @param string $fileKeyWithFormat
* @param Format $format
*
* @return
*/
protected function generateThumbnail($fileKey, $fileKeyWithFormat, Format $format)
{
// check if has original picture
try {
$has = $this->fileSystem->has($fileKey);
} catch (\OutOfBoundsException $e) {
$has = false;
}
if (!$has) {
throw new Exception\ImageDoesNotExistException();
}
// create thumbnail
try {
$blobOriginal = $this->fileSystem->read($fileKey);
} catch (FileNotFound $e) {
throw new Exception\ImageDoesNotExistException();
}
$imagine = new Imagine();
$image = $imagine->load($blobOriginal);
$resizedImage = Manipulator::resize($image, $format);
$extension = $this->getExtension($fileKey);
$blobResizedImage = $resizedImage->get($extension, array('jpeg_quality' => 90, 'png_compression_level' => 9));
$this->fileSystem->write($fileKeyWithFormat, $blobResizedImage, true);
return $blobResizedImage;
}
示例4: getContents
/** @inheritDoc */
public function getContents($path)
{
try {
return $this->gaufrette->read($this->getGaufrettePath($path));
} catch (\Exception $e) {
return '';
}
}
示例5: downloadFile
/**
* Given a Doctrine mapped File instance, retrieves its data and fill
* content local variable with it.
*
* @param FileInterface $file File to download
*
* @return FileInterface File downloaded
*/
public function downloadFile(FileInterface $file)
{
/**
* @var string $content
*/
$content = $this->filesystem->read($this->fileIdentifierTransformer->transform($file));
$file->setContent($content);
return $file;
}
示例6:
function it_saves_content_of_files_from_gaufrette_at_local_disk(Filesystem $filesystem)
{
$filesystem->listKeys('test')->willReturn(['keys' => ['test/aaa/z.txt', 'test/aaa/test2.txt', 'test.txt'], 'dirs' => ['test/aaa']]);
$filesystem->read('test/aaa/z.txt')->willReturn('Some content');
$filesystem->read('test/aaa/test2.txt')->willReturn('Other text content');
$files = $this->getFiles('test');
$files[0]->shouldBeAnInstanceOf('Cocoders\\FileSource\\File');
$files[0]->shouldHaveContent('Some content');
$files[1]->shouldBeAnInstanceOf('Cocoders\\FileSource\\File');
$files[1]->shouldHaveContent('Other text content');
}
示例7: getFiles
/**
* @param $path
* @return array|\Cocoders\FileSource\File[]
*/
public function getFiles($path)
{
$listedKeys = $this->filesystem->listKeys($path);
$files = [];
foreach ($listedKeys['keys'] as $key) {
$filePath = $this->tmpPath . '/' . $key;
$this->createBaseDirectory($filePath);
if ($this->isNotInRootDir($filePath)) {
file_put_contents($filePath, $this->filesystem->read($key));
$files[] = new File($filePath);
}
}
return $files;
}
示例8: testReadThrowsAnExceptionIfTheKeyDoesNotMatchAnyFile
public function testReadThrowsAnExceptionIfTheKeyDoesNotMatchAnyFile()
{
$adapter = new InMemory();
$fs = new Filesystem($adapter);
$this->setExpectedException('InvalidArgumentException');
$fs->read('myFile');
}
示例9: read
private function read(Filesystem $fs)
{
$profileFilename = Application::PROFILE_FILENAME;
if ($fs->has($profileFilename)) {
$this->processProfileContent($fs->read($profileFilename));
}
}
示例10: pullVariation
/**
* Pull a variation image, if the variation does not exist, try pulling the source and creating the variation.
*
* @param ImageVariation $image
*
* @throws NotExistsException
*/
protected function pullVariation(ImageVariation $image)
{
try {
// First, check if the variation exists on the remote
$this->pullSource($image);
} catch (NotExistsException $e) {
// Variation does not exist, try pulling the parent data and creating the variation
try {
$parent = new Image($image->getKey(true));
if ($this->tagExists($image->getKey(true)) === false) {
if (!$this->validate_tags || !$this->validateTag($parent)) {
throw new NotExistsException(self::ERR_PARENT_NOT_EXISTS);
}
}
$data = $this->filesystem->read($image->getKey(true));
// Resample
$parent->setData($data);
$this->hydrateVariation($parent, $image);
$parent->flush();
} catch (FileNotFoundException $e) {
// No image exists
throw new NotExistsException(self::ERR_PARENT_NOT_EXISTS);
}
}
}
示例11: load
/**
* {@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));
}
try {
$mimeType = $this->filesystem->mimeType($path);
} catch (\LogicException $e) {
// Mime Type could not be detected
return $contents;
}
if (!$mimeType) {
// Mime Type could not be detected
return $contents;
}
return new Binary($contents, $mimeType);
}
示例12: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('file');
$filesystem = new Filesystem(new Local('/'));
$titlerator = new Titlerator(new Transliterator(Settings::LANG_SR), $filesystem->read($file));
$titlerator->fixEncoding();
if ($input->getOption('transliterate')) {
$titlerator->transliterate();
}
$filesystem->write($file, $titlerator->getText(), true);
}
示例13: shouldRenameFile
/**
* @test
* @group functional
*/
public function shouldRenameFile()
{
$this->filesystem->write('foo', 'Some content');
$this->filesystem->rename('foo', 'boo');
$this->assertFalse($this->filesystem->has('foo'));
$this->assertEquals('Some content', $this->filesystem->read('boo'));
$this->filesystem->delete('boo');
$this->filesystem->write('foo', 'Some content');
$this->filesystem->rename('foo', 'somedir/sub/boo');
$this->assertFalse($this->filesystem->has('somedir/sub/foo'));
$this->assertEquals('Some content', $this->filesystem->read('somedir/sub/boo'));
$this->filesystem->delete('somedir/sub/boo');
}
示例14: execute
/**
* @param string $targetPath
* @param array $replacePatterns
* @return mixed|void
*/
public function execute($targetPath = '', array $replacePatterns = array())
{
$adapter = new LocalAdapter($targetPath);
$filesystem = new Filesystem($adapter);
$listKeys = $filesystem->listKeys();
if (count($replacePatterns) > 0) {
foreach ($listKeys['keys'] as $file) {
if (!@strstr(mime_content_type($targetPath . $file), 'image') && !@strstr($file, '.git') && !@strstr($file, '.svn')) {
$filesystem->write($file, $this->replaceContent($replacePatterns, $filesystem->read($file)), TRUE);
}
}
}
}
示例15: getETag
public function getETag($id)
{
if ($this->filesystem->has($id)) {
return $this->filesystem->read($id . '.etag');
}
}