Archived
1
0
Fork 0

app/library/Services.php: load router settings from config file.

This commit is contained in:
Henrik Hautakoski 2018-06-18 22:16:03 +02:00
parent ca90ec30fb
commit a8a448331e
2 changed files with 71 additions and 50 deletions

View file

@ -66,6 +66,7 @@ class Services extends DiDefault
// will override settings if there a multiple keys.
$files = array(
'app.yml',
'routes.yml',
'local.yml'
);
@ -76,7 +77,8 @@ class Services extends DiDefault
foreach ($files as $file) {
try {
$config->merge(new Config($basePath . $file));
$tmp = new Config($basePath . $file);
$config->merge($tmp);
} catch(\Phalcon\Config\Exception $e) {
// Sometime went wrong. Log here?
}
@ -329,61 +331,26 @@ class Services extends DiDefault
protected function _initSharedRouter()
{
$config = $this->get('config')->router;
// Create the router
$router = new Router();
$router->removeExtraSlashes(true);
$router->removeExtraSlashes($config->get('removeExtraSlashes', false));
$router->add('/', array(
'controller' => 'index',
'action' => 'index'
))->setName('home-route');
foreach($config->routes as $name => $def) {
// Route about page to index controller
$router->add('/about', array(
'controller' => 'index',
'action' => 'about'
))->setName('about-route');
if (!($def instanceof \Phalcon\Config)) {
continue;
}
$router->add('/callback/created/{id}', array(
'controller' => 'callback',
'action' => 'created',
))->setName('cb-created');
// Route callback endpoints to callback controller.
$router->add('/cb/{id}', array(
'controller' => 'callback',
'action' => 'endpoint',
))->setName('cb-endpoint');
// Login routes.
$router->add('/login', array(
'controller' => 'auth',
'action' => 'index',
))->setName('login');
$router->add('/logout', array(
'controller' => 'auth',
'action' => 'logout',
))->setName('logout');
$router->add('/login/{strategy:([a-z]+)}/:params', array(
'controller' => 'auth',
'action' => 'oauth'
))->setName('oauth');
$router->add('/oauth/{provider:([a-z]+)}/disconnect', 'User::oauthdisconnect')->setName('oauth-disconnect');
$router->add('/oauth/{provider:([a-z]+)}/disconnect/{confirm}', 'User::oauthdisconnect')->setName('oauth-disconnect-confirm');
$router->add('/settings', array(
'controller' => 'user',
'action' => 'settings',
))->setName('user-settings');
$router->add('/act/{link}', array(
'controller' => 'user',
'action' => 'activationlink',
))->setName('activation-link');
$path = $def->get('path', []);
if ($path instanceof \Phalcon\Config) {
$path = $path->toArray();
}
$router->add($def->get('pattern'), $path)
->setName($name);
}
return $router;
}