Example #1
0
 /**
  * Finds all theme route files and adds the routes to the RouteCollection.
  *
  * @return void
  */
 private function discoverRoutes()
 {
     // Where are our routes located?
     $parentRoutes = $this->config->paths->theme->parent->routes;
     $childRoutes = $this->config->paths->theme->child->routes;
     $files = $this->finder->createFinder()->files()->name('*.php')->in($parentRoutes);
     if ($parentRoutes != $childRoutes && is_dir($childRoutes)) {
         $files = $files->in($childRoutes);
     }
     // Collect all the files
     $splFiles = [];
     foreach ($files as $file) {
         $splFiles[] = $file;
     }
     // Now we need to sort them ourselves because it seems Finder's
     // sortByName(), only sorts per in('dir') and not across the
     // entire list.
     $orderedFiles = Linq::from($splFiles)->orderBy('$v', function ($a, $b) {
         return strnatcasecmp($a->getBasename('.php'), $b->getBasename('.php'));
     });
     // Finally lets add some routes.
     foreach ($orderedFiles as $file) {
         $route = import($file->getRealPath(), ['route' => $this->routes]);
         if (is_callable($route)) {
             $this->container->call($route, ['config' => $this->config]);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function refresh(SourceSet $sourceSet)
 {
     if (!is_dir($this->sourceDir)) {
         return;
     }
     $sinceTimeLast = $this->sinceTime;
     $this->sinceTime = date('c');
     // We regenerate the whole site if any config file changes.
     $configFilesHaveChanged = false;
     $files = $this->finderFactory->createFinder()->files()->name('sculpin_site*.yml')->date('>=' . $sinceTimeLast)->in($this->sourceDir);
     $sinceTimeLastSeconds = strtotime($sinceTimeLast);
     foreach ($files as $file) {
         if ($sinceTimeLastSeconds > $file->getMTime()) {
             // This is a hack because Finder is actually incapable
             // of resolution down to seconds.
             //
             // Sometimes this may result in the file looking like it
             // has been modified twice in a row when it has not.
             continue;
         }
         $configFilesHaveChanged = true;
         break;
     }
     if ($configFilesHaveChanged) {
         $newConfig = $this->siteConfigurationFactory->create();
         $this->siteConfiguration->import($newConfig);
         // If any of the config files have changed we should
         // mark all of the sources as having changed.
         foreach ($sourceSet->allSources() as $source) {
             $source->setHasChanged();
         }
     }
 }
Example #3
0
 /**
  * Creates an array of file paths that contain middleware.
  *
  * The middleware files are hierarchical, allowing the child theme to
  * override any middleware that we provide by default. The array is also
  * sorted by filename. So the child theme can "insert" it's middleware
  * in the desired order.
  *
  * @return array
  */
 private function buildQueue()
 {
     $queue = [];
     // Where is our middleware located?
     $parentMiddleware = $this->config->paths->theme->parent->middleware;
     $childMiddleware = $this->config->paths->theme->child->middleware;
     // Loop through our middleware files
     foreach ($this->finder->createFinder()->files()->name('*.php')->in($parentMiddleware) as $file) {
         if ($this->kernel->childHasMiddleware()) {
             // Only register one of our middleware files if the
             // child theme does not have the same middleware file.
             if (!file_exists(str_replace($parentMiddleware, $childMiddleware, $file))) {
                 $queue[] = $file;
             }
         } else {
             $queue[] = $file;
         }
     }
     // Now lets loop through the child theme middleware files.
     if ($this->kernel->childHasMiddleware()) {
         foreach ($this->finder->createFinder()->files()->name('*.php')->in($childMiddleware) as $file) {
             $queue[] = $file;
         }
     }
     // Ensure the middleware queue is sorted.
     return Linq::from($queue)->orderBy('$v')->toArray();
 }
 /**
  * {@inheritdoc}
  */
 public function refresh(SourceSet $sourceSet)
 {
     $sinceTimeLast = $this->sinceTime;
     $this->sinceTime = date('c');
     // We regenerate the whole site if an excluded file changes.
     $excludedFilesHaveChanged = false;
     $files = $this->finderFactory->createFinder()->files()->ignoreVCS(true)->ignoreDotFiles(false)->date('>=' . $sinceTimeLast)->followLinks()->in($this->sourceDir);
     $sinceTimeLastSeconds = strtotime($sinceTimeLast);
     foreach ($files as $file) {
         if ($sinceTimeLastSeconds > $file->getMTime()) {
             // This is a hack because Finder is actually incapable
             // of resolution down to seconds.
             //
             // Sometimes this may result in the file looking like it
             // has been modified twice in a row when it has not.
             continue;
         }
         foreach ($this->ignores as $pattern) {
             if (!$this->matcher->isPattern($pattern)) {
                 continue;
             }
             if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) {
                 // Ignored files are completely ignored.
                 continue 2;
             }
         }
         foreach ($this->excludes as $pattern) {
             if (!$this->matcher->isPattern($pattern)) {
                 continue;
             }
             if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) {
                 $excludedFilesHaveChanged = true;
                 continue 2;
             }
         }
         $isRaw = false;
         foreach ($this->raws as $pattern) {
             if (!$this->matcher->isPattern($pattern)) {
                 continue;
             }
             if ($this->matcher->match($pattern, $this->directorySeparatorNormalizer->normalize($file->getRelativePathname()))) {
                 $isRaw = true;
                 break;
             }
         }
         $source = new FileSource($this->analyzer, $this, $file, $isRaw, true);
         $sourceSet->mergeSource($source);
     }
     if ($excludedFilesHaveChanged) {
         // If any of the exluded files have changed we should
         // mark all of the sources as having changed.
         foreach ($sourceSet->allSources() as $source) {
             $source->setHasChanged();
         }
     }
 }
 /**
  * Returns the iterator to be used as the inner iterator
  *
  * @return \Iterator
  */
 public function getIterator()
 {
     if (is_null($this->iterator)) {
         $finder = $this->finderFactory->createFinder();
         $finder->files()->in($this->path);
         if (false === empty($this->extensions)) {
             $finder->name($this->getExtensionsRegex());
         }
         $this->iterator = $finder->getIterator();
     }
     return $this->iterator;
 }
Example #6
0
 /** @inheritdoc */
 public function boot()
 {
     // Where are our hooks located?
     $parentHooks = $this->config->paths->theme->parent->hooks;
     $childHooks = $this->config->paths->theme->child->hooks;
     // Loop through our hook files
     foreach ($this->finder->createFinder()->files()->name('*.php')->in($parentHooks) as $file) {
         if ($this->childHasHooks()) {
             // Only register one of our hooks if the child theme
             // does not have the same hook file.
             if (!file_exists(str_replace($parentHooks, $childHooks, $file))) {
                 $this->registerHook($file);
             }
         } else {
             $this->registerHook($file);
         }
     }
     // Now lets loop through the child theme hooks
     if ($this->childHasHooks()) {
         foreach ($this->finder->createFinder()->files()->name('*.php')->in($childHooks) as $file) {
             $this->registerHook($file);
         }
     }
 }