Ejemplo n.º 1
0
 /**
  * Create a new Doctrine migration.
  *
  * @param  array  $arguments
  * @return void
  */
 public function make($arguments)
 {
     if (count($arguments) == 0) {
         throw new \Exception("I need to know what to name the migration.");
     }
     list($bundle, $migration) = Bundle::parse($arguments[0]);
     // The migration path is prefixed with the date timestamp, which
     // is a better way of ordering migrations than a simple integer
     // incrementation, since developers may start working on the
     // next migration at the same time unknowingly.
     $prefix = date('Y_m_d_His');
     $path = Bundle::path($bundle) . 'migrations' . DS;
     // If the migration directory does not exist for the bundle,
     // we will create the directory so there aren't errors when
     // when we try to write the migration file.
     if (!is_dir($path)) {
         mkdir($path);
     }
     $file = $path . $prefix . '_' . $migration . EXT;
     File::put($file, $this->stub($bundle, $migration));
     echo "Great! New migration created!";
     // Once the migration has been created, we'll return the
     // migration file name so it can be used by the task
     // consumer if necessary for futher work.
     return $file;
 }
Ejemplo n.º 2
0
 /**
  * Parse the task name to extract the bundle, task, and method.
  *
  * @param  string  $task
  * @return array
  */
 protected static function parse($task)
 {
     list($bundle, $task) = Bundle::parse($task);
     // Extract the task method from the task string. Methods are called
     // on tasks by separating the task and method with a single colon.
     // If no task is specified, "run" is used as the default.
     if (str_contains($task, ':')) {
         list($task, $method) = explode(':', $task);
     } else {
         $method = 'run';
     }
     return array($bundle, $task, $method);
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * Generate an action URI by convention.
  *
  * @param  string  $action
  * @param  array   $parameters
  * @return string
  */
 protected static function convention($action, $parameters)
 {
     list($bundle, $action) = Bundle::parse($action);
     $bundle = Bundle::get($bundle);
     // If a bundle exists for the action, we will attempt to use it's "handles"
     // clause as the root of the generated URL, as the bundle can only handle
     // URIs that begin with that string and no others.
     $root = $bundle['handles'] ?: '';
     $parameters = implode('/', $parameters);
     // We'll replace both dots and @ signs in the URI since both are used
     // to specify the controller and action, and by convention should be
     // translated into URI slashes for the URL.
     $uri = $root . '/' . str_replace(array('.', '@'), '/', $action);
     $uri = static::to(str_finish($uri, '/') . $parameters);
     return trim($uri, '/');
 }
Ejemplo n.º 5
0
 /**
  * Determine if the given view exists.
  *
  * @param  string       $view
  * @param  boolean      $return_path
  * @return string|bool
  */
 public static function exists($view, $return_path = false)
 {
     list($bundle, $view) = Bundle::parse($view);
     $view = str_replace('.', '/', $view);
     // We delegate the determination of view paths to the view loader event
     // so that the developer is free to override and manage the loading
     // of views in any way they see fit for their application.
     $path = Event::until(static::loader, array($bundle, $view));
     if (!is_null($path)) {
         return $return_path ? $path : true;
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * Register a controller with the router.
  *
  * @param  string|array  $controllers
  * @param  string|array  $defaults
  * @param  bool          $https
  * @return void
  */
 public static function controller($controllers, $defaults = 'index', $https = null)
 {
     foreach ((array) $controllers as $identifier) {
         list($bundle, $controller) = Bundle::parse($identifier);
         // First we need to replace the dots with slashes in the controller name
         // so that it is in directory format. The dots allow the developer to use
         // a cleaner syntax when specifying the controller. We will also grab the
         // root URI for the controller's bundle.
         $controller = str_replace('.', '/', $controller);
         $root = Bundle::option($bundle, 'handles');
         // If the controller is a "home" controller, we'll need to also build an
         // index method route for the controller. We'll remove "home" from the
         // route root and setup a route to point to the index method.
         if (ends_with($controller, 'home')) {
             static::root($identifier, $controller, $root);
         }
         // The number of method arguments allowed for a controller is set by a
         // "segments" constant on this class which allows for the developer to
         // increase or decrease the limit on method arguments.
         $wildcards = static::repeat('(:any?)', static::$segments);
         // Once we have the path and root URI we can build a simple route for
         // the controller that should handle a conventional controller route
         // setup of controller/method/segment/segment, etc.
         $pattern = trim("{$root}/{$controller}/{$wildcards}", '/');
         // Finally we can build the "uses" clause and the attributes for the
         // controller route and register it with the router with a wildcard
         // method so it is available on every request method.
         $uses = "{$identifier}@(:1)";
         $attributes = compact('uses', 'defaults', 'https');
         static::register('*', $pattern, $attributes);
     }
 }
Ejemplo n.º 7
0
 /**
  * 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($name, $method) = explode('@', $destination);
     $controller = static::resolve($bundle, $name);
     // For convenience we will set the current controller and action on the
     // Request's route instance so they can be easily accessed from the
     // application. This is sometimes useful for dynamic situations.
     if (!is_null($route = Request::route())) {
         $route->controller = $name;
         $route->controller_action = $method;
     }
     // 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);
 }
Ejemplo n.º 8
0
 /**
  * Parse the path to the form or page
  * 
  * @param string $name
  * @param string $type
  * 
  * @return array($file,$class_name,$method)
  */
 protected static function parse($name, $type)
 {
     list($path, $method) = explode('@', static::$modules[$type][$name]);
     list($bundle, $path) = Bundle::parse($path);
     $file = Bundle::path($bundle) . Str::plural($type) . DS . str_replace('.', DS, $path) . EXT;
     $class_name = static::format($bundle, $path, $type);
     return array($file, $class_name, $method);
 }
Ejemplo n.º 9
0
 /**
  * Get the path to a given view on disk.
  *
  * @param  string  $view
  * @return string
  */
 protected function path($view)
 {
     list($bundle, $view) = Bundle::parse($view);
     $view = str_replace('.', '/', $view);
     // We delegate the determination of view paths to the view loader event
     // so that the developer is free to override and manage the loading
     // of views in any way they see fit for their application.
     $path = Event::first(static::loader, array($bundle, $view));
     if (!is_null($path)) {
         return $path;
     }
     throw new \Exception("View [{$view}] doesn't exist.");
 }
Ejemplo n.º 10
0
 public static function controller($controllers, $defaults = 'index', $https = null)
 {
     foreach ((array) $controllers as $identifier) {
         list($bundle, $controller) = Bundle::parse($identifier);
         $controller = str_replace('.', '/', $controller);
         $root = Bundle::option($bundle, 'handles');
         if (ends_with($controller, 'home')) {
             static::root($identifier, $controller, $root);
         }
         $wildcards = static::repeat('(:any?)', static::$segments);
         $pattern = trim("{$root}/{$controller}/{$wildcards}", '/');
         $uses = "{$identifier}@(:1)";
         $attributes = compact('uses', 'defaults', 'https');
         static::register('*', $pattern, $attributes);
     }
 }
Ejemplo n.º 11
0
 protected static function convention($action, $parameters)
 {
     list($bundle, $action) = Bundle::parse($action);
     $bundle = Bundle::get($bundle);
     $root = $bundle['handles'] ?: '';
     $parameters = implode('/', $parameters);
     $uri = $root . '/' . str_replace(array('.', '@'), '/', $action);
     $uri = static::to(str_finish($uri, '/') . $parameters);
     return trim($uri, '/');
 }