Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
61626494
Commit
61626494
authored
Nov 28, 2016
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(mvc) routing, switch to new routing, deduplicates code....
parent
a81aab89
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
126 deletions
+8
-126
services.php
src/opnsense/mvc/app/config/services.php
+4
-62
services_api.php
src/opnsense/mvc/app/config/services_api.php
+4
-64
No files found.
src/opnsense/mvc/app/config/services.php
View file @
61626494
...
@@ -7,6 +7,7 @@ use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
...
@@ -7,6 +7,7 @@ use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use
Phalcon\Mvc\Model\Metadata\Memory
as
MetaDataAdapter
;
use
Phalcon\Mvc\Model\Metadata\Memory
as
MetaDataAdapter
;
use
Phalcon\Session\Adapter\Files
as
SessionAdapter
;
use
Phalcon\Session\Adapter\Files
as
SessionAdapter
;
use
OPNsense\Core\Config
;
use
OPNsense\Core\Config
;
use
OPNsense\Core\Routing
;
/**
/**
* The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
* The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
...
@@ -91,66 +92,7 @@ $di->set('config', $config);
...
@@ -91,66 +92,7 @@ $di->set('config', $config);
*/
*/
$di
->
set
(
'router'
,
function
()
{
$di
->
set
(
'router'
,
function
()
{
$router
=
new
\Phalcon\Mvc\Router
(
false
);
$routing
=
new
Routing
(
__DIR__
.
"/../controllers/"
,
"ui"
);
$routing
->
getRouter
()
->
handle
();
$router
->
setDefaultController
(
'index'
);
return
$routing
->
getRouter
();
$router
->
setDefaultAction
(
'index'
);
$router
->
setDefaultNamespace
(
'OPNsense\Core'
);
$router
->
add
(
'/'
,
array
(
"controller"
=>
'index'
,
"action"
=>
'index'
));
// probe registered modules and create a namespace map
// for example, OPNsense\Core will be mapped at http(s):\\host\core\..
// module names should be unique in the application, unless you want to
// overwrite functionality (check glob's sorting).
//
// if the glob for probing the directories turns out to be too slow,
// we should consider some kind of caching here
//
$registered_modules
=
array
();
$controller_dir
=
__DIR__
.
"/../controllers/"
;
foreach
(
glob
(
$controller_dir
.
"*"
,
GLOB_ONLYDIR
)
as
$namespace_base
)
{
foreach
(
glob
(
$namespace_base
.
"/*"
,
GLOB_ONLYDIR
)
as
$module_name
)
{
if
(
strpos
(
$module_name
,
'OPNsense/Base'
)
===
false
)
{
$namespace_name
=
str_replace
(
'/'
,
'\\'
,
str_replace
(
$controller_dir
,
''
,
$module_name
));
$registered_modules
[
strtolower
(
basename
(
$module_name
))]
=
$namespace_name
;
}
}
}
// add routing for all controllers, using the following convention:
// \module\controller\action\params
// where module is mapped to the corresponding namespace
foreach
(
$registered_modules
as
$module_name
=>
$namespace_name
)
{
$router
->
add
(
"/"
.
$module_name
.
"/"
,
array
(
"namespace"
=>
$namespace_name
));
$router
->
add
(
"/"
.
$module_name
.
"/:controller/"
,
array
(
"namespace"
=>
$namespace_name
,
"controller"
=>
1
));
$router
->
add
(
"/"
.
$module_name
.
"/:controller/:action/"
,
array
(
"namespace"
=>
$namespace_name
,
"controller"
=>
1
,
"action"
=>
2
));
$router
->
add
(
"/"
.
$module_name
.
"/:controller/:action/:params"
,
array
(
"namespace"
=>
$namespace_name
,
"controller"
=>
1
,
"action"
=>
2
,
"params"
=>
3
));
}
$router
->
handle
();
return
$router
;
});
});
src/opnsense/mvc/app/config/services_api.php
View file @
61626494
...
@@ -35,6 +35,7 @@ use Phalcon\Mvc\View;
...
@@ -35,6 +35,7 @@ use Phalcon\Mvc\View;
use
Phalcon\Mvc\Model\Metadata\Memory
as
MetaDataAdapter
;
use
Phalcon\Mvc\Model\Metadata\Memory
as
MetaDataAdapter
;
use
Phalcon\Session\Adapter\Files
as
SessionAdapter
;
use
Phalcon\Session\Adapter\Files
as
SessionAdapter
;
use
OPNsense\Core\Config
;
use
OPNsense\Core\Config
;
use
OPNsense\Core\Routing
;
/**
/**
* The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
* The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
...
@@ -86,70 +87,9 @@ $di->set('config', $config);
...
@@ -86,70 +87,9 @@ $di->set('config', $config);
*/
*/
$di
->
set
(
'router'
,
function
()
{
$di
->
set
(
'router'
,
function
()
{
$router
=
new
\Phalcon\Mvc\Router
(
false
);
$routing
=
new
Routing
(
__DIR__
.
"/../controllers/"
,
"api"
);
$routing
->
getRouter
()
->
handle
();
$router
->
setDefaultController
(
'index'
);
return
$routing
->
getRouter
();
$router
->
setDefaultAction
(
'index'
);
$router
->
setDefaultNamespace
(
'OPNsense\Base'
);
$router
->
add
(
'/'
,
array
(
"controller"
=>
'index'
,
"action"
=>
'index'
));
//
// probe registered API modules and create a namespace map
// for example, OPNsense\Core\Api will be mapped at http(s):\\host\core\..
// module names should be unique in the application, unless you want to
// overwrite functionality (check glob's sorting).
//
// if the glob for probing the directories turns out to be too slow,
// we should consider some kind of caching here
//
$registered_modules
=
array
();
$controller_dir
=
__DIR__
.
"/../controllers/"
;
foreach
(
glob
(
$controller_dir
.
"*"
,
GLOB_ONLYDIR
)
as
$namespace_base
)
{
foreach
(
glob
(
$namespace_base
.
"/*"
,
GLOB_ONLYDIR
)
as
$module_base
)
{
if
(
strpos
(
$module_base
,
'OPNsense/Base'
)
===
false
)
{
foreach
(
glob
(
$module_base
.
"/Api"
,
GLOB_ONLYDIR
)
as
$api_base
)
{
$namespace_name
=
str_replace
(
'/'
,
'\\'
,
str_replace
(
$controller_dir
,
''
,
$api_base
));
$registered_modules
[
strtolower
(
basename
(
$module_base
))]
=
$namespace_name
;
}
}
}
}
// add routing for all controllers, using the following convention:
// \module\controller\action\params
// where module is mapped to the corresponding namespace
foreach
(
$registered_modules
as
$module_name
=>
$namespace_name
)
{
$router
->
add
(
"/"
.
$module_name
.
"/"
,
array
(
"namespace"
=>
$namespace_name
));
$router
->
add
(
"/"
.
$module_name
.
"/:controller/"
,
array
(
"namespace"
=>
$namespace_name
,
"controller"
=>
1
));
$router
->
add
(
"/"
.
$module_name
.
"/:controller/:action/"
,
array
(
"namespace"
=>
$namespace_name
,
"controller"
=>
1
,
"action"
=>
2
));
$router
->
add
(
"/"
.
$module_name
.
"/:controller/:action/:params"
,
array
(
"namespace"
=>
$namespace_name
,
"controller"
=>
1
,
"action"
=>
2
,
"params"
=>
3
));
}
$router
->
handle
();
return
$router
;
});
});
// exception handling
// exception handling
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment