/** @inheritDoc */ public function getFiles($path = '') { $keys = $this->gaufrette->listKeys($this->getGaufrettePath($path)); $files = new ArrayCollection($keys['keys']); return $files->map(function ($path) { return new File($this, $path); }); }
/** * {@inheritdoc} */ public function getArchives(JobExecution $jobExecution) { $archives = array(); $keys = $this->filesystem->listKeys(dirname($this->getRelativeArchivePath($jobExecution))); foreach ($keys['keys'] as $key) { $archives[basename($key)] = $key; } return $archives; }
/** * {@inheritdoc} */ public function getChildren() { $children = array(); $keys = $this->filesystem->listKeys($this->prefix); foreach ($this->getDirectories($keys['dirs']) as $dir) { $children[] = $this->getChild($dir); } foreach ($this->getFiles($keys['keys']) as $file) { $children[] = $this->getChild($file); } return $children; }
/** * @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; }
/** * Recursively list the files in the given directory path. * * @param string $path The directory path on this filesystem * * @return File[] */ public function getFiles($path = '') { $keys = $this->gaufrette->listKeys($this->getGaufrettePath($path)); $filesystem = $this; return array_map(function ($path) use($filesystem) { return new File($filesystem, $path); }, $keys['keys']); }
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'); }
/** * @Then I should see :fileKey * @Then I should see :fileKey in :key */ public function iShouldSeeIn($fileKey, $key = '') { $outputArray = []; $list = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->filesystem->listKeys($key))); foreach ($list as $sub) { $subArray = $list->getSubIterator(); if ($subArray === $fileKey) { $outputArray[] = iterator_to_array($subArray); } } return count($outputArray) > 0; }
/** * @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); } } } }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\JsonResponse */ protected function fetchRemoteFilesAction(Request $request) { $provider = InputHelper::string($request->request->get('provider')); $path = InputHelper::string($request->request->get('path', '')); $dispatcher = $this->factory->getDispatcher(); $name = AssetEvents::ASSET_ON_REMOTE_BROWSE; if (!$dispatcher->hasListeners($name)) { return $this->sendJsonResponse(array('success' => 0)); } /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ $integrationHelper = $this->factory->getHelper('integration'); /** @var \Mautic\PluginBundle\Integration\AbstractIntegration $integration */ $integration = $integrationHelper->getIntegrationObject($provider); $event = new RemoteAssetBrowseEvent($integration); $dispatcher->dispatch($name, $event); if (!($adapter = $event->getAdapter())) { return $this->sendJsonResponse(array('success' => 0)); } $connector = new Filesystem($adapter); $output = $this->renderView('MauticAssetBundle:Remote:list.html.php', array('connector' => $connector, 'integration' => $integration, 'items' => $connector->listKeys($path))); return $this->sendJsonResponse(array('success' => 1, 'output' => $output)); }
/** * 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(); } }