Skip to content

Commit 8c270f7

Browse files
committed
Merge pull request symfony#2479 from fabpot/debug-component
added documentation for the new Debug component
2 parents 38bbca1 + df35697 commit 8c270f7

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

components/debug.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.. index::
2+
single: Debug
3+
single: Components; Debug
4+
5+
The Debug Component
6+
===================
7+
8+
The Debug Component provides tools to ease debugging PHP code.
9+
10+
.. versionadded:: 2.3
11+
The Debug Component is new to Symfony 2.3. Previously, the classes were
12+
located in the ``HttpKernel`` component.
13+
14+
Installation
15+
------------
16+
17+
You can install the component in many different ways:
18+
19+
* Use the official Git repository (https://github.com/symfony/Debug);
20+
* :doc:`Install it via Composer </components/using_components>` (``symfony/debug`` on `Packagist`_).
21+
22+
Usage
23+
-----
24+
25+
The Debug component provides several tools to help you debug PHP code.
26+
Enabling them all is as easy as it can get::
27+
28+
use Symfony\Component\Debug\Debug;
29+
30+
Debug::enable();
31+
32+
The :method:`Symfony\\Component\\Debug\\Debug::enable` method registers an
33+
error handler and an exception handler. If the :doc:`ClassLoader component
34+
</components/class_loader>` is available, a special class loader is also
35+
registered.
36+
37+
Read the following sections for more information about the different available
38+
tools.
39+
40+
.. caution::
41+
42+
You should never enable the debug tools in a production environment as
43+
they might disclose sensitive information to the user.
44+
45+
Enabling the Error Handler
46+
--------------------------
47+
48+
The :class:`Symfony\\Component\\Debug\\ErrorHandler` class catches PHP errors
49+
and converts them to exceptions (of class :phpclass:`ErrorException` or
50+
:class:`Symfony\\Component\\Debug\\Exception\\FatalErrorException` for PHP
51+
fatal errors)::
52+
53+
use Symfony\Component\Debug\ErrorHandler;
54+
55+
ErrorHandler::register();
56+
57+
Enabling the Exception Handler
58+
------------------------------
59+
60+
The :class:`Symfony\\Component\\Debug\\ExceptionHandler` class catches
61+
uncaught PHP exceptions and converts them to a nice PHP response. It is useful
62+
in debug mode to replace the default PHP/XDebug output with something prettier
63+
and more useful::
64+
65+
use Symfony\Component\Debug\ExceptionHandler;
66+
67+
ExceptionHandler::register();
68+
69+
.. note::
70+
71+
If the :doc:`HttpFoundation component </components/http_foundation>` is
72+
available, the handler uses a Symfony Response object; if not, it falls
73+
back to a regular PHP response.
74+
75+
.. _Packagist: https://packagist.org/packages/symfony/debug

components/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The Components
99
config/index
1010
console/index
1111
css_selector
12+
debug
1213
dom_crawler
1314
dependency_injection/index
1415
event_dispatcher/index

components/map.rst.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
* :doc:`/components/css_selector`
2525

26+
* **Debug**
27+
28+
* :doc:`/components/debug`
29+
2630
* :doc:`/components/dependency_injection/index`
2731

2832
* :doc:`/components/dependency_injection/introduction`

0 commit comments

Comments
 (0)