Пример #1
0
 /**
  * Get the fully qualified location of the view.
  *
  * Just returns $view if $view is in the database, otherwise throws an
  * exception.
  *
  * @param  string  $view
  * @return string
  */
 public function find($view)
 {
     // Check to see if the page exists in the database
     $vpage = Vpage::make($view);
     if (!empty($vpage)) {
         return $view . Vpage::EXTENSION_SEPARATOR . $vpage->pagetype;
     }
     throw new InvalidArgumentException("View [{$view}] not found in vpage table.");
 }
Пример #2
0
 /**
  * Gets the source code of a template, given its name.
  *
  * @param string $name The name of the template to load
  *
  * @return string The template source code
  *
  * @throws Twig_Error_Loader When $name is not found
  */
 public function getSource($name)
 {
     // Fetch the view from the database.
     $viewModel = Vpage::make($name);
     // If it is found return its content.
     if (!empty($viewModel)) {
         return $viewModel->content;
     }
     throw new Twig_Error_Loader('unable to locate page ' . $name);
 }
Пример #3
0
 /**
  * Return the last modified timestamp of a view.
  *
  * @param string $name
  * @return integer
  */
 public function lastModified($name)
 {
     // Fetch the view from the database.
     $viewModel = Vpage::make($name);
     // If it is found return its last modified time as a timestamp.
     if (!empty($viewModel)) {
         $dt = new \DateTime($viewModel->updated_at);
         return $dt->format('U');
     }
     throw new InvalidArgumentException('unable to locate page ' . $name);
 }
Пример #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Sample page directory
     $topdir = $this->getBasePath();
     foreach (scandir($topdir) as $dirname) {
         // Read all of the files and directories under the top level directory.
         if ($dirname == '.' || $dirname == '..') {
             continue;
         }
         // If it's a file, load it directly.
         // As of Laravel v5.1.32 someone made a change:
         // https://github.com/laravel/framework/commit/70e504da5ad395d87467826e528dc9edf3f36ef3
         // Means that pages must have the "." as part of the page type.  If you are on a prior
         // version of Laravel you can remove the "." from in front of the $pagetype variables.
         if (!is_dir($topdir . DIRECTORY_SEPARATOR . $dirname)) {
             if (strpos($dirname, '.blade.php')) {
                 $page_name = str_replace('.blade.php', '', $dirname);
                 $pagetype = '.blade.php';
             } elseif (strpos($dirname, '.twig')) {
                 $page_name = str_replace('.twig', '', $dirname);
                 $pagetype = '.twig';
             } else {
                 echo "No template type for {$dirname}, skipping\n";
                 continue;
             }
             // Create the page
             Vpage::create(['pagekey' => $page_name, 'url' => $page_name, 'name' => $page_name, 'pagetype' => $pagetype, 'description' => $page_name . ' page loaded from ' . $dirname, 'content' => file_get_contents($topdir . DIRECTORY_SEPARATOR . $dirname)]);
             continue;
         }
         // Read all of the files in each directory.
         foreach (scandir($topdir . DIRECTORY_SEPARATOR . $dirname) as $filename) {
             if ($filename == '.' || $filename == '..') {
                 continue;
             }
             if (strpos($filename, '.blade.php')) {
                 $page_name = str_replace('.blade.php', '', $filename);
                 $pagetype = '.blade.php';
             } elseif (strpos($filename, '.twig')) {
                 $page_name = str_replace('.twig', '', $filename);
                 $pagetype = '.twig';
             } else {
                 echo "No template type for {$filename}, skipping\n";
                 continue;
             }
             // Create the page
             Vpage::create(['pagekey' => $dirname . '.' . $page_name, 'url' => $dirname . '/' . $page_name, 'name' => $dirname . '.' . $page_name, 'pagetype' => $pagetype, 'description' => $page_name . ' page loaded from ' . $dirname . '/' . $filename, 'content' => file_get_contents($topdir . DIRECTORY_SEPARATOR . $dirname . DIRECTORY_SEPARATOR . $filename)]);
         }
     }
 }