/** * @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(); }
/** * 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; }
/** * 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()); }
/** * Get the configuration file nesting path. * * @param \Symfony\Component\Finder\SplFileInfo $file * @param string $configPath * @return string */ protected function getConfigurationNesting(SplFileInfo $file, $configPath) { $directory = $file->getPath(); if ($tree = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) { $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.'; } return $tree; }
/** * @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; }
/** * 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); }
/** * @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(); }
/** * 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; }
/** * @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(); }
/** * 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); }
/** * @param string $rawConfig * @param string $magentoRootFolder * @param SplFileInfo|null $file [optional] * * @return string */ protected function applyVariables($rawConfig, $magentoRootFolder, SplFileInfo $file = null) { $replace = array('%module%' => $file ? $file->getPath() : '', '%root%' => $magentoRootFolder); return str_replace(array_keys($replace), $replace, $rawConfig); }
/** * @Route("/file_manager/new-file/save", name="spliced_cms_admin_file_manager_save_file") * @Template("SplicedCmsBundle:Admin/FileManagement:new_file.html.twig") */ public function saveFileAction() { $view = $this->getViewContext(); $fileForm = $this->createForm(new FileFormType(null), array()); if ($fileForm->submit($this->get('request')) && $fileForm->isValid()) { $file = $fileForm->getData(); $fileInfo = new \SplFileInfo($this->dir->getRealPath() . '/' . $file['fileName']); $relativePath = str_replace($this->baseDir->getRealPath(), '', $fileInfo->getPath()); $wrote = file_put_contents($fileInfo->getPath() . '/' . $fileInfo->getFilename(), $file['content']); if (false === $wrote) { $this->get('session')->getFlashBag()->add('error', 'There was an error saving the file. Permission Denied'); } else { return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager_edit_file', array('dir' => $relativePath, 'file' => $fileInfo->getFilename()))); } } else { $this->get('session')->getFlashBag()->add('error', 'There was an error validating your submission'); } return array_merge($view, array('fileForm' => $fileForm->createView())); }
/** * @return bool */ public function exists() { return is_file($this->file->getPath()); }
/** * @param string $scenario * @param SplFileInfo $fileInfo * * @todo make it event driven * * @return string */ public function parseScenario($scenario, $fileInfo) { $feature = ''; list($title, $body) = explode(PHP_EOL, $scenario, 2); $feature .= '### ' . $title . PHP_EOL . PHP_EOL . $body . PHP_EOL . PHP_EOL; $path = $fileInfo->getPath() . '/' . $fileInfo->getBasename('.feature'); if (is_dir($path)) { $targetFile = $path . '/' . $this->sanitizeFileName($title) . '.md'; if (is_readable($targetFile)) { $feature .= file_get_contents($targetFile) . PHP_EOL . PHP_EOL; } } return $feature; }
/** * Make the path relative to a given path. * * If path = src/Resources/images * Pathname = src/Resources/images/subdir/image.png * Relativepath = subdir/image.png * * @param $path * @param SplFileInfo $file * @return mixed */ private function getRelativePath($path, SplFileInfo $file) { return str_replace($path, '', $file->getPath()); }
public function getPath() { return $this->fileInfo->getPath(); }