3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\Common\Util;
23 * Static class containing most used debug methods.
25 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
26 * @link www.doctrine-project.org
28 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
29 * @author Jonathan Wage <jonwage@gmail.com>
30 * @author Roman Borschel <roman@code-factory.org>
31 * @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
36 * Private constructor (prevents from instantiation)
39 private function __construct() {}
42 * Prints a dump of the public, protected and private properties of $var.
44 * @link http://xdebug.org/
46 * @param integer $maxDepth Maximum nesting level for object properties
47 * @param boolean $stripTags Flag that indicate if output should strip HTML tags
49 public static function dump($var, $maxDepth = 2, $stripTags = true)
51 ini_set('html_errors', 'On');
53 if (extension_loaded('xdebug')) {
54 ini_set('xdebug.var_display_max_depth', $maxDepth);
57 $var = self::export($var, $maxDepth++);
61 $dump = ob_get_contents();
64 echo ($stripTags ? strip_tags(html_entity_decode($dump)) : $dump);
66 ini_set('html_errors', 'Off');
73 * @param int $maxDepth
76 public static function export($var, $maxDepth)
79 $isObj = is_object($var);
81 if ($isObj && in_array('Doctrine\Common\Collections\Collection', class_implements($var))) {
82 $var = $var->toArray();
89 foreach ($var as $k => $v) {
90 $return[$k] = self::export($v, $maxDepth - 1);
93 $return = new \stdclass();
94 if ($var instanceof \DateTime) {
95 $return->__CLASS__ = "DateTime";
96 $return->date = $var->format('c');
97 $return->timezone = $var->getTimeZone()->getName();
99 $reflClass = ClassUtils::newReflectionObject($var);
100 $return->__CLASS__ = ClassUtils::getClass($var);
102 if ($var instanceof \Doctrine\Common\Persistence\Proxy) {
103 $return->__IS_PROXY__ = true;
104 $return->__PROXY_INITIALIZED__ = $var->__isInitialized();
107 foreach ($reflClass->getProperties() as $reflProperty) {
108 $name = $reflProperty->getName();
110 $reflProperty->setAccessible(true);
111 $return->$name = self::export($reflProperty->getValue($var), $maxDepth - 1);
118 $return = is_object($var) ? get_class($var)
119 : (is_array($var) ? 'Array(' . count($var) . ')' : $var);
131 public static function toString($obj)
133 return method_exists('__toString', $obj) ? (string) $obj : get_class($obj) . '@' . spl_object_hash($obj);