/** * @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(); }
/** * 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()); } } }
/** * __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 content of the file after rendering. * * @param SplFileInfo $file * * @return string */ protected function getFileContent() { if (ends_with($this->file->getFilename(), '.blade.php')) { return $this->renderBlade(); } elseif (ends_with($this->file->getFilename(), '.md')) { return $this->renderMarkdown(); } return $this->file->getContents(); }
/** * try to verify a search result * * @param SplFileInfo $file file to examine * * @return bool|System */ public function detectSystem(SplFileInfo $file) { if ($file->getFilename() == "system.info" && stripos($file->getContents(), 'project = "drupal"') !== false) { $path = new \SplFileInfo(dirname(dirname($file->getPath()))); return new System($this->getName(), $path); } if ($file->getFilename() == "system.info.yml" && stripos($file->getContents(), "project: 'drupal'") !== false) { $path = new \SplFileInfo(dirname(dirname(dirname($file->getPath())))); return new System($this->getName(), $path); } return false; }
/** * Convert a blade view into a site page. * * @param SplFileInfo $file * * @return void */ public function handle(SplFileInfo $file, $channels) { $this->file = $file; $this->viewPath = $this->getViewPath(); $this->directory = $this->getDirectoryPrettyName(); $this->appendViewInformationToData(); foreach ($channels as $channel => $values) { if ($channel == $this->viewPath) { $this->prepareBlogIndexViewData($this->viewsData[$values['container']], $values['paginationView'], $values['paginationContainer'], $channel); } } $content = $this->getFileContent(); $this->filesystem->put(sprintf('%s/%s', $this->prepareAndGetDirectory(), ends_with($file->getFilename(), ['.blade.php', 'md']) ? 'index.html' : $file->getFilename()), $content); }
/** * 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()); }
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++; } }
private function uploadFile(File $file) { if ($file->getFilename() == 'config.yml') { return; } $this->output->writeln('Uploading ' . $file->getRelativePathname()); $this->bucket->upload($file); }
/** * @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 \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; }
/** * Parses a .platform.app.yaml file. * * @param \Symfony\Component\Finder\SplFileInfo $configFile * The file to parse. * * @return array|null * An array of configurations found in the file or null. */ private function parseConfigFile(SplFileInfo $configFile) { $yaml = new Parser(); try { return $yaml->parse($configFile->getContents()); } catch (ParseException $e) { printf('Unable to parse the platform configuration file: %s', $configFile->getFilename()); } return null; }
public function __construct(SplFileInfo $file) { $this->file = $file; $this->path = str_replace('\\', '/', $file->getRelativePath()); $this->filename = $file->getFilename(); list($this->type, $this->vendor) = explode('/', $this->path); $matches = $this->parseFilename($this->filename); $this->package = $matches['package']; $this->version = $matches['version']; }
function it_should_filter_by_not_name(SplFileInfo $file1, SplFileInfo $file2) { $file1->getFilename()->willReturn('file.php'); $file2->getFilename()->willReturn('file.png'); $result = $this->notName('*.png'); $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\FilesCollection'); $result->count()->shouldBe(1); $files = $result->toArray(); $files[0]->shouldBe($file1); }
/** * try to verify a search result and work around some well known false positives * * @param SplFileInfo $file file to examine * * @return bool|System */ public function detectSystem(SplFileInfo $file) { $fileName = $file->getFilename(); if ($fileName !== "LocalConfiguration.php" && $fileName !== 'localconf.php') { return false; } $path = new \SplFileInfo($file->getPathInfo()->getPath()); // Return result if working return new System($this->getName(), $path); }
/** * verify a search result by making sure that the file has the correct name and $wp_version is in there * * @param SplFileInfo $file file to examine * * @return bool|System */ public function detectSystem(SplFileInfo $file) { if ($file->getFilename() != "version.php") { return false; } if (stripos($file->getContents(), '$wp_version =') === false) { return false; } $path = new \SplFileInfo(dirname($file->getPath())); return new System($this->getName(), $path); }
/** * Impoort the given file and return the number of inserted translations. * * @param \Symfony\Component\Finder\SplFileInfo $file * @param boolean $forceUpdate force update of the translations * @return int */ public function import(\Symfony\Component\Finder\SplFileInfo $file, $forceUpdate = false) { $imported = 0; list($domain, $locale, $extention) = explode('.', $file->getFilename()); if (isset($this->loaders[$extention])) { $messageCatalogue = $this->loaders[$extention]->load($file->getPathname(), $locale, $domain); $translationFile = $this->fileManager->getFor($file->getFilename(), $file->getPath()); foreach ($messageCatalogue->all($domain) as $key => $content) { // skip empty translation values if (!isset($content)) { continue; } $transUnit = $this->storage->getTransUnitByKeyAndDomain($key, $domain); if (!$transUnit instanceof TransUnitInterface) { $transUnit = $this->transUnitManager->create($key, $domain); } $translation = $this->transUnitManager->addTranslation($transUnit, $locale, $content, $translationFile); if ($translation instanceof TranslationInterface) { $imported++; } else { if ($forceUpdate) { $translation = $this->transUnitManager->updateTranslation($transUnit, $locale, $content); $imported++; } } // convert MongoTimestamp objects to time to don't get an error in: // Doctrine\ODM\MongoDB\Mapping\Types\TimestampType::convertToDatabaseValue() if ($transUnit instanceof TransUnitDocument) { $transUnit->convertMongoTimestamp(); } } $this->storage->flush(); // clear only Lexik entities foreach (array('file', 'trans_unit', 'translation') as $name) { $this->storage->clear($this->storage->getModelClass($name)); } } else { throw new \RuntimeException(sprintf('No load found for "%s" format.', $extention)); } return $imported; }
/** * Transform a taxonomy YAML into a TaxonomyFile object * * @param SplFileInfo $file * * @return \Skimpy\Contracts\Entity|TaxonomyFile */ public function transform(SplFileInfo $file) { $data = $this->parser->parse($file->getContents()); $missingFields = $this->getMissingFields($data); if (false === empty($missingFields)) { throw new TransformationFailure(sprintf('Missing required fields (%s) in taxonomy file: %s', implode(', ', $this->getMissingFields($data)), $file->getRealPath())); } $filename = $file->getFilename(); $ext = $file->getExtension(); $slug = explode('.' . $ext, $filename)[0]; return new TaxonomyFile($slug, $data['name'], $data['plural_name'], $data['terms']); }
/** * Constructor * * @param Analyzer $analyzer Analyzer * @param DataSourceInterface $dataSource Data Source * @param SplFileInfo $file File * @param bool $isRaw Should be treated as raw * @param bool $hasChanged Has the file changed? */ public function __construct(Analyzer $analyzer, DataSourceInterface $dataSource, SplFileInfo $file, $isRaw, $hasChanged = false) { $this->analyzer = $analyzer; $this->sourceId = 'FileSource:' . $dataSource->dataSourceId() . ':' . $file->getRelativePathname(); $this->relativePathname = $file->getRelativePathname(); $this->filename = $file->getFilename(); $this->file = $file; $this->isRaw = $isRaw; $this->hasChanged = $hasChanged; $internetMediaTypeFactory = $this->analyzer->getInternetMediaTypeFactory(); $this->applicationXmlType = $internetMediaTypeFactory->createApplicationXml(); $this->init(); }
/** * @see ContentModifierInterface::modify() */ public function modify(SplFileInfo $generatedFile, array $data, Inflector $inflector, SplFileInfo $templateFile) { $options = $this->resolver->resolve($data); $fileContent = $generatedFile->getContents(); // current file is a bundle ? $isInBundle = preg_match(sprintf('/namespace (.*%s.*Bundle);/', $inflector->translate('MajoraNamespace')), $fileContent, $inBundleMatches); $isABundle = preg_match(sprintf('/class (([\\w]*)%s[\\w]*Bundle) extends [\\w]*Bundle/', $inflector->translate('MajoraNamespace')), $fileContent, $isBundleMatches); if (!$isInBundle || !$isABundle) { $this->logger->notice(sprintf('Try to register "%s" file into Kernel which isnt a bundle. Abording.', $generatedFile->getFilename())); return $fileContent; } $bundleInclusion = sprintf('new %s\\%s(),', $inBundleMatches[1], $isBundleMatches[1]); $kernelFile = new SplFileInfo(sprintf('%s/%s', $this->kernelDir, $options['kernel_filename']), '', ''); $kernelContent = $kernelFile->getContents(); // is bundle not already registered ? if (strpos($kernelContent, $bundleInclusion) !== false) { $this->logger->debug(sprintf('Bundle "%s" is already registered. Abording.', $generatedFile->getFilename())); return $fileContent; } $this->filesystem->dumpFile($kernelFile->getPathname(), preg_replace('/(Bundle\\(\\)\\,)(\\n[\\s]+\\);)/', sprintf("\$1\n %s\$2", $bundleInclusion), $kernelContent)); $this->logger->info(sprintf('file updated : %s', $kernelFile->getPathname())); return $fileContent; }
/** * @see ContentModifierInterface::modify() */ public function modify(SplFileInfo $generatedFile, array $data, Inflector $inflector, SplFileInfo $templateFile) { $options = $this->resolver->resolve($data); // retrieve target location $targetServicesFilepath = $this->resolveTargetFilePath($options['target'], $generatedFile->getPath()); // build content $import = sprintf('<import resource="%s" />', $inflector->translate($options['resource'])); $servicesFile = new SplFileInfo($targetServicesFilepath, '', ''); $servicesContent = $servicesFile->getContents(); // are services not already registered ? if (strpos($servicesContent, $import) !== false) { $this->logger->debug(sprintf('Service file "%s" is already registered into "%s". Abording.', $generatedFile->getFilename(), $targetServicesFilepath)); return $generatedFile->getContents(); } $this->filesystem->dumpFile($servicesFile->getRealpath(), str_replace(' </imports>', sprintf(" %s\n </imports>", $import), $servicesContent)); $this->logger->info(sprintf('file updated : %s', $servicesFile->getRealpath())); return $generatedFile->getContents(); }
/** * {@inheritdoc} */ public function import(SplFileInfo $file) { list($domain, $locale, $extension) = explode('.', $file->getFilename()); $translations = []; if ($this->loadersContainer->has($extension)) { /** @var MessageCatalogue $messageCatalogue */ $messageCatalogue = $this->loadersContainer->get($extension)->load($file, $locale, $domain); $domainMessages = $messageCatalogue->all($domain); if (!empty($domainMessages)) { $path = substr(pathinfo($file->getPathname(), PATHINFO_DIRNAME), strlen(getcwd()) + 1); $translations[$path][$domain]['format'] = $file->getExtension(); foreach ($domainMessages as $key => $content) { $translations[$path][$domain]['translations'][$key][$locale] = $content; } } } return $translations; }
public function import(\Symfony\Component\Finder\SplFileInfo $file, $force = false) { $this->validateLoaders($this->loaders); $filename = $file->getFilename(); list($domain, $locale, $extension) = explode('.', $filename); if (!isset($this->loaders[$extension]) || !$this->loaders[$extension] instanceof \Symfony\Component\Translation\Loader\LoaderInterface) { throw new \Exception(sprintf('Requested loader for extension .%s isnt set', $extension)); } $loader = $this->loaders[$extension]; $messageCatalogue = $loader->load($file->getPathname(), $locale, $domain); $importedTranslations = 0; foreach ($messageCatalogue->all($domain) as $keyword => $text) { if ($this->importSingleTranslation($keyword, $text, $locale, $filename, $domain, $force)) { $importedTranslations++; } } return $importedTranslations; }
/** * @see ContentModifierInterface::modify() */ public function modify(SplFileInfo $generatedFile, array $data, Inflector $inflector, SplFileInfo $templateFile) { $options = $this->resolver->resolve($data); // retrieve target location $targetRoutingFilepath = $this->resolveTargetFilePath($options['target'], $generatedFile->getPath()); // build content $routing = sprintf(' %s: resource: "%s" %s', $inflector->translate($options['route']), $inflector->translate($options['resource']), is_null($options['prefix']) ? '' : sprintf("prefix: %s\n", $inflector->translate($options['prefix']))); $routingFile = new SplFileInfo($targetRoutingFilepath, '', ''); $routingContent = $routingFile->getContents(); // is routing not already registered ? if (strpos($routingContent, trim($routing)) !== false) { $this->logger->debug(sprintf('Routing file "%s" is already registered into "%s". Abording.', $generatedFile->getFilename(), $targetRoutingFilepath)); return $generatedFile->getContents(); } $this->filesystem->dumpFile($routingFile->getRealpath(), sprintf('%s%s', $routingContent, $routing)); $this->logger->info(sprintf('file updated : %s', $routingFile->getRealpath())); return $generatedFile->getContents(); }
/** * __construct */ protected function __construct(SplFileInfo $file, $language = 'en') { $parser = app(Parser::class); $this->metadata = $parser->frontmatter($file->getContents()); $this->title = isset($this->metadata['PageTitle']) ? $this->metadata['PageTitle'] : (isset($this->metadata['Title']) ? $this->metadata['Title'] : Content::filename_to_title($file->getFilename())); $this->slug = Content::str_to_slug($this->title); if (ends_with($file->getRelativePathName(), 'index.md')) { $this->is_section_home = true; } $this->level = count(array_filter(explode(DIRECTORY_SEPARATOR, $file->getRelativePath()))); $relativePath = str_replace('\\', '/', $file->getRelativePath()); $this->is_homepage = $this->level === 0 && $this->is_section_home; if ($this->level > 0 && $this->is_section_home) { $this->path = $relativePath; } else { $relativePath = $relativePath . (ends_with($relativePath, '/') ? '' : '/'); $this->path = $relativePath . $this->slug; } $this->language = $language; $this->file = $file; $this->order = isset($this->metadata['Order']) ? $this->metadata['Order'] : (isset($this->metadata['Sort']) ? $this->metadata['Sort'] : 0); }
/** * @param SplFileInfo $file * * @return string */ public function clean(SplFileInfo $file) { $name = $file->getFilename(); if ($file->isFile()) { $name = pathinfo($name, PATHINFO_FILENAME); } $name = str_replace("\t\n\r\v", ' ', $name); // remove control characters $name = str_replace('_', ' ', $name); $name = preg_replace('/\\[[^\\[\\]]*\\]/', ' ', $name); // remove [...] $name = preg_replace('/\\([^\\(\\)]*\\)/', ' ', $name); // remove (...) // remove all file meta data $reg = sprintf('/[ .,](?:%s)[ .,]/i', implode('|', $this->meta)); while (preg_match($reg, $name . ' ')) { $name = preg_replace($reg, ' ', $name . ' '); } $name = str_replace(' ', ' ', $name); // remove double spaces $name = trim($name, ' .,-'); return $name; }
/** * try to verify a search result and work around some well known false positives * * @param SplFileInfo $file file to examine * * @return bool|System */ public function detectSystem(SplFileInfo $file) { if ($file->getFilename() != "configuration.php") { return false; } if (stripos($file->getContents(), "JConfig") === false) { return false; } // False positive "Akeeba Backup Installer" if (stripos($file->getContents(), "class ABIConfiguration") !== false) { return false; } // False positive mock file in unit test folder if (stripos($file->getContents(), "Joomla.UnitTest") !== false) { return false; } // False positive mock file in unit test folder if (stripos($file->getContents(), "Joomla\\Framework\\Test") !== false) { return false; } $path = new \SplFileInfo($file->getPath()); // Return result if working return new System($this->getName(), $path); }
/** * @return string */ public function getName() { return $this->fileInfo->getFilename(); }
private static function createArguments(array $testCase, SplFileInfo $resource) { return array($testCase['user_agent_string'], isset($testCase['js_ua']) ? json_decode(str_replace("'", '"', $testCase['js_ua']), true) : array(), $testCase['family'], isset($testCase['major']) ? $testCase['major'] : null, isset($testCase['minor']) ? $testCase['minor'] : null, isset($testCase['patch']) ? $testCase['patch'] : null, isset($testCase['patch_minor']) ? $testCase['patch_minor'] : null, $resource->getFilename()); }