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
27a3efcd
Commit
27a3efcd
authored
Aug 29, 2015
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed usage of the request service in the docs
parent
b65d9315
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
21 deletions
+30
-21
doc/providers.rst
doc/providers.rst
+4
-2
doc/providers/serializer.rst
doc/providers/serializer.rst
+4
-3
doc/providers/session.rst
doc/providers/session.rst
+4
-3
doc/providers/swiftmailer.rst
doc/providers/swiftmailer.rst
+2
-2
doc/services.rst
doc/services.rst
+6
-7
doc/usage.rst
doc/usage.rst
+10
-4
No files found.
doc/providers.rst
View file @
27a3efcd
...
@@ -158,14 +158,16 @@ given. If the default is also missing, it will use an empty string.
...
@@ -158,14 +158,16 @@ given. If the default is also missing, it will use an empty string.
You can now use this provider as follows::
You can now use this provider as follows::
use Symfony\Component\HttpFoundation\Request;
$app = new Silex\Application();
$app = new Silex\Application();
$app->register(new Acme\HelloServiceProvider(), array(
$app->register(new Acme\HelloServiceProvider(), array(
'hello.default_name' => 'Igor',
'hello.default_name' => 'Igor',
));
));
$app->get('/hello', function () use ($app) {
$app->get('/hello', function (
Request $request
) use ($app) {
$name = $
app['request']
->get('name');
$name = $
request
->get('name');
return $app['hello']($name);
return $app['hello']($name);
});
});
...
...
doc/providers/serializer.rst
View file @
27a3efcd
...
@@ -51,6 +51,7 @@ The ``SerializerServiceProvider`` provider provides a ``serializer`` service:
...
@@ -51,6 +51,7 @@ The ``SerializerServiceProvider`` provider provides a ``serializer`` service:
use Silex\Application;
use Silex\Application;
use Silex\Provider\SerializerServiceProvider;
use Silex\Provider\SerializerServiceProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Response;
$app = new Application();
$app = new Application();
...
@@ -58,18 +59,18 @@ The ``SerializerServiceProvider`` provider provides a ``serializer`` service:
...
@@ -58,18 +59,18 @@ The ``SerializerServiceProvider`` provider provides a ``serializer`` service:
$app->register(new SerializerServiceProvider());
$app->register(new SerializerServiceProvider());
// only accept content types supported by the serializer via the assert method.
// only accept content types supported by the serializer via the assert method.
$app->get("/pages/{id}.{_format}", function ($id) use ($app) {
$app->get("/pages/{id}.{_format}", function (
Request $request,
$id) use ($app) {
// assume a page_repository service exists that returns Page objects. The
// assume a page_repository service exists that returns Page objects. The
// object returned has getters and setters exposing the state.
// object returned has getters and setters exposing the state.
$page = $app['page_repository']->find($id);
$page = $app['page_repository']->find($id);
$format = $
app['request']
->getRequestFormat();
$format = $
request
->getRequestFormat();
if (!$page instanceof Page) {
if (!$page instanceof Page) {
$app->abort("No page found for id: $id");
$app->abort("No page found for id: $id");
}
}
return new Response($app['serializer']->serialize($page, $format), 200, array(
return new Response($app['serializer']->serialize($page, $format), 200, array(
"Content-Type" => $
app['request']
->getMimeType($format)
"Content-Type" => $
request
->getMimeType($format)
));
));
})->assert("_format", "xml|json")
})->assert("_format", "xml|json")
->assert("id", "\d+");
->assert("id", "\d+");
...
...
doc/providers/session.rst
View file @
27a3efcd
...
@@ -62,11 +62,12 @@ Usage
...
@@ -62,11 +62,12 @@ Usage
The Session provider provides a ``session`` service. Here is an example that
The Session provider provides a ``session`` service. Here is an example that
authenticates a user and creates a session for them::
authenticates a user and creates a session for them::
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Response;
$app->get('/login', function () use ($app) {
$app->get('/login', function (
Request $request
) use ($app) {
$username = $
app['request']
->server->get('PHP_AUTH_USER', false);
$username = $
request
->server->get('PHP_AUTH_USER', false);
$password = $
app['request']
->server->get('PHP_AUTH_PW');
$password = $
request
->server->get('PHP_AUTH_PW');
if ('igor' === $username && 'password' === $password) {
if ('igor' === $username && 'password' === $password) {
$app['session']->set('user', array('username' => $username));
$app['session']->set('user', array('username' => $username));
...
...
doc/providers/swiftmailer.rst
View file @
27a3efcd
...
@@ -86,9 +86,9 @@ Usage
...
@@ -86,9 +86,9 @@ Usage
The Swiftmailer provider provides a ``mailer`` service::
The Swiftmailer provider provides a ``mailer`` service::
$app->post('/feedback', function () use ($app) {
use Symfony\Component\HttpFoundation\Request;
$request = $app['request'];
$app->post('/feedback', function (Request $request) use ($app) {
$message = \Swift_Message::newInstance()
$message = \Swift_Message::newInstance()
->setSubject('[YourSite] Feedback')
->setSubject('[YourSite] Feedback')
->setFrom(array('noreply@yoursite.com'))
->setFrom(array('noreply@yoursite.com'))
...
...
doc/services.rst
View file @
27a3efcd
...
@@ -167,18 +167,17 @@ Core services
...
@@ -167,18 +167,17 @@ Core services
Silex defines a range of services.
Silex defines a range of services.
* **request**: Contains the current request object, which is an instance of
* **request_stack**: Controls the lifecycle of requests, an instance of
`Request
`RequestStack <http://api.symfony.com/master/Symfony/Component/HttpFoundation/RequestStack.html>` _.
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/Request.html>`_.
It gives you access to ``GET``, ``POST`` parameters and lots more!
It gives you access to ``GET``, ``POST`` parameters and lots more!
Example usage::
Example usage::
$id = $app['request
']
->get('id');
$id = $app['request
_stack']->getCurrentRequest()
->get('id');
This is only available when a request is being served; you can only access
A request is only available when a request is being served; you can only
it from within a controller, an application before/after middlewares, or an
access it from within a controller, an application before/after middlewares,
error handler.
or an
error handler.
* **routes**: The `RouteCollection
* **routes**: The `RouteCollection
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
<http://api.symfony.com/master/Symfony/Component/Routing/RouteCollection.html>`_
...
...
doc/usage.rst
View file @
27a3efcd
...
@@ -760,8 +760,11 @@ Cross-Site-Scripting attacks.
...
@@ -760,8 +760,11 @@ Cross-Site-Scripting attacks.
* **Escaping HTML**: PHP provides the ``htmlspecialchars`` function for this.
* **Escaping HTML**: PHP provides the ``htmlspecialchars`` function for this.
Silex provides a shortcut ``escape`` method::
Silex provides a shortcut ``escape`` method::
$app->get('/name', function (Silex\Application $app) {
use Symfony\Component\HttpFoundation\Request;
$name = $app['request']->get('name');
$app->get('/name', function (Request $request, Silex\Application $app) {
$name = $request->get('name');
return "You provided the name {$app->escape($name)}.";
return "You provided the name {$app->escape($name)}.";
});
});
...
@@ -771,8 +774,11 @@ Cross-Site-Scripting attacks.
...
@@ -771,8 +774,11 @@ Cross-Site-Scripting attacks.
* **Escaping JSON**: If you want to provide data in JSON format you should
* **Escaping JSON**: If you want to provide data in JSON format you should
use the Silex ``json`` function::
use the Silex ``json`` function::
$app->get('/name.json', function (Silex\Application $app) {
use Symfony\Component\HttpFoundation\Request;
$name = $app['request']->get('name');
$app->get('/name.json', function (Request $request, Silex\Application $app) {
$name = $request->get('name');
return $app->json(array('name' => $name));
return $app->json(array('name' => $name));
});
});
...
...
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