diff --git a/book/forms.rst b/book/forms.rst index 5fc28cc1368..1a16d84454c 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -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'); } diff --git a/book/page_creation.rst b/book/page_creation.rst index 5069f06186d..05d0f61b533 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -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; diff --git a/book/routing.rst b/book/routing.rst index 8091d3e668a..923d80332d5 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -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 @@ -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); diff --git a/book/security.rst b/book/security.rst index edf3172febd..fa9958dca1e 100644 --- a/book/security.rst +++ b/book/security.rst @@ -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 `. + +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 ----- @@ -2091,7 +2158,6 @@ Learn more from the Cookbook * :doc:`Access Control Lists (ACLs) ` * :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 diff --git a/book/validation.rst b/book/validation.rst index 7a4d4f82251..ea5315afaae 100644 --- a/book/validation.rst +++ b/book/validation.rst @@ -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 -------------- diff --git a/components/console/introduction.rst b/components/console/introduction.rst index ea60102dcd6..4ca2bcfe8c1 100644 --- a/components/console/introduction.rst +++ b/components/console/introduction.rst @@ -160,7 +160,7 @@ You can also set these colors and options inside the tagname:: // bold text on a yellow background $output->writeln('foo'); -.. verbosity-levels: +.. _verbosity-levels: Verbosity Levels ~~~~~~~~~~~~~~~~ diff --git a/components/dependency_injection/factories.rst b/components/dependency_injection/factories.rst index 9477a561683..f156d7a8fab 100644 --- a/components/dependency_injection/factories.rst +++ b/components/dependency_injection/factories.rst @@ -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( @@ -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')) diff --git a/components/form/introduction.rst b/components/form/introduction.rst index d28e68e51b3..0e6b06ed826 100644 --- a/components/form/introduction.rst +++ b/components/form/introduction.rst @@ -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`:: diff --git a/components/process.rst b/components/process.rst index f2e61fdabbe..5340f21d1fd 100644 --- a/components/process.rst +++ b/components/process.rst @@ -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 diff --git a/cookbook/bundles/remove.rst b/cookbook/bundles/remove.rst index 5607a0dbbb5..69ba500f2b6 100644 --- a/cookbook/bundles/remove.rst +++ b/cookbook/bundles/remove.rst @@ -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:: diff --git a/cookbook/console/logging.rst b/cookbook/console/logging.rst index b4c9ea9f872..21bd1162777 100644 --- a/cookbook/console/logging.rst +++ b/cookbook/console/logging.rst @@ -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 { @@ -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(); @@ -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 @@ -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; @@ -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(); diff --git a/cookbook/form/dynamic_form_modification.rst b/cookbook/form/dynamic_form_modification.rst index d05dc32fe59..cde1ea9adf9 100644 --- a/cookbook/form/dynamic_form_modification.rst +++ b/cookbook/form/dynamic_form_modification.rst @@ -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 `:: +:ref:`event subscriber `:: // src/Acme/DemoBundle/Form/Type/ProductType.php namespace Acme\DemoBundle\Form\Type; diff --git a/cookbook/logging/monolog_console.rst b/cookbook/logging/monolog_console.rst index 3a22b7dcfbc..7945193022e 100644 --- a/cookbook/logging/monolog_console.rst +++ b/cookbook/logging/monolog_console.rst @@ -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 ` 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 @@ -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. @@ -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 ` for more +information): .. configuration-block:: @@ -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 diff --git a/cookbook/session/sessions_directory.rst b/cookbook/session/sessions_directory.rst index 6ad7de0138d..ad662846f82 100644 --- a/cookbook/session/sessions_directory.rst +++ b/cookbook/session/sessions_directory.rst @@ -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. @@ -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 - - - + + + + + + + .. 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', + ), )); + diff --git a/reference/constraints/UniqueEntity.rst b/reference/constraints/UniqueEntity.rst index 7bc38e3ca45..02b39c045a3 100644 --- a/reference/constraints/UniqueEntity.rst +++ b/reference/constraints/UniqueEntity.rst @@ -217,7 +217,7 @@ Consider this example: - diff --git a/reference/forms/types/options/_error_bubbling_hint.rst b/reference/forms/types/options/_error_bubbling_hint.rst.inc similarity index 100% rename from reference/forms/types/options/_error_bubbling_hint.rst rename to reference/forms/types/options/_error_bubbling_hint.rst.inc diff --git a/reference/forms/types/options/label_attr.rst.inc b/reference/forms/types/options/label_attr.rst.inc index de834c4ae1b..f3ab274cec6 100644 --- a/reference/forms/types/options/label_attr.rst.inc +++ b/reference/forms/types/options/label_attr.rst.inc @@ -1,9 +1,9 @@ label_attr -~~~~~ +~~~~~~~~~~ **type**: ``array`` **default**: ``array()`` -Sets the html attributes for the ``