123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- /*
- * This file is part of the symfony package.
- * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- * sfDebug provides some method to help debugging a symfony application.
- *
- * @package symfony
- * @subpackage debug
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- * @version SVN: $Id: sfDebug.class.php 13931 2008-12-10 22:43:27Z FabianLange $
- */
- class sfDebug
- {
- /**
- * Returns symfony information as an array.
- *
- * @return array An array of symfony information
- */
- public static function symfonyInfoAsArray()
- {
- return array(
- 'version' => SYMFONY_VERSION,
- 'path' => sfConfig::get('sf_symfony_lib_dir'),
- );
- }
- /**
- * Returns PHP information as an array.
- *
- * @return array An array of php information
- */
- public static function phpInfoAsArray()
- {
- $values = array(
- 'php' => phpversion(),
- 'os' => php_uname(),
- 'extensions' => get_loaded_extensions(),
- );
- // assign extension version
- if ($values['extensions'])
- {
- foreach($values['extensions'] as $key => $extension)
- {
- $values['extensions'][$key] = phpversion($extension) ? sprintf('%s (%s)', $extension, phpversion($extension)) : $extension;
- }
- }
- return $values;
- }
- /**
- * Returns PHP globals variables as a sorted array.
- *
- * @return array PHP globals
- */
- public static function globalsAsArray()
- {
- $values = array();
- foreach (array('cookie', 'server', 'get', 'post', 'files', 'env', 'session') as $name)
- {
- if (!isset($GLOBALS['_'.strtoupper($name)]))
- {
- continue;
- }
- $values[$name] = array();
- foreach ($GLOBALS['_'.strtoupper($name)] as $key => $value)
- {
- $values[$name][$key] = $value;
- }
- ksort($values[$name]);
- }
- ksort($values);
- return $values;
- }
- /**
- * Returns sfConfig variables as a sorted array.
- *
- * @return array sfConfig variables
- */
- public static function settingsAsArray()
- {
- $config = sfConfig::getAll();
- ksort($config);
- return $config;
- }
- /**
- * Returns request parameter holders as an array.
- *
- * @param sfRequest $request A sfRequest instance
- *
- * @return array The request parameter holders
- */
- public static function requestAsArray(sfRequest $request = null)
- {
- if (!$request)
- {
- return array();
- }
- return array(
- 'parameterHolder' => self::flattenParameterHolder($request->getParameterHolder(), true),
- 'attributeHolder' => self::flattenParameterHolder($request->getAttributeHolder(), true),
- );
- }
- /**
- * Returns response parameters as an array.
- *
- * @param sfResponse $response A sfResponse instance
- *
- * @return array The response parameters
- */
- public static function responseAsArray(sfResponse $response = null)
- {
- if (!$response)
- {
- return array();
- }
- return array(
- 'options' => $response->getOptions(),
- 'cookies' => method_exists($response, 'getCookies') ? $response->getCookies() : array(),
- 'httpHeaders' => method_exists($response, 'getHttpHeaders') ? $response->getHttpHeaders() : array(),
- 'javascripts' => method_exists($response, 'getJavascripts') ? $response->getJavascripts('ALL') : array(),
- 'stylesheets' => method_exists($response, 'getStylesheets') ? $response->getStylesheets('ALL') : array(),
- 'metas' => method_exists($response, 'getMetas') ? $response->getMetas() : array(),
- 'httpMetas' => method_exists($response, 'getHttpMetas') ? $response->getHttpMetas() : array(),
- );
- }
- /**
- * Returns user parameters as an array.
- *
- * @param sfUser $user A sfUser instance
- *
- * @return array The user parameters
- */
- public static function userAsArray(sfUser $user = null)
- {
- if (!$user)
- {
- return array();
- }
- return array(
- 'options' => $user->getOptions(),
- 'attributeHolder' => self::flattenParameterHolder($user->getAttributeHolder(), true),
- 'culture' => $user->getCulture(),
- );
- }
- /**
- * Returns a parameter holder as an array.
- *
- * @param sfParameterHolder $parameterHolder A sfParameterHolder instance
- * @param boolean $removeObjects when set to true, objects are removed. default is false for BC.
- *
- * @return array The parameter holder as an array
- */
- public static function flattenParameterHolder($parameterHolder, $removeObjects = false)
- {
- $values = array();
- if ($parameterHolder instanceof sfNamespacedParameterHolder)
- {
- foreach ($parameterHolder->getNamespaces() as $ns)
- {
- $values[$ns] = array();
- foreach ($parameterHolder->getAll($ns) as $key => $value)
- {
- $values[$ns][$key] = $value;
- }
- ksort($values[$ns]);
- }
- }
- else
- {
- foreach ($parameterHolder->getAll() as $key => $value)
- {
- $values[$key] = $value;
- }
- }
- if ($removeObjects)
- {
- $values = self::removeObjects($values);
- }
- ksort($values);
- return $values;
- }
- /**
- * Removes objects from the array by replacing them with a String containing the class name.
- *
- * @param array $values an array
- *
- * @return array The array without objects
- */
- public static function removeObjects($values)
- {
- $nvalues = array();
- foreach ($values as $key => $value)
- {
- if (is_array($value))
- {
- $nvalues[$key] = self::removeObjects($value);
- }
- else if (is_object($value))
- {
- $nvalues[$key] = sprintf('%s Object()', get_class($value));
- }
- else
- {
- $nvalues[$key] = $value;
- }
- }
- return $nvalues;
- }
- }
|