예제 #1
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()));
         }
     }
 }
 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;
 }
예제 #3
0
파일: Processor.php 프로젝트: carew/carew
 public function processFile(SplFileInfo $file, $folder = '', $type = Document::TYPE_UNKNOWN)
 {
     $internalPath = trim($folder . '/' . $file->getRelativePathname(), '/');
     $document = new Document($file, $internalPath, $type);
     $event = new CarewEvent($document);
     try {
         return $this->eventDispatcher->dispatch(Events::DOCUMENT_HEADER, $event)->getSubject();
     } catch (\Exception $e) {
         throw new \LogicException(sprintf('Could not process "%s": "%s".', $file->getRelativePathname(), $e->getMessage()), 0, $e);
     }
 }
예제 #4
0
파일: Bucket.php 프로젝트: arvinkx/git-s3
 public function upload(File $file, $metaData)
 {
     try {
         if ($metaData['Content-Encoding']) {
             $this->client->putObject(array('Bucket' => $this->name, 'Key' => $file->getRelativePathname(), 'SourceFile' => $file->getRealpath(), 'ACL' => CannedAcl::PUBLIC_READ, 'ContentEncoding' => $metaData['Content-Encoding']));
         } else {
             $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.");
     }
 }
예제 #5
0
 /**
  * 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();
 }
예제 #6
0
 /**
  * Create sprite image data holder
  * @param string $path
  * @param SplFileInfo $fileInfo
  */
 public function __construct($path, SplFileInfo $fileInfo)
 {
     $this->basePath = $path;
     $this->info = $fileInfo;
     // Assign fileinfo variables
     $this->path = $this->info->getPathname();
     $this->size = $this->info->getSize();
     // Assign image data
     $info = getimagesize($this->path);
     if (!is_array($info)) {
         throw new UnexpectedValueException("The image '{$this->path}' is not a correct image format.");
     }
     $this->hash = sha1(file_get_contents($this->getFullPath()));
     $this->width = (int) $info[0];
     $this->height = (int) $info[1];
     $this->mime = $info['mime'];
     $this->type = explode('/', $this->mime)[1];
     // Assign css name
     $ext = $this->info->getExtension();
     // Replace path parts with `-`
     $name = str_replace(['/', '\\', '_'], '-', $this->info->getRelativePathname());
     // Remove leading `-`
     $name = preg_replace('~^-*~', '', $name);
     // Remove double dashes
     $name = preg_replace('~-+~', '-', $name);
     // Remove file extension
     $name = preg_replace("~\\.{$ext}\$~", '', $name);
     // Replace dots with -
     $name = preg_replace('~\\.~', '-', $name);
     $this->name = $name;
 }
예제 #7
0
 /**
  * @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);
 }
예제 #8
0
 /**
  * Because SplFileInfo can't be serialized, we need to replace it with data that can be recovered when we serialize
  * this object again.
  *
  * @return array
  */
 public function __sleep()
 {
     $fileInfo = ['file' => $this->file->getPathname(), 'relativePath' => $this->file->getRelativePath(), 'relativePathname' => $this->file->getRelativePathname()];
     $classVars = get_object_vars($this);
     $this->file = $fileInfo;
     return array_keys($classVars);
 }
예제 #9
0
 private function uploadFile(File $file)
 {
     if ($file->getFilename() == 'config.yml') {
         return;
     }
     $this->output->writeln('Uploading ' . $file->getRelativePathname());
     $this->bucket->upload($file);
 }
예제 #10
0
 /**
  * @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;
 }
예제 #11
0
 private function uploadFile(File $file)
 {
     // Check if isCompressed was passed and if
     // the file is a JS or CSS file add the
     // correct content encoding
     $ext = pathinfo($file->getRelativePathname(), PATHINFO_EXTENSION);
     $metaData = array();
     if (($ext == "js" || $ext == "css" || $ext == 'json') && $this->isCompressed) {
         $metaData['Content-Encoding'] = 'gzip';
         if ($ext == "js") {
             $metaData['Content-Type'] = 'text/javascript';
         } else {
             $metaData['Content-Type'] = 'text/css';
         }
     }
     $this->output->writeln('Uploading ' . $file->getRelativePathname());
     $this->bucket->upload($file, $metaData);
 }
예제 #12
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;
 }
예제 #13
0
 function it_should_filter_by_not_path(SplFileInfo $file1, SplFileInfo $file2)
 {
     $file1->getRelativePathname()->willReturn('path1/file.php');
     $file2->getRelativePathname()->willReturn('path2/file.png');
     $result = $this->notPath('path2');
     $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\FilesCollection');
     $result->count()->shouldBe(1);
     $files = $result->toArray();
     $files[0]->shouldBe($file1);
 }
 /**
  * loadContext
  *
  * @return array
  */
 private function loadContext()
 {
     $this->files = new Finder();
     $this->baseDir = new SplFileInfo($this->get('spliced_cms.site_manager')->getCurrentAdminSite()->getRootDir(), '/', '/');
     if ($this->get('request')->query->has('dir')) {
         $path = $this->baseDir->getRealPath() . '/' . $this->get('request')->query->get('dir');
         $relativePath = preg_replace('/\\/{2,}/', '/', str_replace($this->baseDir->getRealPath(), '', $path));
         $this->dir = new SplFileInfo($path, $relativePath, $relativePath);
     } else {
         $this->dir = $this->baseDir;
     }
     $this->files->followLinks()->depth(0)->in($this->dir->getRealPath());
     $this->file = null;
     if ($this->get('request')->query->has('file') && $this->get('request')->query->get('file')) {
         $this->file = new SplFileInfo($this->dir->getRealPath() . '/' . $this->get('request')->query->get('file'), $this->dir->getRelativePath() . '/' . $this->get('request')->query->get('file'), $this->dir->getRelativePathname());
     }
     $this->loaded = true;
     return $this;
 }
예제 #15
0
 /**
  * @param SplFileInfo   $file
  * @param string        $classPrefix
  * @param string        $group
  * @return string
  */
 protected function getClassIdentifier(SplFileInfo $file, $classPrefix, $group = '')
 {
     $path = str_replace('.php', '', $file->getRelativePathname());
     $path = str_replace('\\', '/', $path);
     $parts = explode('/', $path);
     $parts = array_map('lcfirst', $parts);
     if ($path == 'Data' && $group == 'helpers') {
         array_pop($parts);
     }
     return rtrim($classPrefix . '/' . implode('_', $parts), '/');
 }
예제 #16
0
 protected function checkUniqueness(ThemeInterface $theme, SplFileInfo $themeFile, InputInterface $input, OutputInterface $output)
 {
     $parentDirectory = $theme->getTemplateDirectories(true);
     $parentFile = $parentDirectory . '/' . $themeFile->getRelativePathname();
     if ($this->compareFiles($themeFile, $parentFile)) {
         $question = sprintf('<question>"%s" is the same as the template in the <info>%s</info> theme, would you like to remove it from your current theme?</question>', $themeFile->getRelativePathname(), $theme->getName());
         if ($this->getHelper('dialog')->askConfirmation($output, $question, false)) {
             $this->getFilesystem()->remove($themeFile);
             $output->writeln('Removed ' . $themeFile);
             $output->writeln('');
         }
     }
     if ($theme->getParentTheme()) {
         $this->checkUniqueness($theme->getParentTheme(), $themeFile, $input, $output);
     }
 }
 /**
  * @param SplFileInfo $file
  *
  * @return IntegrationCase
  */
 public function create(SplFileInfo $file)
 {
     try {
         if (!preg_match('/^
                         --TEST--           \\r?\\n(?<title>          .*?)
                    \\s   --RULESET--        \\r?\\n(?<ruleset>        .*?)
                 (?:\\s   --CONFIG--         \\r?\\n(?<config>         .*?))?
                 (?:\\s   --SETTINGS--       \\r?\\n(?<settings>       .*?))?
                 (?:\\s   --REQUIREMENTS--   \\r?\\n(?<requirements>   .*?))?
                 (?:\\s   --EXPECT--         \\r?\\n(?<expect>         .*?\\r?\\n*))?
                 (?:\\s   --INPUT--          \\r?\\n(?<input>          .*))?
             $/sx', $file->getContents(), $match)) {
             throw new \InvalidArgumentException('File format is invalid.');
         }
         $match = array_merge(array('config' => null, 'settings' => null, 'requirements' => null, 'expect' => null, 'input' => null), $match);
         return new IntegrationCase($file->getRelativePathname(), $match['title'], $this->determineSettings($match['settings']), $this->determineRequirements($match['requirements']), $this->determineConfig($match['config']), $this->determineRuleset($match['ruleset']), $this->determineExpectedCode($match['expect'], $file), $this->determineInputCode($match['input'], $file));
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('%s Test file: "%s".', $e->getMessage(), $file->getRelativePathname()), $e->getCode(), $e);
     }
 }
예제 #18
0
 /**
  * Copy a path to destination, check if file,directory or link
  * @param string $source      The Source File
  * @param string $destination The Destination File
  * @return boolean
  */
 public function copy(\Symfony\Component\Finder\SplFileInfo $source, $destination)
 {
     $new_path = $destination . DIRECTORY_SEPARATOR . $source->getRelativePathname();
     #Test if Source is a link
     if ($source->isLink()) {
         return symlink($source, $new_path);
     }
     # Test if source is a directory
     if ($source->isDir()) {
         return mkdir($new_path);
     }
     #Test if Source is a file
     if ($source->isFile()) {
         return copy($source, $new_path);
     }
     return FALSE;
 }
예제 #19
0
 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++;
     }
 }
 /**
  * @param SplFileInfo $file
  *
  * @return self
  */
 public static function create(SplFileInfo $file)
 {
     return new static($file->getPathname(), $file->getRelativePath(), $file->getRelativePathname());
 }
 /**
  * @param SplFileInfo $file
  *
  * @return string
  */
 private function createLegacyRouteName(SplFileInfo $file)
 {
     return 'basster.legacy.' . str_replace('/', '__', substr($file->getRelativePathname(), 0, -4));
 }
 /**
  * Check whether a file shoud be published
  *
  * @param  \Symfony\Component\Finder\SplFileInfo	$file
  */
 public function shouldPublish($file)
 {
     foreach ($this->publisher->excludes as $key) {
         if (preg_match($key, $file->getRelativePathname())) {
             return false;
         }
     }
     return true;
 }
예제 #23
0
 private function uploadFile(File $file)
 {
     $this->output->writeln('Uploading ' . $file->getRelativePathname());
     $this->bucket->upload($file);
 }
예제 #24
0
 function it_should_filter_by_callback(SplFileInfo $file1, SplFileInfo $file2)
 {
     $file1->getRelativePathname()->willReturn('path1/file.php');
     $file2->getRelativePathname()->willReturn('path2/file.png');
     $result = $this->filter(function (SplFileInfo $file) {
         return $file->getRelativePathname() === 'path1/file.php';
     });
     $result->shouldBeAnInstanceOf(FilesCollection::class);
     $result->count()->shouldBe(1);
     $files = $result->toArray();
     $files[0]->shouldBe($file1);
 }
 private function doRunLegacyScript()
 {
     $streamedResponse = $this->controller->runLegacyScript($this->legacyFile->getPathname(), $this->legacyFile->getRelativePathname());
     self::assertInstanceOf('Symfony\\Component\\HttpFoundation\\StreamedResponse', $streamedResponse);
     $streamedResponse->sendContent();
 }
예제 #26
0
파일: BaseHandler.php 프로젝트: tao/orca
 /**
  * Get the path of the view.
  *
  * @return string
  */
 protected function getViewPath()
 {
     return str_replace(['.blade.php', '.md'], '', $this->file->getRelativePathname());
 }
 public function getRelativePathname()
 {
     return $this->fileInfo->getRelativePathname();
 }
예제 #28
0
 /**
  * transform
  *
  * @param File $entity
  * @param SplFileInfo $file
  * @access private
  * @return File
  */
 private function transform(File $entity, SplFileInfo $file)
 {
     return $entity->setPathname($file->getRelativePathname())->setName($file->getFilename());
 }