Пример #1
0
 /**
  * Return a default View instance.
  *
  * @return \Nova\View\View
  * @throws \BadMethodCallException
  */
 protected function getView(array $data = array())
 {
     list(, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
     $method = $caller['function'];
     //
     $path = str_replace('\\', '/', static::class);
     if (preg_match('#^App/Controllers/(.*)$#i', $path, $matches)) {
         $view = $matches[1] . '/' . ucfirst($method);
         return View::make($view, $data);
     } else {
         if (preg_match('#^App/Modules/(.+)/Controllers/(.*)$#i', $path, $matches)) {
             $view = $matches[2] . '/' . ucfirst($method);
             return View::make($view, $data, $matches[1]);
         }
     }
     throw new BadMethodCallException('Invalid Controller namespace: ' . static::class);
 }
Пример #2
0
 /**
  * Return a default View instance.
  *
  * @return \Nova\View\View
  * @throws \BadMethodCallException
  */
 protected function getView(array $data = array())
 {
     list(, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
     // Retrieve the called Controller method from the caller.
     $method = $caller['function'];
     // Transform the complete class name on a path like variable.
     $path = str_replace('\\', '/', static::class);
     // Check for a valid controller on Application.
     if (preg_match('#^App/Controllers/(.*)$#i', $path, $matches)) {
         $view = $matches[1] . '/' . ucfirst($method);
         return View::make($view, $data);
     }
     // Retrieve the Modules namespace from their configuration.
     $namespace = Config::get('modules.namespace', 'App\\Modules\\');
     // Transform the Modules namespace on a path like variable.
     $basePath = str_replace('\\', '/', rtrim($namespace, '\\'));
     // Check for a valid controller on Modules.
     if (preg_match('#^' . $basePath . '/(.+)/Controllers/(.*)$#i', $path, $matches)) {
         $view = $matches[2] . '/' . ucfirst($method);
         return View::make($view, $data, $matches[1]);
     }
     // If we arrived there, the called class is not a Controller; go Exception.
     throw new BadMethodCallException('Invalid Controller namespace: ' . static::class);
 }
Пример #3
0
 /**
  * Return a new View Response from the application.
  *
  * @param  string  $view
  * @param  array   $data
  * @param  int     $status
  * @param  array   $headers
  * @return \Nova\Http\Response
  */
 public static function view($view, $data = array(), $status = 200, array $headers = array())
 {
     return static::make(View::make($view, $data), $status, $headers);
 }