예제 #1
1
 /**
  * Get the file nesting path.
  *
  * @param \Symfony\Component\Finder\SplFileInfo $file
  * @param string                                $path
  *
  * @return string
  */
 protected function getNesting(SplFileInfo $file, string $path) : string
 {
     $directory = dirname($file->getRealPath());
     if ($tree = trim(str_replace($path, '', $directory), DIRECTORY_SEPARATOR)) {
         $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
     }
     return $tree;
 }
 /**
  * @dataProvider resourceProvider
  */
 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
     $OpenApi = JaneOpenApi::build();
     $files = $OpenApi->generate($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'swagger.json', 'Joli\\Jane\\OpenApi\\Tests\\Expected', $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     $OpenApi->printFiles($files, $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     // 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));
     foreach ($generatedFinder as $generatedFile) {
         $generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
     }
     foreach ($expectedFinder as $expectedFile) {
         $this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData);
         if ($expectedFile->isFile()) {
             $this->assertEquals(file_get_contents($expectedFile->getRealPath()), file_get_contents($generatedData[$expectedFile->getRelativePathname()]));
         }
     }
 }
예제 #3
0
 /**
  * Get the configuration file nesting path.
  *
  * @param  \Symfony\Component\Finder\SplFileInfo  $file
  * @return string
  */
 protected function getConfigurationNesting(SplFileInfo $file)
 {
     $directory = dirname($file->getRealPath());
     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;
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
0
 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;
 }
예제 #7
0
 /**
  * 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']);
 }
예제 #8
0
 /**
  * @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()));
         }
     }
 }
 /**
  * @dataProvider resourceProvider
  */
 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();
     $input = new ArrayInput(['--config-file' => $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . '.jane-openapi'], $command->getDefinition());
     $command->execute($input, 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));
     foreach ($generatedFinder as $generatedFile) {
         $generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
     }
     foreach ($expectedFinder as $expectedFile) {
         $this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData);
         if ($expectedFile->isFile()) {
             $expectedPath = $expectedFile->getRealPath();
             $actualPath = $generatedData[$expectedFile->getRelativePathname()];
             $this->assertEquals(file_get_contents($expectedPath), file_get_contents($actualPath), "Expected " . $expectedPath . " got " . $actualPath);
         }
     }
 }
예제 #10
0
 /**
  * Add a file into the phar package.
  *
  * @param Phar        $phar  Phar object
  * @param SplFileInfo $file  File to add
  * @param bool        $strip strip
  *
  * @return Compiler self Object
  */
 protected function addFile(Phar $phar, SplFileInfo $file, $strip = true)
 {
     $path = strtr(str_replace(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/');
     $content = $file->getContents();
     if ($strip) {
         $content = $this->stripWhitespace($content);
     } elseif ('LICENSE' === $file->getBasename()) {
         $content = "\n" . $content . "\n";
     }
     if ($path === 'src/Composer/Composer.php') {
         $content = str_replace('@package_version@', $this->version, $content);
         $content = str_replace('@release_date@', $this->versionDate, $content);
     }
     $phar->addFromString($path, $content);
     return $this;
 }
 /**
  * @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()));
 }
예제 #12
0
 /**
  * Registers a new theme from a directory.
  * @param \Symfony\Component\Finder\SplFileInfo $themeClassPath
  */
 protected function registerTheme(SplFileInfo $themeClassPath)
 {
     $themeName = preg_replace('/Theme\\.php$/', '', $themeClassPath->getFilename());
     $themeClass = sprintf('Ladybug\\Theme\\%s\\%sTheme', $themeName, $themeName);
     $themePath = dirname($themeClassPath->getRealPath());
     $this->container->register('theme_' . $themeName, $themeClass)->addArgument($themePath)->addTag('ladybug.theme');
 }
예제 #13
0
 /**
  * @return string
  */
 protected function getReversePathParts()
 {
     $path = trim($this->file->getRealPath(), DIRECTORY_SEPARATOR);
     $reversePath = implode(DIRECTORY_SEPARATOR, array_reverse(explode(DIRECTORY_SEPARATOR, $path)));
     return explode('content', $reversePath, 2);
 }
예제 #14
0
 /**
  * Get the configuration file nesting path.
  *
  * @param \Symfony\Component\Finder\SplFileInfo $file
  *
  * @return string
  */
 private function getConfigurationNesting(SplFileInfo $file)
 {
     $directory = dirname($file->getRealPath());
     $configPath = realpath($this->configPath());
     if ($tree = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) {
         $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
     }
     return $tree;
 }
예제 #15
0
 /**
  * Get Class Reflection Instance
  *
  * @access protected
  * @throws \LogicException
  * @param \Symfony\Component\Finder\SplFileInfo $file
  * @param string $namespace
  * @param string $suffix
  * @param string $parent
  * @param integer $allowedParameters
  * @return \Darsyn\ClassFinder\Reflection\ReflectionClass
  */
 protected function getClassReflection(SplFileInfo $file, $namespace, $suffix, $parent, $allowedParameters)
 {
     // Determine the fully-qualified class name of the found file.
     $class = preg_replace('#\\\\{2,}#', '\\', sprintf('%s\\%s\\%s', $namespace, strtr($file->getRelativePath(), '/', '\\'), $file->getBasename($this->extension)));
     // Make sure that the class name has the correct suffix.
     if (!empty($suffix) && substr($class, 0 - strlen($suffix)) !== $suffix) {
         throw new \LogicException(sprintf('The file found at "%s" does not end with the required suffix of "%s".', $file->getRealPath(), $suffix));
     }
     // We have to perform a few checks on the class before we can return it.
     // - It must be an actual class; not interface, abstract or trait types.
     // - For this to work the constructor must not have more than the expected number of required parameters.
     // - And finally make sure that the class loaded was actually loaded from the directory we found it in.
     //   TODO: Make sure that the final (file path) check doesn't cause problems with proxy classes or
     //         bootstraped/compiled class caches.
     $reflect = new ReflectionClass($class, $file->getRelativePath());
     if (is_object($construct = $reflect->getConstructor()) && $construct->getNumberOfRequiredParameters() > $allowedParameters || $reflect->isAbstract() || $reflect->isInterface() || $reflect->isTrait() || is_string($parent) && !empty($parent) && !$reflect->isSubclassOf($parent) || $reflect->getFileName() !== $file->getRealPath()) {
         throw new \LogicException(sprintf('The class definition for "%s" is invalid.', $class));
     }
     return $reflect;
 }
예제 #16
0
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (String::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
     }
     if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) {
         $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>');
     }
     $localPluginConfig = \file_get_contents($path);
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }
예제 #17
0
 /**
  * Get full path to image
  * @return string
  */
 public function getFullPath()
 {
     return $this->info->getRealPath();
 }
 public function getRealPath()
 {
     return $this->fileInfo->getRealPath();
 }
예제 #19
0
파일: TestRunner.php 프로젝트: phpbb/epv
 /**
  * Try to load and initialise a specific test.
  *
  * @param SplFileInfo $test
  *
  * @throws Exception\TestException
  */
 private function tryToLoadTest(SplFileInfo $test)
 {
     $this->output->writelnIfDebug("<info>Found {$test->getRealpath()}.</info>");
     $file = str_replace('.php', '', basename($test->getRealPath()));
     $class = '\\Phpbb\\Epv\\Tests\\Tests\\' . $file;
     $filetest = new $class($this->debug, $this->output, $this->basedir, $this->namespace, $this->titania, $this->directory);
     if (!$filetest instanceof TestInterface) {
         throw new TestException("{$class} does not implement the TestInterface, but matches the test expression.");
     }
     $this->tests[] = $filetest;
 }
 /**
  * Добавляет в загрузку один файл
  *
  * @param string $pathToFile путь к файлу из которого необходимо загрузить фикстуры
  *
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function fromFile($pathToFile)
 {
     if (empty($pathToFile)) {
         throw new \InvalidArgumentException("Был передан пустой путь к файлу с фикстурами");
     }
     if (!is_string($pathToFile)) {
         throw new \InvalidArgumentException("Параметр pathToFile не является строкой");
     }
     if (!file_exists($pathToFile)) {
         throw new \InvalidArgumentException("Был передан несуществующий путь к файлу '{$pathToFile}'");
     }
     $fileInfo = new \SplFileInfo($pathToFile);
     if ($fileInfo->getExtension() !== self::DEFAULT_FILE_EXTENSION) {
         throw new \InvalidArgumentException("Переданный файл '{$pathToFile}' обладает неправильным расширением");
     }
     $this->filePathsByKey[$fileInfo->getRealPath()] = true;
     return $this;
 }
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (BinaryString::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
         if ($path === "") {
             throw new \UnexpectedValueException(sprintf("Realpath for '%s' did return an empty string.", $file));
         }
         if ($path === false) {
             $this->_output->writeln(sprintf("<error>Plugin config file broken link '%s'</error>", $file));
             return;
         }
     }
     if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) {
         $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>');
     }
     $localPluginConfig = \file_get_contents($path);
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }
예제 #22
0
 protected function createPhpFileNode(SplFileInfo $fch)
 {
     return new PhpFile($fch->getRealPath(), $this->fileParser->parse($fch->getContents()));
 }
예제 #23
0
 function it_should_filter_by_date(SplFileInfo $file1, SplFileInfo $file2)
 {
     $file1->isFile()->willReturn(true);
     $file2->isFile()->willReturn(true);
     $file1->getRealPath()->willReturn($this->tempFile);
     $file2->getRealPath()->willReturn($this->tempFile);
     $file1->getMTime()->willReturn(strtotime('-4 hours'));
     $file2->getMTime()->willReturn(strtotime('-5 days'));
     $result = $this->date('since yesterday');
     $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\FilesCollection');
     $result->count()->shouldBe(1);
     $files = $result->toArray();
     $files[0]->shouldBe($file1);
 }
예제 #24
0
 /**
  * @param SplFileInfo $file
  */
 public function untouched(SplFileInfo $file)
 {
     $this->untouched[] = $file;
     $this->processed[] = $file;
     $this->output->writeln(sprintf('<fg=yellow>[=] %s</>', $file->getRealPath()), OutputInterface::VERBOSITY_VERY_VERBOSE);
 }
예제 #25
0
 /**
  * Checks the header of a single file
  *
  * @param SplFileInfo $file The file to check
  */
 private function checkFile(SplFileInfo $file)
 {
     $tokens = token_get_all($file->getContents());
     $licenseTokenIndex = $this->getLicenseTokenIndex($tokens);
     if ($licenseTokenIndex === null) {
         $this->log(sprintf('Missing license header in "%s"', $file->getRealPath()));
     } elseif ($tokens[$licenseTokenIndex][1] != $this->getLicenseAsComment()) {
         $this->log(sprintf('Different license header in "%s"', $file->getRealPath()));
     }
 }
예제 #26
0
 /**
  * run content modifiers on given file content.
  *
  * @param SplFileInfo $generatedFile
  * @param SplFileInfo $templateFile
  * @param array       $modifiers
  * @param Inflector   $inflector
  *
  * @return string
  */
 public function modify(SplFileInfo $generatedFile, SplFileInfo $templateFile, array $modifiers, Inflector $inflector)
 {
     foreach ($modifiers as $modifierAlias => $modifierData) {
         if ($modifier = $this->contentModifiers->get($modifierAlias)) {
             $this->filesystem->dumpFile($generatedFile->getRealPath(), $modifier->modify($generatedFile, is_array($modifierData) ? $modifierData : array(), $inflector, $templateFile));
         }
     }
 }
예제 #27
0
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (BinaryString::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
         if ($path === "") {
             throw new \UnexpectedValueException(sprintf("Realpath for '%s' did return an empty string.", $file));
         }
         if ($path === false) {
             $this->log(sprintf("<error>Plugin config file broken link '%s'</error>", $file));
             return;
         }
     }
     $this->logDebug('Load plugin config <comment>' . $path . '</comment>');
     $localPluginConfigFile = ConfigFile::createFromFile($path);
     $localPluginConfigFile->applyVariables($magentoRootFolder, $file);
     $this->_pluginConfig = $localPluginConfigFile->mergeArray($this->_pluginConfig);
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 public function shouldProcess(SplFileInfo $file)
 {
     return $this->analyzer->shouldProcessFile($file->getRealPath(), $file->getBasename());
 }
예제 #29
0
 /**
  * @param SplFileInfo $file
  * @throws SnapshotException
  */
 public function deleteSnapshot(SplFileInfo $file)
 {
     try {
         $this->removeFile($file->getRealPath());
     } catch (IOExceptionInterface $e) {
         throw new SnapshotException("File couldn't be deleted, {$e->getMessage()}", $e->getCode(), $e);
     }
 }
예제 #30
-1
 /**
  * @param SplFileInfo[] $fileList
  * @param string        $basePath
  *
  * @return string
  */
 public function mergeFiles($fileList, $basePath)
 {
     $imagePath = str_replace(dirname(RMP_MDOC_BASE_DIR), '', $basePath);
     $contents = '';
     foreach ($fileList->files() as $singleFile) {
         if (false == $singleFile instanceof SplFileInfo) {
             $singleFile = new SplFileInfo($singleFile->getRealPath(), $basePath, $basePath);
         }
         $this->setCurrentFile($singleFile);
         /** @var SplFileInfo $singleFile */
         $buffer = $singleFile->getContents() . PHP_EOL . PHP_EOL;
         $depth = max(0, substr_count(str_replace($basePath, '', $singleFile->getRealPath()), '/') - 1);
         $directory = $singleFile->getPath() . '/' . $singleFile->getBasename('.md');
         if (is_dir($directory)) {
             $featureFinder = new Finder();
             $featureFinder->in($directory)->name('*.feature')->depth(0);
             foreach ($featureFinder->files() as $feature) {
                 $buffer .= $this->parseFeature($feature);
             }
         }
         $link = ltrim('http://' . $_SERVER['HTTP_HOST'] . str_replace($_SERVER['DOCUMENT_ROOT'], '', $singleFile->getPath() . '/') . '/', '/');
         $buffer = str_replace('](./', '](' . $link, $buffer);
         // in between
         $buffer = str_replace("\n#", "\n#" . str_repeat('#', $depth), $buffer);
         // in beginning
         $buffer = preg_replace('/^#/', str_repeat('#', $depth + 1), $buffer);
         $buffer = preg_replace_callback('/\\s@import "([^"]*)"\\s/s', [$this, 'replaceFileImports'], $buffer);
         $contents .= $buffer;
     }
     return $contents;
 }