Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
74a1a05d
Commit
74a1a05d
authored
Jan 06, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add phpdoc to Framework
parent
717e1453
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
2 deletions
+119
-2
src/Silex/Framework.php
src/Silex/Framework.php
+119
-2
No files found.
src/Silex/Framework.php
View file @
74a1a05d
...
@@ -31,6 +31,15 @@ class Framework extends HttpKernel
...
@@ -31,6 +31,15 @@ class Framework extends HttpKernel
protected
$routes
;
protected
$routes
;
protected
$errorHandlers
=
array
();
protected
$errorHandlers
=
array
();
/**
* Constructor.
*
* Takes a route map argument (assoc array). The key is (optional) a pipe '|'
* delimited list of HTTP methods followed by a single space ' ', followed by
* the path pattern to match. The value is a callable.
*
* @param array $map Route map, mapping patterns to callables
*/
public
function
__construct
(
array
$map
=
null
)
public
function
__construct
(
array
$map
=
null
)
{
{
$this
->
routes
=
new
RouteCollection
();
$this
->
routes
=
new
RouteCollection
();
...
@@ -48,6 +57,20 @@ class Framework extends HttpKernel
...
@@ -48,6 +57,20 @@ class Framework extends HttpKernel
parent
::
__construct
(
$dispatcher
,
$resolver
);
parent
::
__construct
(
$dispatcher
,
$resolver
);
}
}
/**
* Map a pattern to a callable.
*
* You can optionally specify HTTP methods that should be matched.
*
* This method is chainable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
* @param string $method Matched HTTP methods, multiple can be supplied,
* delimited by a pipe character '|', eg. 'GET|POST'.
*
* @return $this
*/
public
function
match
(
$pattern
,
$to
,
$method
=
null
)
public
function
match
(
$pattern
,
$to
,
$method
=
null
)
{
{
$requirements
=
array
();
$requirements
=
array
();
...
@@ -62,6 +85,16 @@ class Framework extends HttpKernel
...
@@ -62,6 +85,16 @@ class Framework extends HttpKernel
return
$this
;
return
$this
;
}
}
/**
* Map a GET request to a callable.
*
* This method is chainable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return $this
*/
public
function
get
(
$pattern
,
$to
)
public
function
get
(
$pattern
,
$to
)
{
{
$this
->
match
(
$pattern
,
$to
,
'GET'
);
$this
->
match
(
$pattern
,
$to
,
'GET'
);
...
@@ -69,6 +102,16 @@ class Framework extends HttpKernel
...
@@ -69,6 +102,16 @@ class Framework extends HttpKernel
return
$this
;
return
$this
;
}
}
/**
* Map a POST request to a callable.
*
* This method is chainable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return $this
*/
public
function
post
(
$pattern
,
$to
)
public
function
post
(
$pattern
,
$to
)
{
{
$this
->
match
(
$pattern
,
$to
,
'POST'
);
$this
->
match
(
$pattern
,
$to
,
'POST'
);
...
@@ -76,6 +119,16 @@ class Framework extends HttpKernel
...
@@ -76,6 +119,16 @@ class Framework extends HttpKernel
return
$this
;
return
$this
;
}
}
/**
* Map a PUT request to a callable.
*
* This method is chainable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return $this
*/
public
function
put
(
$pattern
,
$to
)
public
function
put
(
$pattern
,
$to
)
{
{
$this
->
match
(
$pattern
,
$to
,
'PUT'
);
$this
->
match
(
$pattern
,
$to
,
'PUT'
);
...
@@ -83,6 +136,16 @@ class Framework extends HttpKernel
...
@@ -83,6 +136,16 @@ class Framework extends HttpKernel
return
$this
;
return
$this
;
}
}
/**
* Map a DELETE request to a callable.
*
* This method is chainable.
*
* @param string $pattern Matched route pattern
* @param mixed $to Callback that returns the response when matched
*
* @return $this
*/
public
function
delete
(
$pattern
,
$to
)
public
function
delete
(
$pattern
,
$to
)
{
{
$this
->
match
(
$pattern
,
$to
,
'DELETE'
);
$this
->
match
(
$pattern
,
$to
,
'DELETE'
);
...
@@ -90,6 +153,23 @@ class Framework extends HttpKernel
...
@@ -90,6 +153,23 @@ class Framework extends HttpKernel
return
$this
;
return
$this
;
}
}
/**
* Register an error handler.
*
* Error handlers are simple callables which take a single Exception
* as an argument. If a controller throws an exception, an error handler
* can return a specific response.
*
* When an exception occurs, all registered error handlers will be called.
* The first response a handler returns (it may also return nothing) will
* then be served.
*
* This method is chainable.
*
* @param mixed $callback Error handler callback, takes an Exception argument
*
* @return $this
*/
public
function
error
(
$callback
)
public
function
error
(
$callback
)
{
{
$this
->
errorHandlers
[]
=
$callback
;
$this
->
errorHandlers
[]
=
$callback
;
...
@@ -97,6 +177,13 @@ class Framework extends HttpKernel
...
@@ -97,6 +177,13 @@ class Framework extends HttpKernel
return
$this
;
return
$this
;
}
}
/**
* Handle the request and deliver the response.
*
* @param Request $request Request to process
*
* @return $this
*/
public
function
run
(
Request
$request
=
null
)
public
function
run
(
Request
$request
=
null
)
{
{
if
(
null
===
$request
)
{
if
(
null
===
$request
)
{
...
@@ -106,6 +193,11 @@ class Framework extends HttpKernel
...
@@ -106,6 +193,11 @@ class Framework extends HttpKernel
$this
->
handle
(
$request
)
->
send
();
$this
->
handle
(
$request
)
->
send
();
}
}
/**
* Parse a route map and create routes
*
* @see __construct()
*/
protected
function
parseRouteMap
(
array
$map
)
{
protected
function
parseRouteMap
(
array
$map
)
{
foreach
(
$map
as
$pattern
=>
$to
)
{
foreach
(
$map
as
$pattern
=>
$to
)
{
$method
=
null
;
$method
=
null
;
...
@@ -118,6 +210,11 @@ class Framework extends HttpKernel
...
@@ -118,6 +210,11 @@ class Framework extends HttpKernel
}
}
}
}
/**
* Handler for core.request
*
* @see __construct()
*/
public
function
parseRequest
(
Event
$event
)
public
function
parseRequest
(
Event
$event
)
{
{
$request
=
$event
->
get
(
'request'
);
$request
=
$event
->
get
(
'request'
);
...
@@ -136,6 +233,13 @@ class Framework extends HttpKernel
...
@@ -136,6 +233,13 @@ class Framework extends HttpKernel
$request
->
attributes
->
add
(
$attributes
);
$request
->
attributes
->
add
(
$attributes
);
}
}
/**
* Handler for core.view
*
* Converts string responses to Response objects.
*
* @see __construct()
*/
public
function
parseResponse
(
Event
$event
,
$response
)
public
function
parseResponse
(
Event
$event
,
$response
)
{
{
// convert return value into a response object
// convert return value into a response object
...
@@ -146,8 +250,14 @@ class Framework extends HttpKernel
...
@@ -146,8 +250,14 @@ class Framework extends HttpKernel
return
$response
;
return
$response
;
}
}
// use the first non-null handler response
/**
// but execute all error handlers
* Handler for core.exception
*
* Executes all registered error handlers and sets the first response
* to be sent to the client.
*
* @see error()
*/
public
function
handleException
(
Event
$event
)
public
function
handleException
(
Event
$event
)
{
{
$exception
=
$event
->
get
(
'exception'
);
$exception
=
$event
->
get
(
'exception'
);
...
@@ -163,6 +273,13 @@ class Framework extends HttpKernel
...
@@ -163,6 +273,13 @@ class Framework extends HttpKernel
}
}
}
}
/**
* Convenience method to create a new instance of Framework.
*
* @param array $map
*
* @return instance of Framework
*/
public
static
function
create
(
array
$map
=
null
)
public
static
function
create
(
array
$map
=
null
)
{
{
return
new
static
(
$map
);
return
new
static
(
$map
);
...
...
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