Development

/branches/1.0/lib/debug/sfDebug.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/debug/sfDebug.class.php

Revision 3785, 3.7 kB (checked in by fabien, 7 years ago)

fixed getCookies() call in sfDebug when using sfConsoleResponse (closes #1666)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfDebug provides some method to help debugging a symfony application.
13  *
14  * @package    symfony
15  * @subpackage debug
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfDebug
20 {
21   /**
22    * Returns PHP information as an array.
23    *
24    * @return array An array of php information
25    */
26   public static function phpInfoAsArray()
27   {
28     $values = array(
29       'php'        => phpversion(),
30       'os'         => php_uname(),
31       'extensions' => get_loaded_extensions(),
32     );
33
34     return $values;
35   }
36
37   /**
38    * Returns PHP globals variables as a sorted array.
39    *
40    * @return array PHP globals
41    */
42   public static function globalsAsArray()
43   {
44     $values = array();
45     foreach (array('cookie', 'server', 'get', 'post', 'files', 'env', 'session') as $name)
46     {
47       if (!isset($GLOBALS['_'.strtoupper($name)]))
48       {
49         continue;
50       }
51
52       $values[$name] = array();
53       foreach ($GLOBALS['_'.strtoupper($name)] as $key => $value)
54       {
55         $values[$name][$key] = $value;
56       }
57       ksort($values[$name]);
58     }
59
60     ksort($values);
61
62     return $values;
63   }
64
65   /**
66    * Returns sfConfig variables as a sorted array.
67    *
68    * @return array sfConfig variables
69    */
70   public static function settingsAsArray()
71   {
72     $config = sfConfig::getAll();
73
74     ksort($config);
75
76     return $config;
77   }
78
79   /**
80    * Returns request parameter holders as an array.
81    *
82    * @param sfRequest A sfRequest instance
83    *
84    * @return array The request parameter holders
85    */
86   public static function requestAsArray($request)
87   {
88     if ($request)
89     {
90       $values = array(
91         'parameterHolder' => self::flattenParameterHolder($request->getParameterHolder()),
92         'attributeHolder' => self::flattenParameterHolder($request->getAttributeHolder()),
93       );
94     }
95     else
96     {
97       $values = array('parameterHolder' => array(), 'attributeHolder' => array());
98     }
99
100     return $values;
101   }
102
103   /**
104    * Returns response parameters as an array.
105    *
106    * @param sfResponse A sfResponse instance
107    *
108    * @return array The response parameters
109    */
110   public static function responseAsArray($response)
111   {
112     if ($response)
113     {
114       $values = array(
115         'cookies'         => array(),
116         'httpHeaders'     => array(),
117         'parameterHolder' => self::flattenParameterHolder($response->getParameterHolder()),
118       );
119       if (method_exists($response, 'getHttpHeaders'))
120       {
121         foreach ($response->getHttpHeaders() as $key => $value)
122         {
123           $values['httpHeaders'][$key] = $value;
124         }
125       }
126
127       if (method_exists($response, 'getCookies'))
128       {
129         $cookies = array();
130         foreach ($response->getCookies() as $key => $value)
131         {
132           $values['cookies'][$key] = $value;
133         }
134       }
135     }
136     else
137     {
138       $values = array('cookies' => array(), 'httpHeaders' => array(), 'parameterHolder' => array());
139     }
140
141     return $values;
142   }
143
144   /**
145    * Returns a parameter holder as an array.
146    *
147    * @param sfParameterHolder A sfParameterHolder instance
148    *
149    * @return array The parameter holder as an array
150    */
151   public static function flattenParameterHolder($parameterHolder)
152   {
153     $values = array();
154     foreach ($parameterHolder->getNamespaces() as $ns)
155     {
156       $values[$ns] = array();
157       foreach ($parameterHolder->getAll($ns) as $key => $value)
158       {
159         $values[$ns][$key] = $value;
160       }
161       ksort($values[$ns]);
162     }
163
164     ksort($values);
165
166     return $values;
167   }
168 }
169
Note: See TracBrowser for help on using the browser.