/** * Call an action method on a controller. * * <code> * // Call the "show" method on the "user" controller * $response = Controller::call('user@show'); * * // Call the "user/admin" controller and pass parameters * $response = Controller::call('user.admin@profile', array($username)); * </code> * * @param string $destination * @param array $parameters * @return Response */ public static function call($destination, $parameters = array()) { static::references($destination, $parameters); list($bundle, $destination) = Bundle::parse($destination); // We will always start the bundle, just in case the developer is pointing // a route to another bundle. This allows us to lazy load the bundle and // improve speed since the bundle is not loaded on every request. Bundle::start($bundle); list($controller, $method) = explode('@', $destination); $controller = static::resolve($bundle, $controller); // If the controller could not be resolved, we're out of options and // will return the 404 error response. If we found the controller, // we can execute the requested method on the instance. if (is_null($controller)) { return Event::first('404'); } return $controller->execute($method, $parameters); }
/** * Resolve a bundle and controller name to a controller instance. * * @param string $bundle * @param string $controller * @return Controller */ public static function resolve($bundle, $controller) { if (!static::load($bundle, $controller)) { return; } $identifier = Bundle::identifier($bundle, $controller); // If the controller is registered in the IoC container, we will resolve // it out of the container. Using constructor injection on controllers // via the container allows more flexible applications. $resolver = 'controller: ' . $identifier; if (IoC::registered($resolver)) { return IoC::resolve($resolver); } $controller = static::format($bundle, $controller); // If we couldn't resolve the controller out of the IoC container we'll // format the controller name into its proper class name and load it // by convention out of the bundle's controller directory. if (Event::listeners(static::factory)) { return Event::first(static::factory, $controller); } else { return new $controller(); } }
/** * Load all of the language lines from a language file. * * @param string $bundle * @param string $language * @param string $file * @return bool */ public static function load($bundle, $language, $file) { if (isset(static::$lines[$bundle][$language][$file])) { return true; } // We use a "loader" event to delegate the loading of the language // array, which allows the develop to organize the language line // arrays for their application however they wish. $lines = Event::first(static::loader, func_get_args()); static::$lines[$bundle][$language][$file] = $lines; return count($lines) > 0; }
/** * Load all of the configuration items from a configuration file. * * @param string $bundle * @param string $file * @return bool */ public static function load($bundle, $file) { if (isset(static::$items[$bundle][$file])) { return true; } // We allow a "config.loader" event to be registered which is responsible for // returning an array representing the configuration for the bundle and file // requested. This allows many types of config "drivers". $config = Event::first(static::loader, func_get_args()); // If configuration items were actually found for the bundle and file we // will add them to the configuration array and return true, otherwise // we will return false indicating the file was not found. if (count($config) > 0) { static::$items[$bundle][$file] = $config; } return isset(static::$items[$bundle][$file]); }
/** * Get the evaluated contents of the view. * * @return string */ public function get() { $__data = $this->data(); // The contents of each view file is cached in an array for the // request since partial views may be rendered inside of for // loops which could incur performance penalties. $__contents = $this->load(); ob_start() and extract($__data, EXTR_SKIP); // We'll include the view contents for parsing within a catcher // so we can avoid any WSOD errors. If an exception occurs we // will throw it out to the exception handler. try { eval('?>' . $__contents); } catch (\Exception $e) { ob_get_clean(); throw $e; } $content = ob_get_clean(); // The view filter event gives us a last chance to modify the // evaluated contents of the view and return them. This lets // us do something like run the contents through Jade, etc. if (Event::listeners('view.filter')) { return Event::first('view.filter', array($content, $this->path)); } return $content; }
/** * Get the evaluated string content of the view. * * @return string */ public function render() { // To allow bundles or other pieces of the application to modify the // view before it is rendered, we'll fire an event, passing in the // view instance so it can modified. $composer = "laravel.composing: {$this->view}"; Event::fire($composer, array($this)); // If there are listeners to the view engine event, we'll pass them // the view so they can render it according to their needs, which // allows easy attachment of other view parsers. if (Event::listeners(static::engine)) { $result = Event::first(static::engine, array($this)); if ($result !== false) { return $result; } } return $this->get(); }
public static function load($bundle, $language, $file) { if (isset(static::$lines[$bundle][$language][$file])) { return true; } $lines = Event::first(static::loader, func_get_args()); static::$lines[$bundle][$language][$file] = $lines; return count($lines) > 0; }
public static function resolve($bundle, $controller) { if (!static::load($bundle, $controller)) { return; } $identifier = Bundle::identifier($bundle, $controller); $resolver = 'controller: ' . $identifier; if (IoC::registered($resolver)) { return IoC::resolve($resolver); } $controller = static::format($bundle, $controller); if (Event::listeners(static::factory)) { return Event::first(static::factory, $controller); } else { return new $controller(); } }
if ($config['auto']) { Bundle::start($bundle); } } /* |-------------------------------------------------------------------------- | Register The Catch-All Route |-------------------------------------------------------------------------- | | This route will catch all requests that do not hit another route in | the application, and will raise the 404 error event so the error | can be handled by the developer in their 404 event listener. | */ Router::register('*', '(:all)', function () { return Event::first('404'); }); /* |-------------------------------------------------------------------------- | Gather The URI And Locales |-------------------------------------------------------------------------- | | When routing, we'll need to grab the URI and the supported locales for | the route so we can properly set the language and route the request | to the proper end-point in the application. | */ $uri = URI::current(); $languages = Config::get('application.languages', array()); $languages[] = Config::get('application.language'); /*