Exemplo n.º 1
0
 public function build()
 {
     $container = $this->builder->getContainer();
     $view = ucfirst($container->inflector->pluralize($this->viewName));
     $fullPath = $container->getNamespacePrefix($this->getSection()) . 'View\\' . $view . '\\' . ucfirst($this->viewType);
     // Let's remove the last part and use it to create the class name
     $parts = explode('\\', trim($fullPath, '\\'));
     $className = array_pop($parts);
     // Now glue everything together
     $namespace = implode('\\', $parts);
     // Let's be sure that the parent class extends with a backslash
     $baseClass = '\\' . trim(get_class($this->view), '\\');
     $code = '<?php' . PHP_EOL;
     $code .= PHP_EOL;
     $code .= 'namespace ' . $namespace . ';' . PHP_EOL;
     $code .= PHP_EOL;
     $code .= "defined('_JEXEC') or die;" . PHP_EOL;
     $code .= PHP_EOL;
     $code .= 'class ' . $className . ' extends ' . $baseClass . PHP_EOL;
     $code .= '{' . PHP_EOL;
     $code .= PHP_EOL;
     $code .= '}' . PHP_EOL;
     $path = $container->backEndPath;
     if (in_array('Site', $parts)) {
         $path = $container->frontEndPath;
     }
     $path .= '/View/' . $view . '/' . $className . '.php';
     $filesystem = $container->filesystem;
     $filesystem->fileWrite($path, $code);
     return $path;
 }
Exemplo n.º 2
0
Arquivo: View.php Projeto: akeeba/fof
 public function execute()
 {
     // Backend or frontend?
     $section = $this->input->get('frontend', false) ? 'site' : 'admin';
     $view = $this->getViewName($this->input);
     // Let's force the use of the Magic Factory
     $container = Container::getInstance($this->component, array('factoryClass' => 'FOF30\\Factory\\MagicFactory'));
     $container->factory->setSaveScaffolding(true);
     $view = $container->inflector->pluralize($view);
     $classname = $container->getNamespacePrefix($section) . 'View\\' . ucfirst($view) . '\\Html';
     $scaffolding = new ViewBuilder($container);
     $scaffolding->setSection($section);
     ini_set('error_reporting', E_ALL);
     ini_set('display_errors', 1);
     if (!$scaffolding->make($classname, $view, 'html')) {
         throw new \RuntimeException("An error occurred while creating the Model class");
     }
 }
Exemplo n.º 3
0
 /**
  * Create a new View object
  *
  * @param   string  $viewName  The name of the view we're getting a View object for.
  * @param   string  $viewType  The type of the View object. By default it's "html".
  * @param   array   $config    Optional MVC configuration values for the View object.
  *
  * @return  View
  */
 public function view($viewName, $viewType = 'html', array $config = array())
 {
     $container = $this->container;
     $prefix = $this->container->getNamespacePrefix($this->getSection());
     $viewClass = $prefix . 'View\\' . ucfirst($viewName) . '\\' . ucfirst($viewType);
     try {
         return $this->createView($viewClass, $config);
     } catch (ViewNotFound $e) {
     }
     $viewClass = $prefix . 'View\\' . ucfirst($container->inflector->singularize($viewName)) . '\\' . ucfirst($viewType);
     try {
         $view = $this->createView($viewClass, $config);
     } catch (ViewNotFound $e) {
         // Do I have to create and save the class file? If not, let's rethrow the exception. Note: I can only create HTML views
         if (!$this->saveViewScaffolding) {
             throw $e;
         }
         // By default view classes are plural
         $viewClass = $prefix . 'View\\' . ucfirst($container->inflector->pluralize($viewName)) . '\\' . ucfirst($viewType);
         $scaffolding = new ViewBuilder($this->container);
         // Was the scaffolding successful? If so let's call ourself again, otherwise throw a not found exception
         if ($scaffolding->make($viewClass, $viewName, $viewType)) {
             $view = $this->view($viewName, $viewType, $config);
         } else {
             throw $e;
         }
     }
     return $view;
 }