예제 #1
0
 /**
  * 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";
         }
     }
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * @param SplFileInfo $fileInfo
  *
  * @todo make it event driven
  *
  * @return mixed|string
  *
  */
 protected function parseFeature($fileInfo)
 {
     $feature = $fileInfo->getContents();
     $scenarios = explode('Szenario:', $feature);
     $feature = array_shift($scenarios);
     $lines = explode(PHP_EOL, $feature);
     if (0 === strpos($feature, '#')) {
         array_shift($lines);
     }
     $title = array_shift($lines);
     $title = str_replace('Funktionalität: ', '## ', $title);
     $userStory = trim(implode(PHP_EOL, $lines));
     $userStory = preg_replace('/\\n[\\s]*/', "\n", $userStory);
     $imageFile = $fileInfo->getPath() . '/' . $fileInfo->getBasename('.feature') . '.png';
     $output = $title . PHP_EOL . PHP_EOL;
     $output .= $userStory . PHP_EOL . PHP_EOL;
     if (is_readable($imageFile)) {
         $output .= '![' . basename($imageFile, '.png') . '](./' . $fileInfo->getRelativePath() . basename($fileInfo->getPath()) . '/' . basename($imageFile) . ')' . PHP_EOL . PHP_EOL;
     }
     foreach ($scenarios as $scenario) {
         $scenario = trim($scenario);
         if (!$scenario) {
             continue;
         }
         $output .= $this->parseScenario($scenario, $fileInfo);
     }
     return $output;
 }
예제 #4
0
 /**
  * @param SplFileInfo $composerJsonFile
  * @param array $bundles
  *
  * @return bool
  */
 protected function shouldSkip(SplFileInfo $composerJsonFile, array $bundles)
 {
     if (!$bundles) {
         return false;
     }
     $folder = $composerJsonFile->getRelativePath();
     return !in_array($folder, $bundles);
 }
예제 #5
0
 /**
  * __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;
 }
예제 #6
0
파일: BaseHandler.php 프로젝트: tao/orca
 /**
  * Generate directory path to be used for the file pretty name.
  *
  * @return string
  */
 protected function getDirectoryPrettyName()
 {
     $fileBaseName = $this->getFileName();
     $fileRelativePath = $this->normalizePath($this->file->getRelativePath());
     if (in_array($this->file->getExtension(), ['php', 'md']) && $fileBaseName != 'index') {
         $fileRelativePath .= $fileRelativePath ? "/{$fileBaseName}" : $fileBaseName;
     }
     return ORCA_PUBLIC_DIR . ($fileRelativePath ? "/{$fileRelativePath}" : '');
 }
예제 #7
0
 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'];
 }
예제 #8
0
 /**
  * __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);
 }
 /**
  * @Route("/file_manager/delete-folder", name="spliced_cms_admin_file_manager_delete_folder")
  * @Template()
  */
 public function deleteFolderAction()
 {
     $this->loadContext();
     if (!$this->dir instanceof \SplFileInfo || !$this->dir->getRealPath() || !$this->file->isDir()) {
         $this->get('session')->getFlashBag()->add('error', 'Directory Not Found');
         return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager', array('dir' => $this->dir->getRelativePath())));
     }
     $fs = new Filesystem();
     $success = false;
     try {
         $fs->remove($this->dir->getRealPath());
         $this->get('session')->getFlashBag()->add('success', 'File Deleted');
         $success = true;
     } catch (\IOException $e) {
         $this->get('session')->getFlashBag()->add('error', 'Could Not Delete Folder');
     }
     return $this->redirect($this->generateUrl('spliced_cms_admin_file_manager', array('dir' => $success ? $this->baseDir->getRelativePath() : $this->dir->getRelativePath())));
 }
 /**
  * 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());
     }
 }
예제 #11
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();
     }
 }
예제 #12
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();
     }
 }
 public function getRelativePath()
 {
     return $this->fileInfo->getRelativePath();
 }
예제 #14
0
 /**
  * @param array $composerJson
  * @param \Symfony\Component\Finder\SplFileInfo $composerJsonFile
  *
  * @return array
  */
 public function update(array $composerJson, SplFileInfo $composerJsonFile)
 {
     $bundleName = $composerJsonFile->getRelativePath();
     $composerJson[self::KEY_DESCRIPTION] = $bundleName . ' bundle';
     return $composerJson;
 }
 /**
  * @param \Symfony\Component\Finder\SplFileInfo $composerJsonFile
  * @param string $bundleName
  *
  * @return bool
  */
 protected function shouldSkip(SplFileInfo $composerJsonFile, $bundleName)
 {
     $folder = $composerJsonFile->getRelativePath();
     return $folder !== $bundleName;
 }
예제 #16
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;
 }
 /**
  * @param SplFileInfo $file
  *
  * @return self
  */
 public static function create(SplFileInfo $file)
 {
     return new static($file->getPathname(), $file->getRelativePath(), $file->getRelativePathname());
 }
예제 #18
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}";
 }