app/library/Services.php: load router settings from config file.
This commit is contained in:
parent
ca90ec30fb
commit
a8a448331e
2 changed files with 71 additions and 50 deletions
54
app/config/routes.yml
Normal file
54
app/config/routes.yml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
router:
|
||||
removeExtraSlashes: true
|
||||
routes:
|
||||
home-route:
|
||||
pattern: '/'
|
||||
path:
|
||||
controller: index
|
||||
action: index
|
||||
about-route:
|
||||
pattern: '/about'
|
||||
path:
|
||||
controller: index
|
||||
action: about
|
||||
cb-created:
|
||||
pattern: '/callback/created/{id}'
|
||||
path:
|
||||
controller: callback
|
||||
action: created
|
||||
cb-endpoint:
|
||||
pattern: '/cb/{id}'
|
||||
path:
|
||||
controller: callback
|
||||
action: endpoint
|
||||
login:
|
||||
pattern: '/login'
|
||||
path:
|
||||
controller: auth
|
||||
action: index
|
||||
logout:
|
||||
pattern: '/logout'
|
||||
path:
|
||||
controller: auth
|
||||
action: logout
|
||||
oauth:
|
||||
pattern: '/login/{strategy:([a-z]+)}/:params'
|
||||
path:
|
||||
controller: auth
|
||||
action: oauth
|
||||
oauth-disconnect:
|
||||
pattern: '/oauth/{provider:([a-z]+)}/disconnect'
|
||||
path: 'User::oauthdisconnect'
|
||||
oauth-disconnect-confirm:
|
||||
pattern: '/oauth/{provider:([a-z]+)}/disconnect/{confirm}'
|
||||
path: 'User::oauthdisconnect'
|
||||
user-settings:
|
||||
pattern: '/settings'
|
||||
path:
|
||||
controller: user
|
||||
action: settings
|
||||
activation-link:
|
||||
path:
|
||||
controller: user
|
||||
action: activationlink
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue