/**
  * 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;
 }
예제 #2
0
 public function __construct(SplFileInfo $file)
 {
     $this->file = $file;
     $this->path = str_replace('\\', '/', $file->getRelativePath());
     $this->filename = $file->getFilename();
     $this->package = $file->getBasename('.zip');
     $this->version = 'dev-unknown';
     list($this->type, $this->vendor) = explode('/', $this->path);
     $matches = $this->parseFilename($this->filename);
     if (!empty($matches)) {
         $this->package = $matches['package'];
         $this->version = $matches['version'];
     }
 }
예제 #3
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;
 }
 /**
  * Load a single generator into the registry.
  * @param SplFileInfo $file
  * @param string      $ns
  */
 private function loadGeneratorInBundle(SplFileInfo $file, $ns)
 {
     if ($relativePath = $file->getRelativePath()) {
         $ns .= '\\' . strtr($relativePath, '/', '\\');
     }
     $class = $ns . '\\' . $file->getBasename('.php');
     // if an alias of the generator exists, skip this one
     if ($this->container) {
         $alias = 'tweedegolf_generator.generator.' . strtolower(str_replace('\\', '_', $class));
         if ($this->container->has($alias)) {
             return;
         }
     }
     // add the generator through reflection
     $r = new \ReflectionClass($class);
     if ($r->isSubclassOf('TweedeGolf\\Generator\\GeneratorInterface') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) {
         $this->addGenerator($r->newInstance());
     }
 }
예제 #5
0
 /**
  * Constructor.
  *
  * @param null|SplFileInfo $file
  */
 public function __construct(SplFileInfo $file = null)
 {
     $this->file = $file;
     if ($this->file instanceof SplFileInfo) {
         // file extension: "md"
         $this->fileExtension = pathinfo($this->file, PATHINFO_EXTENSION);
         // file path: "Blog"
         $this->filePath = str_replace(DIRECTORY_SEPARATOR, '/', $this->file->getRelativePath());
         // file id: "Blog/Post 1"
         $this->fileId = ($this->filePath ? $this->filePath . '/' : '') . basename($this->file->getBasename(), '.' . $this->fileExtension);
         /*
          * variables default values
          */
         // id - ie: "blog/post-1"
         $this->id = $this->urlize($this->fileId);
         // pathname - ie: "blog/post-1"
         $this->pathname = $this->urlize($this->fileId);
         // path - ie: "blog"
         $this->path = $this->urlize($this->filePath);
         // name - ie: "post-1"
         $this->name = $this->urlize(basename($this->file->getBasename(), '.' . $this->fileExtension));
         /*
          * front matter default values
          */
         // title - ie: "Post 1"
         $this->setTitle(basename($this->file->getBasename(), '.' . $this->fileExtension));
         // section - ie: "blog"
         $this->setSection(explode('/', $this->path)[0]);
         // date
         $this->setDate(filemtime($this->file->getPathname()));
         // permalink
         $this->setPermalink($this->pathname);
         parent::__construct($this->id);
     } else {
         $this->virtual = true;
         parent::__construct();
     }
 }
예제 #6
0
 /**
  * @param \Symfony\Component\Finder\SplFileInfo $fileInfo
  * @return string
  */
 protected function getQualifiedName(SplFileInfo $fileInfo)
 {
     if (!preg_match('/namespace (.+?);/', $fileInfo->getContents(), $match)) {
         return null;
     }
     return $match[1] . '\\' . $fileInfo->getBasename('.php');
 }
예제 #7
0
 /**
  * Returns filename w/o extension
  *
  * @return string
  */
 public function getFilename()
 {
     $exclude = '.' . $this->file->getExtension();
     return $this->file->getBasename($exclude);
 }
예제 #8
0
 /**
  * Gets the class name.
  *
  * @param \Symfony\Component\Finder\SplFileInfo $file
  *
  * @return string
  */
 protected function getClassname(SplFileInfo $file)
 {
     if ($file->getExtension() === 'php') {
         return $file->getBasename('.php');
     }
     if ($file->getFilename() === $this->composerFilename) {
         $composerData = $this->readComposerFile($file);
         if (isset($composerData['extra']['spress_class']) === true && is_string($composerData['extra']['spress_class'])) {
             return $composerData['extra']['spress_class'];
         }
     }
     return '';
 }
예제 #9
0
 /**
  * Load and parse content from file.
  *
  * @param  SplFileInfo $file
  * @return void
  */
 protected function load(SplFileInfo $file)
 {
     // File info
     $this->filename = $file->getBasename();
     $this->sourcePath = $file->getRelativePath();
     // Load the file
     $data = $file->getContents();
     list($content, $meta) = $this->splitContentMeta($data);
     // Parse meta
     $meta = Yaml::parse($meta) ?: [];
     // Parse content
     switch ($file->getExtension()) {
         case 'md':
         case 'markdown':
             $content = Markdown::parse($content);
             $this->type = self::TYPE_MARKDOWN;
             break;
         case 'tx':
         case 'textile':
             $content = Textile::parse($content);
             $this->type = self::TYPE_TEXTILE;
             break;
     }
     // Set content
     $this->content = $content;
     $this->meta = $meta;
     // Ensure local URLs are absolute
     foreach ($this->meta as $key => $value) {
         if (preg_match('/\\burl\\b|.*_url\\b/', $key)) {
             $this->meta[$key] = $this->builder->getUrl($value);
         }
     }
     // Set target
     $this->setTarget($file);
     // Pagination enabled
     $this->paginate = isset($this->meta['paginate']);
     // Get parent page
     if ($root = dirname(dirname($this->target))) {
         if ($root !== DIRECTORY_SEPARATOR) {
             $this->parentId = ltrim($root, '/');
         }
     }
     // Set URL
     $this->url = '/' . trim(str_replace([DIRECTORY_SEPARATOR, '//'], ['/', '/'], $this->target), '/');
     // Remove "index.html" from the end, this provides a cleaner URL
     if (substr($this->url, -10) === 'index.html') {
         $this->url = substr($this->url, 0, -10);
     }
     // Set basic values
     $this->id = trim($this->url, '/') ?: 'root';
     $this->title = $this->get('title');
     $this->url = $this->builder->getUrl($this->url);
     // Set Description
     if ($this->has('description')) {
         $this->description = $this->get('description');
     } else {
         $this->description = $this->getDescription();
     }
 }
예제 #10
0
 /**
  * Проверяет является ли класс миграцией.
  * @param SplFileInfo $file файл
  * @return bool|IMigration
  */
 protected function isMigration(SplFileInfo $file)
 {
     require_once $file->getPathname();
     $className = $file->getBasename('.php');
     $migration = new $className();
     if (!$migration instanceof IMigration) {
         return false;
     }
     return $migration;
 }
 public function getBasename($suffix = null)
 {
     return $this->fileInfo->getBasename($suffix);
 }
예제 #12
0
 /**
  * 获取图像文件保存路径
  * @param SplFileInfo $fileInfo
  * @return string
  */
 protected function getImageSavePath(SplFileInfo $fileInfo)
 {
     return $this->savePath . '/' . $fileInfo->getBasename(true);
 }
예제 #13
0
 /**
  * @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;
 }
예제 #14
0
 /**
  * Extract all strings from a given file.
  *
  * @param SplFileInfo $file
  *
  * @return string[]
  */
 protected function extractStringTokens(SplFileInfo $file)
 {
     // Fetch tokens from cache if available
     $hash = 'janitor.tokens.' . md5($file->getPathname()) . '-' . $file->getMTime();
     return $this->cache->rememberForever($hash, function () use($file) {
         $contents = $file->getContents();
         // See if we have an available Tokenizer
         // and use it to extract the contents
         switch ($file->getExtension()) {
             case 'php':
                 $tokenizer = strpos($file->getBasename(), 'blade.php') !== false ? new BladeTokenizer() : new PhpTokenizer();
                 break;
             case 'twig':
                 $tokenizer = new TwigTokenizer();
                 break;
             case 'json':
                 $tokenizer = new JsonTokenizer();
                 break;
             case 'yml':
             case 'yaml':
                 $tokenizer = new YamlTokenizer();
                 break;
             case 'xml':
                 $tokenizer = new XmlTokenizer();
                 break;
             default:
                 $tokenizer = new DefaultTokenizer();
                 break;
         }
         return $tokenizer->tokenize($contents);
     });
 }
예제 #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
 /**
  * {@inheritdoc}
  */
 public function shouldProcess(SplFileInfo $file)
 {
     return $this->analyzer->shouldProcessFile($file->getRealPath(), $file->getBasename());
 }
예제 #17
0
 public function getBuildPath($buildDir, Mixer $mixer, SplFileInfo $file)
 {
     $ext = $mixer->getOutputExtension();
     if (!$ext) {
         $ext = $file->getExtension();
     }
     $path = $file->getRelativePath();
     $filename = $file->getBasename("." . $file->getExtension());
     $build = $buildDir . "/" . $path;
     if (!$this->files->exists($build)) {
         $this->files->makeDirectory($build, 0755, true);
     }
     return "{$build}/{$filename}.{$ext}";
 }