Ejemplo n.º 1
0
 /**
  * Startup the system.
  *
  * @return void
  */
 public static function start()
 {
     // Load the application config.
     Config::file(path('config') . 'app.php');
     // Initialize the URI.
     Uri::initialize();
     // Attempt a database connection.
     Database::initialize();
     // Initilize the session.
     Session::initialize();
     // Initialize auth.
     Auth::initialize();
     // Assign class aliases.
     $aliases = Config::item('aliases');
     // Check aliases is a valid array first.
     if (is_array($aliases)) {
         foreach ($aliases as $alias => $class) {
             class_alias($class, $alias);
         }
     }
 }
Ejemplo n.º 2
0
 public function testSegmentString()
 {
     $uri = Uri::segmentString();
     $this->assertInternalType('string', $uri);
 }
Ejemplo n.º 3
0
 /**
  * Rewrites the application routes.
  *
  * @return void
  */
 private static function rewrite()
 {
     foreach (Repository::stored() as $method => $routes) {
         foreach ($routes as $uri => $options) {
             $segments = explode('/', $uri);
             $rewrite = false;
             foreach ($segments as $key => $segment) {
                 $matches = [];
                 // Get route URI segments we need to rewrite.
                 preg_match('/\\(([0-9a-z]+)\\:([a-z]+)\\)/i', $segment, $matches);
                 // Do we have matches?
                 if (!empty($matches)) {
                     // Get the real value for this segment and validate it
                     // against the rule.
                     $value = Uri::segment($key + 1);
                     $rule = $matches[2];
                     $valid = false;
                     // Validate the rule.
                     if ($rule === 'numeric' && is_numeric($value)) {
                         $valid = true;
                     } else {
                         if ($rule === 'any') {
                             $valid = true;
                         }
                     }
                     // If the segment is valid, assign the value.
                     if ($valid === true) {
                         $segments[$key] = $value;
                     }
                     // Add the parameters.
                     if (!isset($options['parameters'])) {
                         $options['parameters'] = [$value];
                     } else {
                         array_push($options['parameters'], $value);
                     }
                     // We will need to rewrite this URL.
                     $rewrite = true;
                 }
             }
             // Do we need to rewrite the URI value.
             if ($rewrite) {
                 // Remove the old URI.
                 Repository::remove($method, $uri);
                 // Add the new one.
                 Repository::store($method, implode('/', $segments), $options);
             }
         }
     }
 }