/** * 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(); } }
/** * 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); } // 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. $controller = static::format($bundle, $controller); $controller = new $controller(); // If the controller has specified a layout to be used when rendering // views, we will instantiate the layout instance and set it to the // layout property, replacing the string layout name. if (!is_null($controller->layout)) { $controller->layout = $controller->layout(); } return $controller; }
/** * Resolve an instance of the given task name. * * <code> * // Resolve an instance of a task * $task = Command::resolve('application', 'migrate'); * * // Resolve an instance of a task wtihin a bundle * $task = Command::resolve('bundle', 'foo'); * </code> * * @param string $bundle * @param string $task * @return object */ public static function resolve($bundle, $task) { $identifier = Bundle::identifier($bundle, $task); // First we'll check to see if the task has been registered in the // application IoC container. This allows all dependencies to be // injected into tasks for more testability. if (IoC::registered("task: {$identifier}")) { return IoC::resolve("task: {$identifier}"); } // If the task file exists, we'll format the bundle and task name // into a task class name and resolve an instance of the so that // the requested method may be executed. if (file_exists($path = Bundle::path($bundle) . 'tasks/' . $task . EXT)) { require $path; $task = static::format($bundle, $task); return new $task(); } }
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(); } }