Skip to content

Commit

Permalink
Merge branch '2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Jan 2, 2014
2 parents 33d27cc + 780cd22 commit b1e0886
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 54 deletions.
3 changes: 2 additions & 1 deletion book/forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,8 @@ that will house the logic for building the task form::
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('task')
$builder
->add('task')
->add('dueDate', null, array('widget' => 'single_text'))
->add('save', 'submit');
}
Expand Down
2 changes: 1 addition & 1 deletion book/page_creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ an entry when you generated the ``AcmeHelloBundle``:
$collection = new RouteCollection();
$collection->addCollection(
$loader->import('@AcmeHelloBundle/Resources/config/routing.php'),
'/',
'/'
);
return $collection;
Expand Down
18 changes: 10 additions & 8 deletions book/routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,15 @@ is *not* a number).
As a result, a URL like ``/blog/my-blog-post`` will now properly match the
``blog_show`` route.

+--------------------+-----------+-----------------------+
| URL | route | parameters |
+====================+===========+=======================+
| /blog/2 | blog | {page} = 2 |
+--------------------+-----------+-----------------------+
| /blog/my-blog-post | blog_show | {slug} = my-blog-post |
+--------------------+-----------+-----------------------+
+----------------------+-----------+-------------------------+
| URL | route | parameters |
+======================+===========+=========================+
| /blog/2 | blog | {page} = 2 |
+----------------------+-----------+-------------------------+
| /blog/my-blog-post | blog_show | {slug} = my-blog-post |
+----------------------+-----------+-------------------------+
| /blog/2-my-blog-post | blog_show | {slug} = 2-my-blog-post |
+----------------------+-----------+-------------------------+

.. sidebar:: Earlier Routes always Win

Expand Down Expand Up @@ -1131,7 +1133,7 @@ instead of simply ``/hello/{name}``:
$acmeHello = $loader->import(
"@AcmeHelloBundle/Resources/config/routing.php"
);
$acmeHello->setPrefix('/admin');
$acmeHello->addPrefix('/admin');
$collection->addCollection($acmeHello);
Expand Down
68 changes: 67 additions & 1 deletion book/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,73 @@ the user will be redirected to ``https``:
),
),
.. _book-security-securing-controller:

Securing a Controller
~~~~~~~~~~~~~~~~~~~~~

Protecting your application based on URL patterns is easy, but may not be
fine-grained enough in certain cases. When necessary, you can easily force
authorization from inside a controller::

// ...
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

public function helloAction($name)
{
if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}

// ...
}

.. _book-security-securing-controller-annotations:

Thanks to the SensioFrameworkExtraBundle, you can also secure your controller using annotations::

// ...
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

/**
* @Security("has_role('ROLE_ADMIN')")
*/
public function helloAction($name)
{
// ...
}

For more information, see the
:doc:`FrameworkExtraBundle documentation </bundles/SensioFrameworkExtraBundle/annotations/security>`.

Securing other Services
~~~~~~~~~~~~~~~~~~~~~~~

In fact, anything in Symfony can be protected using a strategy similar to
the one seen in the previous section. For example, suppose you have a service
(i.e. a PHP class) whose job is to send emails from one user to another.
You can restrict use of this class - no matter where it's being used from -
to users that have a specific role.

For more information on how you can use the Security component to secure
different services and methods in your application, see :doc:`/cookbook/security/securing_services`.

Access Control Lists (ACLs): Securing Individual Database Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Imagine you are designing a blog system where your users can comment on your
posts. Now, you want a user to be able to edit their own comments, but not
those of other users. Also, as the admin user, you yourself want to be able
to edit *all* comments.

The Security component comes with an optional access control list (ACL) system
that you can use when you need to control access to individual instances
of an object in your system. *Without* ACL, you can secure your system so that
only certain users can edit blog comments in general. But *with* ACL, you
can restrict or allow access on a comment-by-comment basis.

For more information, see the cookbook article: :doc:`/cookbook/security/acl`.

Users
-----

Expand Down Expand Up @@ -2091,7 +2158,6 @@ Learn more from the Cookbook
* :doc:`Access Control Lists (ACLs) </cookbook/security/acl>`
* :doc:`/cookbook/security/remember_me`

.. _`JMSSecurityExtraBundle`: http://jmsyst.com/bundles/JMSSecurityExtraBundle/1.2
.. _`FOSUserBundle`: https://github.com/FriendsOfSymfony/FOSUserBundle
.. _`implement the \Serializable interface`: http://php.net/manual/en/class.serializable.php
.. _`functions-online.com`: http://www.functions-online.com/sha1.html
Expand Down
2 changes: 1 addition & 1 deletion book/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ section .
The ``validateValue`` method returns a :class:`Symfony\\Component\\Validator\\ConstraintViolationList`
object, which acts just like an array of errors. Each error in the collection
is a :class:`Symfony\\Component\\Validator\\ConstraintViolation` object,
which holds the error message on its `getMessage` method.
which holds the error message on its ``getMessage`` method.

Final Thoughts
--------------
Expand Down
2 changes: 1 addition & 1 deletion components/console/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ You can also set these colors and options inside the tagname::
// bold text on a yellow background
$output->writeln('<bg=yellow;options=bold>foo</bg=yellow;options=bold>');

.. verbosity-levels:
.. _verbosity-levels:

Verbosity Levels
~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions components/dependency_injection/factories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ factory itself as a service:
$container->setDefinition('newsletter_factory', new Definition(
'%newsletter_factory.class%'
))
));
$container->setDefinition('newsletter_manager', new Definition(
'%newsletter_manager.class%'
))->setFactoryService(
Expand Down Expand Up @@ -193,7 +193,7 @@ in the previous example takes the ``templating`` service as an argument:
$container->setDefinition('newsletter_factory', new Definition(
'%newsletter_factory.class%'
))
));
$container->setDefinition('newsletter_manager', new Definition(
'%newsletter_manager.class%',
array(new Reference('templating'))
Expand Down
10 changes: 5 additions & 5 deletions components/form/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ object to read data off of the correct PHP superglobals (i.e. ``$_POST`` or
:class:`Symfony\\Component\\Form\\Extension\\HttpFoundation\\HttpFoundationExtension`
to your form factory::

use Symfony\Component\Form\Forms;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;

$formFactory = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
->getFormFactory();
$formFactory = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension())
->getFormFactory();

Now, when you process a form, you can pass the :class:`Symfony\\Component\\HttpFoundation\\Request`
object to :method:`Symfony\\Component\\Form\\Form::handleRequest`::
Expand Down
6 changes: 3 additions & 3 deletions components/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ and :method:`Symfony\\Component\\Process\\Process::getIncrementalErrorOutput`
methods returns the new outputs since the last call.

.. versionadded:: 2.4
The ``flushOutput()`` and ``flushErrorOutput()`` methods were added in Symfony 2.4.
The ``clearOutput()`` and ``clearErrorOutput()`` methods were added in Symfony 2.4.

The :method:`Symfony\\Component\\Process\\Process::flushOutput` method flushes
The :method:`Symfony\\Component\\Process\\Process::clearOutput` method clears
the contents of the output and
:method:`Symfony\\Component\\Process\\Process::flushErrorOutput` flushes
:method:`Symfony\\Component\\Process\\Process::clearErrorOutput` clears
the contents of the error output.

Getting real-time Process Output
Expand Down
2 changes: 1 addition & 1 deletion cookbook/bundles/remove.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ starting a project, but you'll probably want to eventually remove it.
---------------------------------------------

To disconnect the bundle from the framework, you should remove the bundle from
the ``Appkernel::registerBundles()`` method. The bundle is normally found in
the ``AppKernel::registerBundles()`` method. The bundle is normally found in
the ``$bundles`` array but the AcmeDemoBundle is only registered in a
development environment and you can find him in the if statement after::

Expand Down
12 changes: 7 additions & 5 deletions cookbook/console/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ container and use it to do the logging::
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use \Psr\Log\LoggerInterface;
use Psr\Log\LoggerInterface;

class GreetCommand extends ContainerAwareCommand
{
Expand Down Expand Up @@ -150,7 +150,8 @@ Then implement the actual listener::
$this->logger = $logger;
}

public function onConsoleException(ConsoleExceptionEvent $event) {
public function onConsoleException(ConsoleExceptionEvent $event)
{
$command = $event->getCommand();
$exception = $event->getException();

Expand All @@ -170,7 +171,7 @@ Then implement the actual listener::
In the code above, when any command throws an exception, the listener will
receive an event. You can simply log it by passing the logger service via the
service configuration. Your method receives a
:class:`Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent`` object,
:class:`Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent` object,
which has methods to get information about the event and the exception.

Logging non-0 exit statuses
Expand Down Expand Up @@ -241,7 +242,7 @@ First configure a listener for console terminate events in the service container
Then implement the actual listener::

// src/Acme/DemoBundle/EventListener/ConsoleExceptionListener.php
namespace Acme/DemoBundle\EventListener;
namespace Acme\DemoBundle\EventListener;

use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Psr\Log\LoggerInterface;
Expand All @@ -255,7 +256,8 @@ Then implement the actual listener::
$this->logger = $logger;
}

public function onConsoleTerminate(ConsoleTerminateEvent $event) {
public function onConsoleTerminate(ConsoleTerminateEvent $event)
{
$statusCode = $event->getExitCode();
$command = $event->getCommand();

Expand Down
2 changes: 1 addition & 1 deletion cookbook/form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Adding an Event Subscriber to a Form Class

For better reusability or if there is some heavy logic in your event listener,
you can also move the logic for creating the ``name`` field to an
:ref:`event subscriber <event_dispatcher-using-event-subscribers:ref:>`::
:ref:`event subscriber <event_dispatcher-using-event-subscribers>`::

// src/Acme/DemoBundle/Form/Type/ProductType.php
namespace Acme\DemoBundle\Form\Type;
Expand Down
21 changes: 11 additions & 10 deletions cookbook/logging/monolog_console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
How to Configure Monolog to Display Console Messages
====================================================

.. versionadded:: 2.3
This feature was introduced to the MonologBundle in version 2.4, which
was first packaged with Symfony at version 2.4 (but compatible with Symfony 2.3).
.. versionadded:: 2.4
This feature was introduced to the MonologBridge in Symfony 2.4.

It is possible to use the console to print messages for certain :ref:`verbosity-levels`
using the :class:`Symfony\\Component\\Console\\Output\\OutputInterface`
instance that is passed when a command gets executed.
It is possible to use the console to print messages for certain
:ref:`verbosity levels <verbosity-levels>` using the
:class:`Symfony\\Component\\Console\\Output\\OutputInterface` instance that
is passed when a command gets executed.

When a lot of logging has to happen, it's cumbersome to print information
depending on the verbosity settings (``-v``, ``-vv``, ``-vvv``) because the
Expand All @@ -32,7 +32,7 @@ For example::
}

Instead of using these semantic methods to test for each of the verbosity
levels, `MonologBundle`_ 2.4 provides a `ConsoleHandler`_ that listens to
levels, the `MonologBridge`_ provides a `ConsoleHandler`_ that listens to
console events and writes log messages to the console output depending on the
current log level and the console verbosity.

Expand Down Expand Up @@ -96,8 +96,9 @@ With the ``verbosity_levels`` option you can adapt the mapping between
verbosity and log level. In the given example it will also show notices in
normal verbosity mode (instead of warnings only). Additionally, it will only
use messages logged with the custom ``my_channel`` channel and it changes the
display style via a custom formatter. See also the :doc:`reference/configuration/monolog`
for more information:
display style via a custom formatter (see the
:doc:`MonologBundle reference </reference/configuration/monolog>` for more
information):

.. configuration-block::

Expand Down Expand Up @@ -180,4 +181,4 @@ for more information:
;
.. _ConsoleHandler: https://github.com/symfony/MonologBridge/blob/master/Handler/ConsoleHandler.php
.. _MonologBundle: https://github.com/symfony/MonologBundle
.. _MonologBridge: https://github.com/symfony/MonologBridge
46 changes: 38 additions & 8 deletions cookbook/session/sessions_directory.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
.. index::
single: Sessions, sessions directory

Configuring the Directory where Sessions Files are Saved
Configuring the Directory Where Sessions Files are Saved
========================================================

By default, Symfony stores the session data in the cache directory. This
means that when you clear the cache, any current sessions will also be
deleted.
By default, Symfony stores the session data in files in the cache
directory ``%kernel.cache_dir%/sessions``. This means that when you clear
the cache, any current sessions will also be deleted.

.. note::

If the ``session`` configuration key is set to ``~``, Symfony will use the
global PHP ini values for ``session.save_handler`` and associated
``session.save_path`` from ``php.ini``.

.. note::

While the Symfony Full Stack Framework defaults to using the
``session.handler.native_file``, the Symfony Standard Edition is
configured to use PHP's global session settings by default and therefor
sessions will be stored according to the ``session.save_path`` location
and will not be deleted when clearing the cache.

Using a different directory to save session data is one method to ensure
that your current sessions aren't lost when you clear Symfony's cache.
Expand All @@ -30,18 +44,34 @@ session directory to ``app/sessions``:
# app/config/config.yml
framework:
session:
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/sessions"
.. code-block:: xml
<!-- app/config/config.xml -->
<framework:config>
<framework:session save-path="%kernel.root_dir%/sessions" />
</framework:config>
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
>
<framework:config>
<framework:session handler-id="session.handler.native_file" />
<framework:session save-path="%kernel.root_dir%/sessions" />
</framework:config>
</container>
.. code-block:: php
// app/config/config.php
$container->loadFromExtension('framework', array(
'session' => array('save-path' => "%kernel.root_dir%/sessions"),
'session' => array(
'handler-id' => 'session.handler.native_file',
'save-path' => '%kernel.root_dir%/sessions',
),
));
2 changes: 1 addition & 1 deletion reference/constraints/UniqueEntity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Consider this example:
<class name="Acme\AdministrationBundle\Entity\Service">
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
<option name="field">
<option name="fields">
<value>host</value>
<value>port</value>
</option>
Expand Down
Loading

0 comments on commit b1e0886

Please sign in to comment.