Example #1
0
 public function setRoutes(Map $map)
 {
     $routes = [];
     if ($handle = opendir($this->config->getSys('basedir') . '/configs')) {
         $defaultRoutes = $this->config->getSys('basedir') . '/configs/Routes/default.' . $this->config->getSys('cfg.format');
         $envRoutes = $this->config->getSys('basedir') . '/configs/Routes/' . $this->env . '.' . $this->config->getSys('cfg.format');
         if (file_exists($defaultRoutes)) {
             $routes = json_decode(file_get_contents($defaultRoutes), true);
         }
         if (file_exists($envRoutes)) {
             $routes = array_replace($routes, json_decode(file_get_contents($envRoutes), true));
         }
     }
     if (isset($routes['default'])) {
         $this->applyRouteConfig($map, $routes['default']);
     }
     foreach ($routes as $uri => $properties) {
         // Skip if defaults and not a route
         if ($uri == 'default') {
             continue;
         }
         /*
          * First set up the route object
          *
          * NOTE: Because Objects are always passed by reference in PHP, as we go through the optional stuff on the
          * returned route object, the object stored in the map will also be altered since they are both a reference
          * to the same object.
          */
         switch ($properties['httpMethod']) {
             case 'get':
                 $route = $map->get($properties['name'], $uri, $properties['handler']);
                 break;
             case 'post':
                 $route = $map->post($properties['name'], $uri, $properties['handler']);
                 break;
             case 'patch':
                 $route = $map->patch($properties['name'], $uri, $properties['handler']);
                 break;
             case 'delete':
                 $route = $map->delete($properties['name'], $uri, $properties['handler']);
                 break;
             case 'options':
                 $route = $map->options($properties['name'], $uri, $properties['handler']);
                 break;
             case 'head':
                 $route = $map->head($properties['name'], $uri, $properties['handler']);
                 break;
             default:
                 $route = $map->route($properties['name'], $uri, $properties['handler']);
                 break;
         }
         // Okay, now let's go through all the supported options
         $this->applyRouteConfig($route, $properties);
     }
 }
Example #2
0
 public function __construct(Config $config)
 {
     $dsn = $config->get('db.driver') . ':dbname=' . $config->get('db.name', 'eden') . ';host=' . $config->get('db.host', 'localhost');
     parent::__construct($dsn, $config->get('db.user'), $config->get('db.pass'), $config->get('db.options'), $config->get('db.attributes'));
 }