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
c2b4e534
Commit
c2b4e534
authored
12 years ago
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Add API description to OC_Route and OC_Router
parent
f3a211c0
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/route.php
+40
-0
40 additions, 0 deletions
lib/route.php
lib/router.php
+31
-0
31 additions, 0 deletions
lib/router.php
with
71 additions
and
0 deletions
lib/route.php
+
40
−
0
View file @
c2b4e534
...
@@ -9,31 +9,53 @@
...
@@ -9,31 +9,53 @@
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\Routing\Route
;
class
OC_Route
extends
Route
{
class
OC_Route
extends
Route
{
/**
* Specify the method when this route is to be used
*
* @param string $method HTTP method (uppercase)
*/
public
function
method
(
$method
)
{
public
function
method
(
$method
)
{
$this
->
setRequirement
(
'_method'
,
strtoupper
(
$method
));
$this
->
setRequirement
(
'_method'
,
strtoupper
(
$method
));
return
$this
;
return
$this
;
}
}
/**
* Specify POST as the method to use with this route
*/
public
function
post
()
{
public
function
post
()
{
$this
->
method
(
'POST'
);
$this
->
method
(
'POST'
);
return
$this
;
return
$this
;
}
}
/**
* Specify GET as the method to use with this route
*/
public
function
get
()
{
public
function
get
()
{
$this
->
method
(
'GET'
);
$this
->
method
(
'GET'
);
return
$this
;
return
$this
;
}
}
/**
* Specify PUT as the method to use with this route
*/
public
function
put
()
{
public
function
put
()
{
$this
->
method
(
'PUT'
);
$this
->
method
(
'PUT'
);
return
$this
;
return
$this
;
}
}
/**
* Specify DELETE as the method to use with this route
*/
public
function
delete
()
{
public
function
delete
()
{
$this
->
method
(
'DELETE'
);
$this
->
method
(
'DELETE'
);
return
$this
;
return
$this
;
}
}
/**
* Defaults to use for this route
*
* @param array $defaults The defaults
*/
public
function
defaults
(
$defaults
)
{
public
function
defaults
(
$defaults
)
{
$action
=
$this
->
getDefault
(
'action'
);
$action
=
$this
->
getDefault
(
'action'
);
$this
->
setDefaults
(
$defaults
);
$this
->
setDefaults
(
$defaults
);
...
@@ -44,6 +66,11 @@ class OC_Route extends Route {
...
@@ -44,6 +66,11 @@ class OC_Route extends Route {
return
$this
;
return
$this
;
}
}
/**
* Requirements for this route
*
* @param array $requirements The requirements
*/
public
function
requirements
(
$requirements
)
{
public
function
requirements
(
$requirements
)
{
$method
=
$this
->
getRequirement
(
'_method'
);
$method
=
$this
->
getRequirement
(
'_method'
);
$this
->
setRequirements
(
$requirements
);
$this
->
setRequirements
(
$requirements
);
...
@@ -56,6 +83,14 @@ class OC_Route extends Route {
...
@@ -56,6 +83,14 @@ class OC_Route extends Route {
return
$this
;
return
$this
;
}
}
/**
* The action to execute when this route matches
* @param string|callable $class the class or a callable
* @param string $function the function to use with the class
*
* This function is called with $class set to a callable or
* to the class with $function
*/
public
function
action
(
$class
,
$function
=
null
)
{
public
function
action
(
$class
,
$function
=
null
)
{
$action
=
array
(
$class
,
$function
);
$action
=
array
(
$class
,
$function
);
if
(
is_null
(
$function
))
{
if
(
is_null
(
$function
))
{
...
@@ -65,6 +100,11 @@ class OC_Route extends Route {
...
@@ -65,6 +100,11 @@ class OC_Route extends Route {
return
$this
;
return
$this
;
}
}
/**
* The action to execute when this route matches, includes a file like
* it is called directly
* @param $file
*/
public
function
actionInclude
(
$file
)
{
public
function
actionInclude
(
$file
)
{
$function
=
create_function
(
'$param'
,
'unset($param["_route"]);$_GET=array_merge($_GET,$param);unset($param);require_once "'
.
$file
.
'";'
);
$function
=
create_function
(
'$param'
,
'unset($param["_route"]);$_GET=array_merge($_GET,$param);unset($param);require_once "'
.
$file
.
'";'
);
$this
->
action
(
$function
);
$this
->
action
(
$function
);
...
...
This diff is collapsed.
Click to expand it.
lib/router.php
+
31
−
0
View file @
c2b4e534
...
@@ -53,16 +53,34 @@ class OC_Router {
...
@@ -53,16 +53,34 @@ class OC_Router {
return
$this
->
collections
[
$name
];
return
$this
->
collections
[
$name
];
}
}
/**
* Sets the collection to use for adding routes
*
* @param string $name Name of the colletion to use.
*/
public
function
useCollection
(
$name
)
{
public
function
useCollection
(
$name
)
{
$this
->
collection
=
$this
->
getCollection
(
$name
);
$this
->
collection
=
$this
->
getCollection
(
$name
);
}
}
/**
* Create a OC_Route.
*
* @param string $name Name of the route to create.
* @param string $pattern The pattern to match
* @param array $defaults An array of default parameter values
* @param array $requirements An array of requirements for parameters (regexes)
*/
public
function
create
(
$name
,
$pattern
,
array
$defaults
=
array
(),
array
$requirements
=
array
())
{
public
function
create
(
$name
,
$pattern
,
array
$defaults
=
array
(),
array
$requirements
=
array
())
{
$route
=
new
OC_Route
(
$pattern
,
$defaults
,
$requirements
);
$route
=
new
OC_Route
(
$pattern
,
$defaults
,
$requirements
);
$this
->
collection
->
add
(
$name
,
$route
);
$this
->
collection
->
add
(
$name
,
$route
);
return
$route
;
return
$route
;
}
}
/**
* Find the route matching $url.
*
* @param string $url The url to find
*/
public
function
match
(
$url
)
{
public
function
match
(
$url
)
{
$matcher
=
new
UrlMatcher
(
$this
->
root
,
$this
->
context
);
$matcher
=
new
UrlMatcher
(
$this
->
root
,
$this
->
context
);
$parameters
=
$matcher
->
match
(
$url
);
$parameters
=
$matcher
->
match
(
$url
);
...
@@ -81,6 +99,10 @@ class OC_Router {
...
@@ -81,6 +99,10 @@ class OC_Router {
}
}
}
}
/**
* Get the url generator
*
*/
public
function
getGenerator
()
public
function
getGenerator
()
{
{
if
(
null
!==
$this
->
generator
)
{
if
(
null
!==
$this
->
generator
)
{
...
@@ -90,11 +112,20 @@ class OC_Router {
...
@@ -90,11 +112,20 @@ class OC_Router {
return
$this
->
generator
=
new
UrlGenerator
(
$this
->
root
,
$this
->
context
);
return
$this
->
generator
=
new
UrlGenerator
(
$this
->
root
,
$this
->
context
);
}
}
/**
* Generate url based on $name and $parameters
*
* @param string $name Name of the route to use.
* @param array $parameters Parameters for the route
*/
public
function
generate
(
$name
,
$parameters
=
array
(),
$absolute
=
false
)
public
function
generate
(
$name
,
$parameters
=
array
(),
$absolute
=
false
)
{
{
return
$this
->
getGenerator
()
->
generate
(
$name
,
$parameters
,
$absolute
);
return
$this
->
getGenerator
()
->
generate
(
$name
,
$parameters
,
$absolute
);
}
}
/**
* Generate JSON response for routing in javascript
*/
public
static
function
JSRoutes
()
public
static
function
JSRoutes
()
{
{
// TODO: http caching
// TODO: http caching
...
...
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