/** * @param FilesystemMap $filesystemMap * @param Router $router * @param ServiceLink $securityFacadeLink * @param array $fileIcons */ public function __construct(FilesystemMap $filesystemMap, Router $router, ServiceLink $securityFacadeLink, $fileIcons) { $this->filesystem = $filesystemMap->get('attachments'); $this->router = $router; $this->fileIcons = $fileIcons; $this->securityFacadeLink = $securityFacadeLink; }
/** * @param \Gaufrette\FilesystemMap $filesystemMap */ public function __construct(GaufretteBundleFilesystemMap $filesystemMap) { $map = $filesystemMap->getIterator(); foreach ($map as $domain => $filesystem) { $this->set($domain, $filesystem); } }
protected function setUp() { $this->filesystemMap = $this->getMockBuilder('Knp\\Bundle\\GaufretteBundle\\FilesystemMap')->disableOriginalConstructor()->getMock(); $this->filesystem = $this->getMockBuilder('Gaufrette\\Filesystem')->setMethods(['get'])->disableOriginalConstructor()->getMock(); $this->filesystemMap->expects($this->once())->method('get')->with('attachments')->will($this->returnValue($this->filesystem)); $this->factory = new Factory(); $this->emailAttachmentTransformer = new EmailAttachmentTransformer($this->filesystemMap, $this->factory); }
/** * Dans le cas d'un document nouvellement enregistré, je vais renommer le nom du fichier uploadé si besoin * @param LifecycleEventArgs $eventArgs [description] * @return [type] [description] */ public function postPersist(LifecycleEventArgs $eventArgs) { $document = $eventArgs->getDocument(); $dm = $eventArgs->getDocumentManager(); $is_uploadable = $this->metadata_reader->isUploadable(ClassUtils::getClass($document)); if ($is_uploadable) { // Récupération des champs uploadable $fields = $this->metadata_reader->getUploadableFields(ClassUtils::getClass($document)); // Pour chacun de ces champs, je récupère le mapping associé pour vérifier le namer et le nom du champ foreach ($fields as $field) { $mapping = $this->mapping_factory->fromField($document, $field['propertyName']); if ($mapping->getNamer() instanceof \Redking\Bundle\UploadBundle\Naming\ObjectNamer) { $filename = $mapping->getFileName($document); $file = $mapping->getFile($document); // Si il y a bien un fichier, je vérifie son nom if (!is_null($filename) && $file instanceof File) { $filename_normalized = $mapping->getNamer()->getNormalizedName($document, $filename); // Si les deux noms ne correspondent pas, je renomme et réassigne if (strcmp($filename, $filename_normalized) !== 0) { $base_directory = $mapping->hasDirectoryNamer() ? $mapping->getDirectoryNamer()->directoryName($document, $mapping) . '/' : ''; $adapter = $this->filesystem_map->get($mapping->getUploadDestination())->getAdapter(); $adapter->rename($base_directory . $filename, $base_directory . $filename_normalized); if ($adapter->exists($base_directory . $filename)) { $adapter->delete($base_directory . $filename); } // On vérifie si il y a des fichiers resized à renommer foreach ($this->resizes as $suffix => $resize_conf) { $resize_filename = $base_directory . ResizedNamer::getName($filename, $suffix); $resize_filename_normalized = $base_directory . ResizedNamer::getName($filename_normalized, $suffix); if ($adapter->exists($resize_filename)) { $adapter->rename($resize_filename, $resize_filename_normalized); if ($adapter->exists($resize_filename)) { $adapter->delete($resize_filename); } } } $mapping->setFileName($document, $filename_normalized); // Ré-enregistrement $class = $dm->getClassMetadata(get_class($document)); $dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $document); } } } // Traitement du répertoire basé sur l'id pour voir si le fichier est bien dedans $directory_namer = $mapping->getDirectoryNamer(); if (!is_null($directory_namer) && $directory_namer instanceof BaseDirectoryIdNamer) { $adapter = $this->filesystem_map->get($mapping->getUploadDestination())->getAdapter(); $filename = $mapping->getFileName($document); $good_path = ltrim($directory_namer->directoryName($document, $mapping) . '/' . $filename, '/'); $bad_path = ltrim($directory_namer->directoryNameError($document, $mapping) . '/' . $filename, '/'); if (!$adapter->exists($good_path) && $adapter->exists($bad_path)) { $success = $adapter->rename($bad_path, $good_path); } } } } }
/** * @param FileSystemMap $filesystemMap * @param EntityManager $em * @param KernelInterface $kernel * @param ServiceLink $securityFacadeLink * @param ConfigFileValidator $configFileValidator * @param AttachmentConfig $attachmentConfig */ public function __construct(FilesystemMap $filesystemMap, EntityManager $em, KernelInterface $kernel, ServiceLink $securityFacadeLink, ConfigFileValidator $configFileValidator, AttachmentConfig $attachmentConfig) { $this->filesystem = $filesystemMap->get('attachments'); $this->em = $em; $this->attachmentDir = $kernel->getRootDir() . DIRECTORY_SEPARATOR . self::ATTACHMENT_DIR; $this->securityFacadeLink = $securityFacadeLink; $this->configFileValidator = $configFileValidator; $this->attachmentConfig = $attachmentConfig; }
public function getContent($key) { // get file $file = $this->getMetadata($key); // get filesystem $filesystem = $this->filesystemMap->get($file->getFilesystem()); // get content return $filesystem->read($key); }
/** * ImageStoreService constructor. * * @param FilesystemMap $files * @param RequestStack $requestStack * @param \Dropbox_OAuth_Curl $dropbox */ public function __construct(FilesystemMap $files, RequestStack $requestStack, \Dropbox_OAuth_Curl $dropbox) { $this->request = $requestStack->getCurrentRequest(); if ($this->request !== null && $this->request->getSession() !== null && ($data = $this->request->getSession()->get($this->request->get(self::DROPBOX_STORAGE_NAME))) !== null) { $this->files = $files->get('pictures_dropbox'); $dropbox->setToken($data['access']); $this->uId = $data['uid']; } else { $this->files = $files->get('pictures'); } }
/** * A la suppression de l'objet uploadé, je supprime également les redimensionnements * @param Event $event [description] * @return [type] [description] */ public function onPreRemove(Event $event) { $object = $event->getObject(); $mapping = $event->getMapping(); $adapter = $this->filesystem_map->get($mapping->getUploadDestination())->getAdapter(); $base_directory = $mapping->hasDirectoryNamer() ? $mapping->getDirectoryNamer()->directoryName($object, $mapping) . '/' : ''; foreach ($this->resizes as $suffix => $resize_conf) { $resize_file = $base_directory . ResizedNamer::getName($mapping->getFileName($object), $suffix); if (!is_null($resize_file) && $adapter->exists($resize_file)) { $adapter->delete($resize_file); } } }
/** * @param InputInterface $input * @param OutputInterface $output * * @throws \LogicException * @throws ServiceCircularReferenceException * @throws ServiceNotFoundException * @throws \UnexpectedValueException */ protected function initialize(InputInterface $input, OutputInterface $output) { // Check if this command can be launched ? $this->resourceManager = $this->getContainer()->get('sidus_file_upload.resource.manager'); $this->doctrine = $this->getContainer()->get('doctrine'); $this->fileSystemMaps = $this->getContainer()->get('knp_gaufrette.filesystem_map'); foreach ($this->resourceManager->getResourceConfigurations() as $resourceConfiguration) { $fsKey = $resourceConfiguration->getFilesystemKey(); if (!array_key_exists($fsKey, $this->fileSystems)) { $fs = $this->fileSystemMaps->get($fsKey); $this->fileSystems[$fsKey] = $fs; } } }
/** * Test that FileNotFound exception is catched */ public function testRemoveNotFoundFile() { $mapping = $this->getMock('Vich\\UploaderBundle\\Mapping\\PropertyMapping'); $obj = new DummyEntity(); $prop = $this->getMockBuilder('\\ReflectionProperty')->disableOriginalConstructor()->getMock(); $prop->expects($this->any())->method('getValue')->with($obj)->will($this->returnValue('file.txt')); $prop->expects($this->any())->method('getName')->will($this->returnValue('nameProperty')); $mapping->expects($this->once())->method('getDeleteOnRemove')->will($this->returnValue(true)); $mapping->expects($this->any())->method('getUploadDir')->will($this->returnValue('filesystemKey')); $mapping->expects($this->once())->method('getFileNameProperty')->will($this->returnValue($prop)); $mapping->expects($this->once())->method('getProperty')->will($this->returnValue($prop)); $filesystem = $this->getFilesystemMock(); $filesystem->expects($this->once())->method('delete')->with('file.txt')->will($this->throwException(new FileNotFound('File Not Found'))); $this->filesystemMap->expects($this->once())->method('get')->with('filesystemKey')->will($this->returnValue($filesystem)); $this->factory->expects($this->once())->method('fromObject')->with($obj)->will($this->returnValue(array($mapping))); $storage = new GaufretteStorage($this->factory, $this->filesystemMap); $storage->remove($obj, 'file'); }
public function testUploadDoesNotSetMetadataWhenUsingNonMetadataSupporterAdapter() { $adapter = $this->getMockBuilder('\\Gaufrette\\Adapter\\Apc')->disableOriginalConstructor()->getMock(); $file = $this->getUploadedFileMock(); $file->expects($this->once())->method('getClientOriginalName')->will($this->returnValue('filename')); $file->expects($this->once())->method('getPathname')->will($this->returnValue($this->getValidUploadDir() . DIRECTORY_SEPARATOR . 'test.txt')); $this->mapping->expects($this->once())->method('getFile')->will($this->returnValue($file)); $this->mapping->expects($this->once())->method('getUploadDestination')->will($this->returnValue('filesystemKey')); $filesystem = $this->getFilesystemMock(); $imb = $this->getMockBuilder('\\Gaufrette\\Stream\\InMemoryBuffer')->disableOriginalConstructor()->setMethods(array('open', 'write', 'close'))->getMock(); $imb->expects($this->once())->method('open')->will($this->returnValue(true)); $imb->expects($this->once())->method('write')->will($this->returnValue(true)); $imb->expects($this->once())->method('close')->will($this->returnValue(true)); $filesystem->expects($this->once())->method('createStream')->will($this->returnValue($imb)); $this->filesystemMap->expects($this->once())->method('get')->with('filesystemKey')->will($this->returnValue($filesystem)); $adapter->expects($this->never())->method('setMetadata')->will($this->returnValue(null)); $filesystem->expects($this->any())->method('getAdapter')->will($this->returnValue($adapter)); $this->storage->upload($this->object, $this->mapping); }
/** * Get filesystem adapter from the property mapping * * @param PropertyMapping $mapping * * @return \Gaufrette\Filesystem */ protected function getFilesystem(PropertyMapping $mapping) { return $this->filesystemMap->get($mapping->getUploadDestination()); }
/** * @param FilesystemMap $filesystemMap * @param Factory $factory */ public function __construct(FilesystemMap $filesystemMap, Factory $factory) { $this->filesystem = $filesystemMap->get('attachments'); $this->factory = $factory; }
/** * @param string $type * @return Filesystem * @throws UnexpectedValueException */ public function getFilesystemForType($type) { $config = $this->getResourceTypeConfiguration($type); return $this->filesystemMap->get($config->getFilesystemKey()); }
/** * Construct * * @param FilesystemMap $filesystemMap * @param string $temporaryFilesystemKey * @param string $mediaFilesystemKey */ public function __construct(FilesystemMap $filesystemMap, $temporaryFilesystemKey, $mediaFilesystemKey) { $this->temporaryFilesystem = $filesystemMap->get($temporaryFilesystemKey); $this->mediaFilesystem = $filesystemMap->get($mediaFilesystemKey); }
/** * Try to get the filesystem for the entity passed * * @param object $entity * @return \Gaufrette\Filesystem */ private function getFilesystemForEntity($entity) { return $this->filesystemMap->get($entity->getFilesystemMapId()); }
/** * @param FilesystemMap $filesystemMap * @param string $filesystemKey * @param Filesystem $fileSystem */ public function __construct(FilesystemMap $filesystemMap, $filesystemKey, Filesystem $fileSystem) { $this->adapter = $filesystemMap->get($filesystemKey)->getAdapter(); $this->fileSystem = $fileSystem; }
/** * Get filesystem adapter by key * * @param string $key * * @return \Gaufrette\Filesystem */ protected function getAdapter($key) { return $this->filesystemMap->get($key); }
/** * Save the transformed file * * @param string $endpoint * @param BinaryInterface $cropedFile * @param array $data */ public function saveTransformedFile($endpoint, BinaryInterface $cropedFile, array $data) { $this->filesystemMap->get($this->configuration->getValue($endpoint, 'croped_fs'))->write($data['filename'], $cropedFile->getContent()); }
/** * @param \Knp\Bundle\GaufretteBundle\FilesystemMap $filesystemMap * @param \Gaufrette\Filesystem $filesystem */ function let($filesystemMap, $filesystem) { $filesystemMap->getIterator()->shouldBeCalled()->willReturn(array('filesystem' => $filesystem)); $this->beConstructedWith($filesystemMap); }