Beispiel #1
0
 /**
  * @return resource
  */
 private function getPrivateKeyResource()
 {
     try {
         $file = $this->filesystem->get($this->fileName);
     } catch (FileNotFound $e) {
         $file = $this->createKeys();
     }
     $key = openssl_pkey_get_private($file->getContent());
     return $key;
 }
 /**
  * {@inheritdoc}
  */
 public function getChild($name)
 {
     $key = $this->prefix . $name;
     if (!$this->filesystem->has($key)) {
         throw new Exception\NotFound('The file with name: ' . $name . ' could not be found');
     }
     if ($this->filesystem->getAdapter()->isDirectory($key)) {
         return new self($this->filesystem, $key . '/');
     }
     return new File($this->filesystem->get($key));
 }
 /**
  * Validate file by target entity without saving.
  *
  * @param EmailAttachment $emailAttachment
  * @param string $className
  *
  * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  */
 public function validateEmailAttachmentForTargetClass(EmailAttachment $emailAttachment, $className)
 {
     if (null === $emailAttachment->getFile()) {
         $file = $this->copyEmailAttachmentToFileSystem($emailAttachment);
         $fileViolations = $this->configFileValidator->validate($className, $file);
         $this->filesystem->get($file->getFilename())->delete();
     } else {
         $file = $emailAttachment->getFile();
         $fileViolations = $this->configFileValidator->validate($className, $file);
     }
     return $fileViolations;
 }
 /**
  * @param AttachmentOro $attachmentOro
  *
  * @return AttachmentEntity
  */
 public function oroToEntity(AttachmentOro $attachmentOro)
 {
     $emailAttachmentEntity = new AttachmentEntity();
     $emailAttachmentEntity->setFileName($attachmentOro->getFile()->getFilename());
     $emailAttachmentContent = new EmailAttachmentContent();
     $emailAttachmentContent->setContent(base64_encode($this->filesystem->get($attachmentOro->getFile()->getFilename())->getContent()));
     $emailAttachmentContent->setContentTransferEncoding('base64');
     $emailAttachmentContent->setEmailAttachment($emailAttachmentEntity);
     $emailAttachmentEntity->setContent($emailAttachmentContent);
     $emailAttachmentEntity->setContentType($attachmentOro->getFile()->getMimeType());
     $emailAttachmentEntity->setFile($attachmentOro->getFile());
     $emailAttachmentEntity->setFileName($attachmentOro->getFile()->getOriginalFilename());
     return $emailAttachmentEntity;
 }
Beispiel #5
0
 public function testGetThrowsAnExceptionIfTheFileDoesNotExistAndTheCreateParameterIsSetToFalse()
 {
     $adapter = new InMemory();
     $fs = new Filesystem($adapter);
     $this->setExpectedException('InvalidArgumentException');
     $fs->get('myFile');
 }
 public function testResize()
 {
     $image = $this->getMock('Imagine\\Image\\ImageInterface');
     $image->expects($this->once())->method('thumbnail')->will($this->returnValue($image));
     $image->expects($this->once())->method('get')->will($this->returnValue(file_get_contents(__DIR__ . '/../fixtures/logo.png')));
     $adapter = $this->getMock('Imagine\\Image\\ImagineInterface');
     $adapter->expects($this->any())->method('load')->will($this->returnValue($image));
     $media = $this->getMock('Sonata\\MediaBundle\\Model\\MediaInterface');
     $media->expects($this->exactly(2))->method('getBox')->will($this->returnValue(new Box(535, 132)));
     $filesystem = new Filesystem(new InMemory());
     $in = $filesystem->get('in', true);
     $in->setContent(file_get_contents(__DIR__ . '/../fixtures/logo.png'));
     $out = $filesystem->get('out', true);
     $resizer = new SimpleResizer($adapter, 'outbound');
     $resizer->resize($media, $in, $out, 'bar', array('height' => null, 'width' => 90, 'quality' => 100));
 }
 /**
  * @param Media $media
  *
  * @return \Gaufrette\File
  */
 public function getOriginalFile(Media $media)
 {
     $relativePath = sprintf('/%s.%s', $media->getUuid(), ExtensionGuesser::getInstance()->guess($media->getContentType()));
     return $this->fileSystem->get($relativePath, true);
 }
 /**
  * @param Media $media
  *
  * @return \Gaufrette\File
  */
 public function getOriginalFile(Media $media)
 {
     return $this->fileSystem->get($this->getFilePath($media), true);
 }
 /**
  * @return string
  */
 public function getJson()
 {
     return $this->filesystem->has($this->configFile) ? $this->filesystem->get($this->configFile, true)->getContent() : '{}';
 }
Beispiel #10
0
 /**
  * Get file content
  *
  * @param File|string $file The File object or file name
  *
  * @return string
  */
 public function getContent($file)
 {
     return $this->filesystem->get($file instanceof File ? $file->getFilename() : $file)->getContent();
 }
Beispiel #11
0
 /**
  * Get file content
  *
  * @param File $entity
  * @return string
  */
 public function getContent(File $entity)
 {
     return $this->filesystem->get($entity->getFilename())->getContent();
 }
Beispiel #12
0
 /**
  * Get Virtual Files Action
  *
  * @param string $file
  *
  * @throws NotFoundHttpException
  * @return Response
  */
 public function fileAction($file = null)
 {
     if (null == $file) {
         return $this->redirect($this->generateUrl('vfs_files', array('file' => '/')));
     }
     $cacheDirectory = $this->getParameter('adapter_cache_dir');
     $local = new LocalAdapter($cacheDirectory, true);
     $localadapter = new LocalAdapter($this->getParameter('adapter_files'));
     $adapter = new CacheAdapter($localadapter, $local, 3600);
     $fsAvatar = new Filesystem($adapter);
     if ($this->endswith($file, '/')) {
         if ($fsAvatar->has($file)) {
             $this->gvars['title'] = $this->translate('indexof', array('%dir%' => $this->generateUrl('vfs_files', array('file' => $file))));
             $this->gvars['pagetitle'] = $this->translate('indexof_raw', array('%dir%' => $this->generateUrl('vfs_files', array('file' => $file))));
             $path = substr($file, 1);
             $fs = $fsAvatar->listKeys($path);
             $listfiles = array();
             foreach ($fs['dirs'] as $key) {
                 $fulldir = $key . '/';
                 $dirname = $key;
                 if (substr($key, 0, strlen($path)) == $path) {
                     $dirname = substr($dirname, strlen($path));
                 }
                 if (!strstr($dirname, '/')) {
                     $listfiles[$fulldir] = $dirname;
                 }
             }
             foreach ($fs['keys'] as $key) {
                 $fullfile = $key;
                 $filename = $key;
                 if (substr($key, 0, strlen($path)) == $path) {
                     $filename = substr($filename, strlen($path));
                 }
                 if (!strstr($filename, '/')) {
                     $listfiles[$fullfile] = $filename;
                 }
             }
             $this->gvars['fs'] = $listfiles;
             return $this->renderResponse('AcfResBundle:Vfs:list_files.html.twig', $this->gvars);
         } else {
             throw new NotFoundHttpException();
         }
     }
     if ($fsAvatar->has($file)) {
         if ($fsAvatar->getAdapter()->isDirectory($file)) {
             $file .= '/';
             return $this->redirect($this->generateUrl('vfs_files', array('file' => $file)));
         }
         $reqFile = $fsAvatar->get($file);
         $response = new Response();
         $response->headers->set('Content-Type', 'binary');
         $response->setContent($reqFile->getContent());
         return $response;
     } else {
         throw new NotFoundHttpException();
     }
 }
 /**
  * Get file.
  *
  * @param $name
  * @return File
  */
 public function get($name)
 {
     return $this->filesystem->get($name);
 }
 /**
  * Returns raw image.
  *
  * @param string $imagePath
  *
  * @return string
  */
 public function getImage($imagePath)
 {
     return $this->files->get($imagePath)->getContent();
 }
Beispiel #15
0
 /**
  * Move file to external filesystem
  *
  * @param Filesystem $filesystem File system to store file. If omitted - store in php's upload_tmp_dir
  * @param string $targetFilename New file name. If omitted - use original filename
  * @return \Gaufrette\File
  */
 public function move(Filesystem $filesystem = null, $targetFilename = null, $overwrite = true)
 {
     // source file
     $sourceFile = $this->getTransport()->getFile();
     // target base name
     $targetBasename = $this->buildTargetBasename($sourceFile, $targetFilename);
     // move file to target storage
     $content = stream_get_contents($sourceFile->getStream());
     // write file
     $filesystem->write($targetBasename, $content, $overwrite);
     return $filesystem->get($targetBasename);
 }