Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
4b9200f6
Commit
4b9200f6
authored
12 years ago
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Routing: combine all routes into one set
parent
6ba26234
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/api.php
+1
-0
1 addition, 0 deletions
lib/api.php
lib/router.php
+14
-8
14 additions, 8 deletions
lib/router.php
ocs/v1.php
+1
-3
1 addition, 3 deletions
ocs/v1.php
with
16 additions
and
11 deletions
lib/api.php
+
1
−
0
View file @
4b9200f6
...
@@ -44,6 +44,7 @@ class OC_API {
...
@@ -44,6 +44,7 @@ class OC_API {
$name
=
strtolower
(
$method
)
.
$url
;
$name
=
strtolower
(
$method
)
.
$url
;
$name
=
str_replace
(
array
(
'/'
,
'{'
,
'}'
),
'_'
,
$name
);
$name
=
str_replace
(
array
(
'/'
,
'{'
,
'}'
),
'_'
,
$name
);
if
(
!
isset
(
self
::
$actions
[
$name
])){
if
(
!
isset
(
self
::
$actions
[
$name
])){
OC
::
getRouter
()
->
useCollection
(
'ocs'
);
OC
::
getRouter
()
->
create
(
$name
,
$url
.
'.{_format}'
)
OC
::
getRouter
()
->
create
(
$name
,
$url
.
'.{_format}'
)
->
method
(
$method
)
->
method
(
$method
)
->
defaults
(
array
(
'_format'
=>
'xml'
)
+
$defaults
)
->
defaults
(
array
(
'_format'
=>
'xml'
)
+
$defaults
)
...
...
This diff is collapsed.
Click to expand it.
lib/router.php
+
14
−
8
View file @
4b9200f6
...
@@ -15,32 +15,38 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException;
...
@@ -15,32 +15,38 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException;
class
OC_Router
{
class
OC_Router
{
protected
$collections
=
array
();
protected
$collections
=
array
();
protected
$collection
=
null
;
protected
$collection
=
null
;
protected
$root
=
null
;
public
function
__construct
()
{
// TODO cache
$this
->
loadRoutes
();
}
/**
/**
* loads the api routes
* loads the api routes
*/
*/
public
function
loadRoutes
()
{
public
function
loadRoutes
()
{
// TODO cache
// TODO cache
$this
->
root
=
$this
->
getCollection
(
'root'
);
foreach
(
OC_APP
::
getEnabledApps
()
as
$app
){
foreach
(
OC_APP
::
getEnabledApps
()
as
$app
){
$file
=
OC_App
::
getAppPath
(
$app
)
.
'/appinfo/routes.php'
;
$file
=
OC_App
::
getAppPath
(
$app
)
.
'/appinfo/routes.php'
;
if
(
file_exists
(
$file
)){
if
(
file_exists
(
$file
)){
$this
->
useCollection
(
$app
);
require_once
(
$file
);
require_once
(
$file
);
$collection
=
$this
->
getCollection
(
$app
);
$this
->
root
->
addCollection
(
$collection
,
'/apps/'
.
$app
);
}
}
}
}
// include ocs routes
// include ocs routes
require_once
(
OC
::
$SERVERROOT
.
'/ocs/routes.php'
);
require_once
(
OC
::
$SERVERROOT
.
'/ocs/routes.php'
);
$collection
=
$this
->
getCollection
(
'ocs'
);
$this
->
root
->
addCollection
(
$collection
,
'/ocs'
);
}
}
p
ublic
function
use
Collection
(
$name
)
{
p
rotected
function
get
Collection
(
$name
)
{
if
(
!
isset
(
$this
->
collections
[
$name
]))
{
if
(
!
isset
(
$this
->
collections
[
$name
]))
{
$this
->
collections
[
$name
]
=
new
RouteCollection
();
$this
->
collections
[
$name
]
=
new
RouteCollection
();
}
}
$this
->
collection
=
$this
->
collections
[
$name
];
return
$this
->
collections
[
$name
];
}
public
function
useCollection
(
$name
)
{
$this
->
collection
=
$this
->
getCollection
(
$name
);
}
}
public
function
create
(
$name
,
$pattern
,
array
$defaults
=
array
(),
array
$requirements
=
array
())
{
public
function
create
(
$name
,
$pattern
,
array
$defaults
=
array
(),
array
$requirements
=
array
())
{
...
@@ -51,7 +57,7 @@ class OC_Router {
...
@@ -51,7 +57,7 @@ class OC_Router {
public
function
match
(
$url
)
{
public
function
match
(
$url
)
{
$context
=
new
RequestContext
(
$_SERVER
[
'REQUEST_URI'
],
$_SERVER
[
'REQUEST_METHOD'
]);
$context
=
new
RequestContext
(
$_SERVER
[
'REQUEST_URI'
],
$_SERVER
[
'REQUEST_METHOD'
]);
$matcher
=
new
UrlMatcher
(
$this
->
collection
,
$context
);
$matcher
=
new
UrlMatcher
(
$this
->
root
,
$context
);
$parameters
=
$matcher
->
match
(
$url
);
$parameters
=
$matcher
->
match
(
$url
);
if
(
isset
(
$parameters
[
'action'
]))
{
if
(
isset
(
$parameters
[
'action'
]))
{
$action
=
$parameters
[
'action'
];
$action
=
$parameters
[
'action'
];
...
...
This diff is collapsed.
Click to expand it.
ocs/v1.php
+
1
−
3
View file @
4b9200f6
...
@@ -25,10 +25,8 @@ require_once('../lib/base.php');
...
@@ -25,10 +25,8 @@ require_once('../lib/base.php');
use
Symfony\Component\Routing\Exception\ResourceNotFoundException
;
use
Symfony\Component\Routing\Exception\ResourceNotFoundException
;
use
Symfony\Component\Routing\Exception\MethodNotAllowedException
;
use
Symfony\Component\Routing\Exception\MethodNotAllowedException
;
OC
::
getRouter
()
->
useCollection
(
'ocs'
);
try
{
try
{
OC
::
getRouter
()
->
match
(
$_SERVER
[
'PATH_INFO'
]);
OC
::
getRouter
()
->
match
(
'/ocs'
.
$_SERVER
[
'PATH_INFO'
]);
}
catch
(
ResourceNotFoundException
$e
)
{
}
catch
(
ResourceNotFoundException
$e
)
{
OC_OCS
::
notFound
();
OC_OCS
::
notFound
();
}
catch
(
MethodNotAllowedException
$e
)
{
}
catch
(
MethodNotAllowedException
$e
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment