/** * @see ContentModifierInterface::modify() */ public function modify(SplFileInfo $generatedFile, array $data, Inflector $inflector, SplFileInfo $templateFile) { $options = $this->resolver->resolve($data); // retrieve target location $targetConfigFilepath = $this->resolveTargetFilePath($options['target'], $generatedFile->getPath()); $emBundleDefinition = sprintf(' %s: type: yml dir: %s prefix: %s alias: %s ', $options['bundle'], $options['relative_schema_directory'], $options['prefix'], $options['alias']); $configsFile = new SplFileInfo($targetConfigFilepath, '', ''); $configsContent = $configsFile->getContents(); // are configs not already registered ? if (strpos($configsContent, trim($emBundleDefinition)) !== false) { $this->logger->debug(sprintf('Config file "%s" is already registered into "%s". Abording.', $generatedFile->getFilename(), $targetConfigFilepath)); return $generatedFile->getContents(); } $this->filesystem->dumpFile($configsFile->getPathname(), str_replace(sprintf(' entity_managers: %s: mappings:', $options['em']), sprintf(' entity_managers: %s: mappings:%s', $options['em'], $emBundleDefinition), $configsContent)); $this->logger->info(sprintf('file updated : %s', $configsFile->getPathname())); return $generatedFile->getContents(); }
/** * @param $string * @param null $path * @return string */ public function parse($string, $path = null) { $headers = []; $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $string, 3); if (count($parts) == 3) { $string = $parts[0] . "\n" . $parts[2]; $headers = $this->yaml->parse($parts[1]); } $file = new SplFileInfo($path, '', ''); $date = Carbon::createFromTimestamp($file->getMTime()); $dateFormat = config('fizl-pages::date_format', 'm/d/Y g:ia'); $headers['date_modified'] = $date->toDateTimeString(); if (isset($headers['date'])) { try { $headers['date'] = Carbon::createFromFormat($dateFormat, $headers['date'])->toDateTimeString(); } catch (\InvalidArgumentException $e) { $headers['date'] = $headers['date_modified']; //dd($e->getMessage()); } } else { $headers['date'] = $headers['date_modified']; } $this->execute(new PushHeadersIntoCollectionCommand($headers, $this->headers)); $viewPath = PageHelper::filePathToViewPath($path); $cacheKey = "{$viewPath}.headers"; $this->cache->put($cacheKey, $headers); return $string; }
/** * @param \Phar $phar * @param SplFileInfo $file */ private function addFile(\Phar $phar, SplFileInfo $file) { $path = $file->getRelativePathname(); $content = file_get_contents($file); $content = preg_replace('{^#!/usr/bin/env php\\s*}', '', $content); $phar->addFromString($path, $content); }
/** * @dataProvider schemaProvider */ public function testRessources(SplFileInfo $testDirectory) { // 1. Cleanup generated $filesystem = new Filesystem(); if ($filesystem->exists($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated')) { $filesystem->remove($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated'); } $filesystem->mkdir($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated'); // 2. Generate $command = new GenerateCommand(); $inputArray = new ArrayInput(['--config-file' => $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . '.jane'], $command->getDefinition()); $command->execute($inputArray, new NullOutput()); // 3. Compare $expectedFinder = new Finder(); $expectedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'expected'); $generatedFinder = new Finder(); $generatedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated'); $generatedData = []; $this->assertEquals(count($expectedFinder), count($generatedFinder), sprintf('No same number of files for %s', $testDirectory->getRelativePathname())); foreach ($generatedFinder as $generatedFile) { $generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath(); } foreach ($expectedFinder as $expectedFile) { $this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData, sprintf('File %s does not exist for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname())); if ($expectedFile->isFile()) { $this->assertEquals(file_get_contents($expectedFile->getRealPath()), file_get_contents($generatedData[$expectedFile->getRelativePathname()]), sprintf('File %s does not have the same content for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname())); } } }
private function processFile(SplFileInfo $path) { $relativeDirName = dirname(str_replace($this->inPath, '', $path->getPathname())); $filenameParts = explode('/', $relativeDirName); $pdfDir = array_pop($filenameParts); $restaurant = array_pop($filenameParts); $outDir = $this->outPath . '/' . $relativeDirName; if (!is_dir($outDir)) { mkdir($outDir, 0777, true); } $outFilename = $outDir . '/' . str_replace('.pdf', '-%03d.png', $path->getFilename()); $convertCommand = "gm convert -density 300 \"{$path->getPathname()}\" -resize '1280x1280>' +profile '*' +adjoin \"{$outFilename}\""; $this->output->writeln("Processing {$path->getPathname()}"); // convert directory exec($convertCommand); // create csv file $finder = new Finder(); $finder->files()->name('*.png')->in($outDir); /** @type SplFileInfo $file */ $index = 1; $this->output->writeln("-- " . $finder->count() . " images"); foreach ($finder as $file) { if (!isset($this->outCsv[$restaurant])) { $this->outCsv[$restaurant] = []; } $this->outCsv[$restaurant][] = ['restaurant' => $restaurant, 'pdf' => $path->getRelativePathname(), 'page' => $index, 'image' => $relativeDirName . '/' . $file->getFilename(), 'folder' => $relativeDirName]; $index++; } }
protected function _getAbsoluteFilePathToCompareAgainst() { // todokj The 'enterprise' needs to be determined dynamically $design = \Mage::getSingleton('core/design_package'); $filename = $design->getFilename($this->_file->getRelativePathname(), array('_area' => 'frontend', '_package' => $this->_getPackageToCompareAgainst(), '_theme' => $this->_getPackageThemeToCompareAgainst(), '_type' => $this->_getType())); return $filename; }
/** * Create our second level request for posting items * * @param Api $api * @param SplFileInfo $file * @param bool $method */ public function __construct(Api $api, SplFileInfo $file, $method) { $data = $api->getResponse()->json(); parent::__construct($api->getApiKey(), $api->getApiSecret(), $api->getHttps()); $this->path = sprintf('%s://%s%s', $data['link']['protocol'], $data['link']['address'], $data['link']['path']); $this->setGet('key', $data['link']['query']['key'])->setGet('token', $data['link']['query']['token'])->setPost('file', '@' . $file->getPath() . '/' . $file->getFilename()); }
/** * @return string */ public function read() { if ($this->contents) { return $this->contents; } return $this->contents = $this->file->getContents(); }
/** * Convert a blade view into a site page. * * @param SplFileInfo $file * * @return void */ public function handle(SplFileInfo $file, $viewsData) { $this->viewsData = $viewsData; $this->file = $file; $this->viewPath = $this->getViewPath(); $this->directory = $this->getDirectoryPrettyName(); $this->appendViewInformationToData(); $content = $this->getFileContent(); $this->filesystem->put(sprintf('%s/%s', $this->prepareAndGetDirectory(), ends_with($file->getFilename(), ['.blade.php', 'md']) ? 'index.html' : $file->getFilename()), $content); // copy images to public folder foreach ($file->images as $media) { $copyFrom = ORCA_CONTENT_DIR . "/{$file->getRelativePath()}/{$media}"; $copyTo = "{$this->directory}/{$media}"; if (!$this->filesystem->copy($copyFrom, $copyTo)) { echo "failed to copy {$media}...\n"; } } // copy documents foreach ($file->documents as $media) { $copyFrom = ORCA_CONTENT_DIR . "/{$file->getRelativePath()}/{$media}"; $copyTo = "{$this->directory}/{$media}"; if (!$this->filesystem->copy($copyFrom, $copyTo)) { echo "failed to copy {$media}...\n"; } } }
public function put($src, $dest) { if (false === file_exists($src)) { throw new \InvalidArgumentException(sprintf('Resource \'%s\' does not exist', $src)); } if (is_file($src) && is_dir($dest)) { $dest = $dest . DIRECTORY_SEPARATOR . basename($src); } if (is_file($src)) { $file = new \SplFileInfo($src); $this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_PUT, new TransporterEvent($this, array('dest' => $dest, 'src' => $file->getPathname()))); $pwd = dirname($dest); if (!is_dir($pwd)) { $this->mkdir($pwd); } copy($file->getPathname(), $dest); } else { if (!$this->exists($dest)) { $this->mkdir($dest); } $finder = new Finder(); $test = $finder->in($src)->depth('== 0'); foreach ($test as $file) { $this->put(rtrim($src, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file->getFilename(), rtrim($dest, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file->getFilename()); } } }
private function uploadFile(File $file) { if ($file->getFilename() == 'config.yml') { return; } $this->output->writeln('Uploading ' . $file->getRelativePathname()); $this->bucket->upload($file); }
public static function readFile($path) { $file = new SplFileInfo($path, '', ''); if (!$file->isFile()) { throw new Exception('Invalid file. Fail to get file ' . $path); } return $file; }
/** * @param SplFileInfo $file * @return StdClass */ protected function createImageObject(SplFileInfo $file) { $obj = new StdClass(); $path = $file->getRelativePathname(); $obj->url = route('imagecache', ['original', $path]); $obj->thumbnail = route('imagecache', ['small', $path]); return $obj; }
/** * __construct */ protected function __construct(SplFileInfo $file, $relativePath = null) { $this->title = Content::filename_to_title($file->getFilename()); $this->slug = Content::str_to_slug($file->getFilename()); $relativePath = !is_null($relativePath) && !empty($relativePath) ? $relativePath : $file->getRelativePath(); $this->path = $relativePath . (ends_with($relativePath, '/') ? '' : '/') . $this->slug; $this->file = $file; }
/** * Get the configuration file nesting path. * * @param \Symfony\Component\Finder\SplFileInfo $file * @return string */ private function getConfigurationNesting(SplFileInfo $file) { $directory = dirname($file->getPathname()); if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR)) { $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.'; } return $tree; }
/** * @param SplFileInfo $file * * @return void * * @throws InvalidContentFile */ protected function verifyFrontMatterSeparatorExists(SplFileInfo $file) { $content = $file->getContents(); $fileName = $file->getFilename(); if (false === strpos($content, FrontMatter::SEPARATOR)) { throw new InvalidContentFile("Missing '---' deliminator in " . $fileName); } }
/** * @param SplFileInfo $file * * @return string */ private function getFileContents(SplFileInfo $file) { $content = $file->getContents(); if ($file->getExtension() === 'js' && substr($content, -1) !== ';') { $content .= ';'; } return $content; }
/** * @param \Symfony\Component\Finder\SplFileInfo $file * @param string $configPath * * @return string */ protected function getConfigurationNesting(SplFileInfo $file, $configPath) { $directory = dirname($file->getRealPath()); if ($tree = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) { $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.'; } return $tree; }
/** * @param SplFileInfo $composerJsonFile * @param array $bundles * * @return bool */ protected function shouldSkip(SplFileInfo $composerJsonFile, array $bundles) { if (!$bundles) { return false; } $folder = $composerJsonFile->getRelativePath(); return !in_array($folder, $bundles); }
/** * treatFile * * @param File $file * @param bool $recursive * @access private * @return File */ private function treatFile(SplFileInfo $file) { if ($file->isDir()) { return $this->fileTransformer->transformToDirectory($file); } elseif ($file->isFile()) { return $this->fileTransformer->transformToFile($file); } }
public function upload(File $file) { try { $this->client->putObject(array('Bucket' => $this->name, 'Key' => $file->getRelativePathname(), 'SourceFile' => $file->getRealpath(), 'ACL' => CannedAcl::PUBLIC_READ)); } catch (InstanceProfileCredentialsException $e) { throw new InvalidAccessKeyIdException("The AWS Access Key Id you provided does not exist in our records."); } }
/** * Get the configuration file nesting path. * * @param \Symfony\Component\Finder\SplFileInfo $file * @return string */ private function getConfigurationNesting(SplFileInfo $file) { $directory = $this->normalizePath(dirname($file->getRealPath())); $directory = ltrim($directory, $this->userConfigurationPath); if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR)) { $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.'; } return $tree; }
/** * Returns FQCN for file * * @param SplFileInfo $fileInfo * * @return string|null */ private function getBundleClass(SplFileInfo $fileInfo) { $reflection = new ReflectionFile($fileInfo->getRealPath()); $baseName = $fileInfo->getBasename('.php'); foreach ($reflection->getNamespaces() as $namespace) { return $namespace . '\\' . $baseName; } return null; }
/** * @param \Symfony\Component\Finder\SplFileInfo $schemaFile * @param array $schemaFiles * * @return array */ private function addSchemaToList(SplFileInfo $schemaFile, array $schemaFiles) { $fileIdentifier = $schemaFile->getFilename(); if (!isset($schemaFiles[$fileIdentifier])) { $schemaFiles[$fileIdentifier] = []; } $schemaFiles[$fileIdentifier][] = $schemaFile; return $schemaFiles; }
public static function checkIfImage($path) { $file = new \SplFileInfo($path); $ex = $file->getExtension(); if ($ex === "png" || $ex === "gif" || $ex === 'bmp' || $ex === "jpeg" || $ex === "jpg") { return true; } return false; }
/** * Load and parse data from cache file */ public function load() { $files = new Filesystem(); if ($files->exists($this->source)) { $file = new SplFileInfo($this->source, null, null); return unserialize($file->getContents()); } return array(); }
/** * @param array $composerJson * @param \Symfony\Component\Finder\SplFileInfo $composerJsonFile * * @return array */ protected function updateAutoloadForTests(array $composerJson, SplFileInfo $composerJsonFile) { $testDirectoryKeys = $this->buildTestDirectoryKeys(); $bundlePath = dirname($composerJsonFile->getPathname()); foreach ($testDirectoryKeys as $testDirectoryKey) { $composerJson = $this->updateAutoload($composerJson, $testDirectoryKey, $bundlePath); } return $composerJson; }
protected function createPageFile(DirectoryPath $repositoryPath, DirectoryPath $directoryPath, SplFileInfo $file) { $pageFile = new PageFile($repositoryPath->toAbsoluteFileString(), $directoryPath->toRelativeFileString(), $file->getRelativePathName()); $title = $this->elasticsearchRepository->getTitle($pageFile->getAbsolutePath()); if (empty($title)) { $title = $pageFile->getRelativePath()->getFileName(); } $pageFile->setTitle($title); return $pageFile; }
protected function prepareFile(SplFileInfo $file) { $filePath = $file->getRelativePathname(); if ($file->isDir()) { $this->newConfig['folders'][] = $filePath; return; } $fileContents = file_get_contents($file->getRealPath()); $this->newConfig['files'][$filePath] = $fileContents; }
/** * @param SplFileInfo $file * * @return array */ public function extractRegisterInformation(SplFileInfo $file) { $content = Yaml::parse($file->getContents()); $result = array('namespace' => $content['namespace'], 'source_dir' => rtrim($file->getPathInfo()->getRealPath(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($content['source_dir'], DIRECTORY_SEPARATOR)); $name = array(); preg_match('#(?P<name>[a-z\\-]*)/?$#i', $file->getPath(), $name); $key = $name['name']; $this->moduleList[$key] = $result; return $result; }