From cc77903ac8b2c08b23231018be659f66e340cd33 Mon Sep 17 00:00:00 2001 From: Ricard Clau Date: Tue, 5 Feb 2013 18:25:17 +0100 Subject: [PATCH] some missing formats --- cookbook/logging/monolog.rst | 101 ++++++++++++++++ cookbook/logging/monolog_email.rst | 59 ++++++++++ cookbook/templating/global_variables.rst | 70 ++++++++--- cookbook/web_services/php_soap_extension.rst | 116 +++++++++++-------- 4 files changed, 283 insertions(+), 63 deletions(-) diff --git a/cookbook/logging/monolog.rst b/cookbook/logging/monolog.rst index bfc27cda2d7..9c837db0dde 100644 --- a/cookbook/logging/monolog.rst +++ b/cookbook/logging/monolog.rst @@ -59,6 +59,7 @@ allows you to log the messages in several ways easily. .. code-block:: yaml + # app/config/config.yml monolog: handlers: applog: @@ -75,8 +76,10 @@ allows you to log the messages in several ways easily. syslog: type: syslog level: error + .. code-block:: xml + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('monolog', array( + 'handlers' => array( + 'applog' => array( + 'type' => 'stream', + 'path' => '/var/log/symfony.log', + 'level' => 'error', + ), + 'main' => array( + 'type' => 'fingers_crossed', + 'action_level' => 'warning', + 'handler' => 'file', + ), + 'file' => array( + 'type' => 'stream', + 'level' => 'debug', + ), + 'syslog' => array( + 'type' => 'syslog', + 'level' => 'error', + ), + ), + )); + The above configuration defines a stack of handlers which will be called in the order where they are defined. @@ -137,6 +166,7 @@ easily. Your formatter must implement .. code-block:: yaml + # app/config/config.yml services: my_formatter: class: Monolog\Formatter\JsonFormatter @@ -149,6 +179,7 @@ easily. Your formatter must implement .. code-block:: xml + + + .. code-block:: php + + // app/config/config.php + $container + ->register('my_formatter', 'Monolog\Formatter\JsonFormatter'); + + $container->loadFromExtension('monolog', array( + 'handlers' => array( + 'file' => array( + 'type' => 'stream', + 'level' => 'debug', + 'formatter' => 'my_formatter', + ), + ), + )); + Adding some extra data in the log messages ------------------------------------------ @@ -243,6 +291,59 @@ using a processor. level: debug formatter: monolog.formatter.session_request + .. code-block:: xml + + + + + + [%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%%\n + + + + + + + + + + + + + + .. code-block:: php + + // app/config/config.php + $container + ->register('monolog.formatter.session_request', 'Monolog\Formatter\LineFormatter') + ->addArgument('[%%datetime%%] [%%extra.token%%] %%channel%%.%%level_name%%: %%message%%\n'); + + $container + ->register('monolog.processor.session_request', 'Acme\MyBundle\SessionRequestProcessor') + ->addArgument(new Reference('session')) + ->addTag('monolog.processor', array('method' => 'processRecord')); + + $container->loadFromExtension('monolog', array( + 'handlers' => array( + 'main' => array( + 'type' => 'stream', + 'path' => '%kernel.logs_dir%/%kernel.environment%.log', + 'level' => 'debug', + 'formatter' => 'monolog.formatter.session_request', + ), + ), + )); + .. note:: If you use several handlers, you can also register the processor at the diff --git a/cookbook/logging/monolog_email.rst b/cookbook/logging/monolog_email.rst index 330d4a3de60..da5c11945a9 100644 --- a/cookbook/logging/monolog_email.rst +++ b/cookbook/logging/monolog_email.rst @@ -61,6 +61,31 @@ it is broken down. /> + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('monolog', array( + 'handlers' => array( + 'mail' => array( + 'type' => 'fingers_crossed', + 'action_level' => 'critical', + 'handler' => 'buffered', + ), + 'buffered' => array( + 'type' => 'buffer', + 'handler' => 'swift', + ), + 'swift' => array( + 'type' => 'swift_mailer', + 'from_email' => 'error@example.com', + 'to_email' => 'error@example.com', + 'subject' => 'An Error Occurred!', + 'level' => 'debug', + ), + ), + )); + The ``mail`` handler is a ``fingers_crossed`` handler which means that it is only triggered when the action level, in this case ``critical`` is reached. @@ -154,6 +179,40 @@ get logged on the server as well as the emails being sent: + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('monolog', array( + 'handlers' => array( + 'main' => array( + 'type' => 'fingers_crossed', + 'action_level' => 'critical', + 'handler' => 'grouped', + ), + 'grouped' => array( + 'type' => 'group', + 'members' => array('streamed', 'buffered'), + ), + 'streamed' => array( + 'type' => 'stream', + 'path' => '%kernel.logs_dir%/%kernel.environment%.log', + 'level' => 'debug', + ), + 'buffered' => array( + 'type' => 'buffer', + 'handler' => 'swift', + ), + 'swift' => array( + 'type' => 'swift_mailer', + 'from_email' => 'error@example.com', + 'to_email' => 'error@example.com', + 'subject' => 'An Error Occurred!', + 'level' => 'debug', + ), + ), + )); + + This uses the ``group`` handler to send the messages to the two group members, the ``buffered`` and the ``stream`` handlers. The messages will now be both written to the log file and emailed. diff --git a/cookbook/templating/global_variables.rst b/cookbook/templating/global_variables.rst index 93dddeaefb3..a95ef2478e0 100644 --- a/cookbook/templating/global_variables.rst +++ b/cookbook/templating/global_variables.rst @@ -7,19 +7,45 @@ How to Inject Variables into all Templates (i.e. Global Variables) Sometimes you want a variable to be accessible to all the templates you use. This is possible inside your ``app/config/config.yml`` file: -.. code-block:: yaml +.. configuration-block:: - # app/config/config.yml - twig: - # ... - globals: - ga_tracking: UA-xxxxx-x + .. code-block:: yaml + + # app/config/config.yml + twig: + # ... + globals: + ga_tracking: UA-xxxxx-x + + .. code-block:: xml + + + + + UA-xxxxx-x + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('twig', array( + ..., + 'globals' => array( + 'ga_tracking' => 'UA-xxxxx-x', + ), + )); Now, the variable ``ga_tracking`` is available in all Twig templates: -.. code-block:: html+jinja +.. configuration-block:: + + .. code-block:: html+jinja + +

The google tracking code is: {{ ga_tracking }}

-

The google tracking code is: {{ ga_tracking }}

+ .. code-block:: html+php + +

The google tracking code is:

It's that easy! You can also take advantage of the built-in :ref:`book-service-container-parameters` system, which lets you isolate or reuse the value: @@ -30,12 +56,30 @@ system, which lets you isolate or reuse the value: [parameters] ga_tracking: UA-xxxxx-x -.. code-block:: yaml +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + twig: + globals: + ga_tracking: "%ga_tracking%" + + .. code-block:: xml + + + + %ga_tracking% + + + .. code-block:: php - # app/config/config.yml - twig: - globals: - ga_tracking: "%ga_tracking%" + // app/config/config.php + $container->loadFromExtension('twig', array( + 'globals' => array( + 'ga_tracking' => '%ga_tracking%', + ), + )); The same variable is available exactly as before. diff --git a/cookbook/web_services/php_soap_extension.rst b/cookbook/web_services/php_soap_extension.rst index 14b5afc8106..d629f907c9d 100644 --- a/cookbook/web_services/php_soap_extension.rst +++ b/cookbook/web_services/php_soap_extension.rst @@ -68,11 +68,19 @@ a ``HelloService`` object properly: - - - + + + + .. code-block:: php + + // app/config/config.php + $container + ->register('hello_service', 'Acme\SoapBundle\Services\HelloService') + ->addArgument(new Reference('mailer')); + + Below is an example of a controller that is capable of handling a SOAP request. If ``indexAction()`` is accessible via the route ``/soap``, then the WSDL document can be retrieved via ``/soap?wsdl``. @@ -125,53 +133,61 @@ An example WSDL is below. .. code-block:: xml - - - - - - - - - - - - - - - - Hello World - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + Hello World + + + + + + + + + + + + + + + + + + + + + + + + +