/** * @return mixed */ public function read() { if (!$this->gaufrette->has($this->filePath)) { return ''; } return $this->gaufrette->read($this->filePath); }
/** * @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; }
/** * @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; }
/** @inheritDoc */ public function getContents($path) { try { return $this->gaufrette->read($this->getGaufrettePath($path)); } catch (\Exception $e) { return ''; } }
/** * 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; }
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'); }
/** * @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; }
public function testReadThrowsAnExceptionIfTheKeyDoesNotMatchAnyFile() { $adapter = new InMemory(); $fs = new Filesystem($adapter); $this->setExpectedException('InvalidArgumentException'); $fs->read('myFile'); }
private function read(Filesystem $fs) { $profileFilename = Application::PROFILE_FILENAME; if ($fs->has($profileFilename)) { $this->processProfileContent($fs->read($profileFilename)); } }
/** * 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); } } }
/** * {@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); }
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); }
/** * @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'); }
/** * @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); } } } }
public function getETag($id) { if ($this->filesystem->has($id)) { return $this->filesystem->read($id . '.etag'); } }
/** * @param $path * @return mixed */ public function read($path) { $this->filesystem->read($path); }
/** * @param \Gaufrette\Filesystem $filesystem */ function it_allows_to_set_size($filesystem) { $filesystem->read('filename')->shouldNotBeCalled(); $this->setSize(21); $this->getSize()->shouldReturn(21); }
use Symfony\Component\HttpFoundation\Response; use Silex\Provider\UrlGeneratorServiceProvider; use Silex\Provider\TwigServiceProvider; use Gaufrette\Filesystem; use Gaufrette\Adapter\Local; use Transliterator\Transliterator; use Transliterator\Settings; use Titlerator\Titlerator; $app = new Application(); $app->get('/', function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->post('/convert', function (Request $request) use($app) { $file = $request->files->get('title'); if (null === $file) { return $app['twig']->render('index.html.twig', ['error' => 'Титл није изабран.']); } if (!$file->isValid()) { return $app['twig']->render('index.html.twig', ['error' => 'Дошло је до грешке при отпремању титла.']); } if (!in_array($file->getClientMimeType(), ['application/x-subrip', 'text/x-microdvd', 'text/plain'])) { return $app['twig']->render('index.html.twig', ['error' => 'Изабранa датотека није титл.']); } $filesystem = new Filesystem(new Local('/')); $titlerator = new Titlerator(new Transliterator(Settings::LANG_SR), $filesystem->read($file->getRealPath())); $titlerator->fixEncoding(); $titlerator->transliterate($request->request->has('latin')); return new Response($titlerator->getText(), 200, ['Content-Type' => $file->getClientMimeType(), 'Content-Disposition' => sprintf('attachment; filename="%s"', $file->getClientOriginalName())]); })->bind('convert'); $app->register(new UrlGeneratorServiceProvider())->register(new TwigServiceProvider(), ['twig.path' => __DIR__ . '/../views']); $app->run();
/** * @When I read file :name */ public function iReadFile($name) { $this->currentFileContent = $this->filesystem->read($name); }
/** * @dataProvider providerTestHydrateWithADifferentSystemEnvironment */ public function testHydrateWithADifferentSystemEnvironment($env, $systemEnv, $expectedA, $expectedList, $expectedDirective) { $fs = new Filesystem(new InMemory()); $reader = new InMemoryReader(array('poney:dev' => 'poney_d', 'poney:staging' => 'poney_s', '@licorne:dev' => 'licorne_d', '@licorne:staging' => 'licorne_s', 'env:dev' => array('d', 'e', 'v'), 'env:staging' => array('s', 't', 'a'), '@dsn:dev' => array('d', 'e', 'v'), '@dsn:staging' => array('s', 't', 'a'))); $this->hydrator = new Hydrator($fs, $reader, new Finder($fs)); $fs->write('a-dist', '<%poney%> = <%licorne%>'); $fs->write('list-dist', "<%dsn%>\n<%env%>"); $fs->write('directive-dist', '<% karma:list var=dsn delimiter="" %> = <% karma:list var=env delimiter="" %>'); $this->hydrator->setSystemEnvironment($systemEnv)->hydrate($env); $this->assertSame($expectedA, $fs->read('a')); $this->assertSame($expectedList, $fs->read('list')); $this->assertSame($expectedDirective, $fs->read('directive')); }
/** * @param string $fileName * * @return string */ protected function getScenarioContent(string $fileName) : string { $string = $this->filesystem->read($fileName); return $string; }
/** * @param \Gaufrette\Filesystem $filesystem */ function it_should_get_zero_size_when_file_not_found($filesystem) { $filesystem->read('filename')->willThrow(new \Gaufrette\Exception\FileNotFound('filename')); $this->getSize()->shouldReturn(0); }