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
e310b20a
Commit
e310b20a
authored
Dec 28, 2010
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow string responses which are converted to Response objects
parent
a98de661
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
7 deletions
+18
-7
README.md
README.md
+2
-3
example.php
example.php
+3
-4
src/Silex/Framework.php
src/Silex/Framework.php
+13
-0
No files found.
README.md
View file @
e310b20a
...
...
@@ -5,17 +5,16 @@ Silex is a simple web framework to develop simple websites:
require_once __DIR__.'/silex.phar';
use Symfony\Component\HttpFoundation\Response;
use Silex\Framework;
$framework = new Framework(array(
'/hello/:name' => function($name)
{
return
new Response('Hello '.$name)
;
return
"Hello $name"
;
},
'GET|PUT|POST /goodbye/:name' => function($name)
{
return
new Response('Goodbye '.$name)
;
return
"Goodbye $name"
;
},
));
...
...
example.php
View file @
e310b20a
...
...
@@ -3,17 +3,16 @@
require_once
__DIR__
.
'/silex.phar'
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Silex\Framework
;
$hello
=
function
(
$name
)
$hello
=
function
(
$name
)
{
return
new
Response
(
'Hello '
.
$name
)
;
return
"Hello
$name
"
;
};
$goodbye
=
function
(
$name
)
{
return
new
Response
(
'Goodbye '
.
$name
)
;
return
"Goodbye
$name
"
;
};
$framework
=
new
Framework
(
array
(
...
...
src/Silex/Framework.php
View file @
e310b20a
...
...
@@ -5,6 +5,7 @@ namespace Silex;
use
Symfony\Component\HttpKernel\HttpKernel
;
use
Symfony\Component\HttpKernel\Controller\ControllerResolver
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\EventDispatcher\EventDispatcher
;
use
Symfony\Component\EventDispatcher\Event
;
use
Symfony\Component\Routing\RouteCollection
;
...
...
@@ -46,6 +47,7 @@ class Framework extends HttpKernel
$dispatcher
=
new
EventDispatcher
();
$dispatcher
->
connect
(
'core.request'
,
array
(
$this
,
'parseRequest'
));
$dispatcher
->
connect
(
'core.view'
,
array
(
$this
,
'parseResponse'
));
$resolver
=
new
ControllerResolver
();
parent
::
__construct
(
$dispatcher
,
$resolver
);
...
...
@@ -77,4 +79,15 @@ class Framework extends HttpKernel
$request
->
attributes
->
add
(
$attributes
);
}
public
function
parseResponse
(
Event
$event
,
$response
)
{
// convert return value into a response object
if
(
!
$response
instanceof
Response
)
{
return
new
Response
((
string
)
$response
);
}
return
$response
;
}
}
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