2015-08-17 17:00:26 -07:00
< ? php
/*
* This file is part of the Symfony package .
*
* ( c ) Fabien Potencier < fabien @ symfony . com >
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
namespace Symfony\Component\HttpKernel\DataCollector\Util ;
2018-11-23 12:29:20 +00:00
@ trigger_error ( 'The ' . __NAMESPACE__ . '\ValueExporter class is deprecated since Symfony 3.2 and will be removed in 4.0. Use the VarDumper component instead.' , E_USER_DEPRECATED );
2015-08-17 17:00:26 -07:00
/**
* @ author Bernhard Schussek < bschussek @ gmail . com >
2018-11-23 12:29:20 +00:00
*
* @ deprecated since version 3.2 , to be removed in 4.0 . Use the VarDumper component instead .
2015-08-17 17:00:26 -07:00
*/
class ValueExporter
{
/**
* Converts a PHP value to a string .
*
* @ param mixed $value The PHP value
2018-11-23 12:29:20 +00:00
* @ param int $depth Only for internal usage
* @ param bool $deep Only for internal usage
2015-08-17 17:00:26 -07:00
*
* @ return string The string representation of the given value
*/
public function exportValue ( $value , $depth = 1 , $deep = false )
{
2017-02-02 16:28:38 -08:00
if ( $value instanceof \__PHP_Incomplete_Class ) {
return sprintf ( '__PHP_Incomplete_Class(%s)' , $this -> getClassNameFromIncomplete ( $value ));
}
2018-11-23 12:29:20 +00:00
if ( \is_object ( $value )) {
if ( $value instanceof \DateTimeInterface ) {
return sprintf ( 'Object(%s) - %s' , \get_class ( $value ), $value -> format ( \DateTime :: ATOM ));
2015-08-17 17:00:26 -07:00
}
2018-11-23 12:29:20 +00:00
return sprintf ( 'Object(%s)' , \get_class ( $value ));
2015-08-17 17:00:26 -07:00
}
2018-11-23 12:29:20 +00:00
if ( \is_array ( $value )) {
2015-08-17 17:00:26 -07:00
if ( empty ( $value )) {
return '[]' ;
}
$indent = str_repeat ( ' ' , $depth );
$a = array ();
foreach ( $value as $k => $v ) {
2018-11-23 12:29:20 +00:00
if ( \is_array ( $v )) {
2015-08-17 17:00:26 -07:00
$deep = true ;
}
$a [] = sprintf ( '%s => %s' , $k , $this -> exportValue ( $v , $depth + 1 , $deep ));
}
if ( $deep ) {
return sprintf ( " [ \n %s%s \n %s] " , $indent , implode ( sprintf ( " , \n %s " , $indent ), $a ), str_repeat ( ' ' , $depth - 1 ));
}
2018-11-23 12:29:20 +00:00
$s = sprintf ( '[%s]' , implode ( ', ' , $a ));
if ( 80 > \strlen ( $s )) {
return $s ;
}
return sprintf ( " [ \n %s%s \n ] " , $indent , implode ( sprintf ( " , \n %s " , $indent ), $a ));
2015-08-17 17:00:26 -07:00
}
2018-11-23 12:29:20 +00:00
if ( \is_resource ( $value )) {
2015-08-17 17:00:26 -07:00
return sprintf ( 'Resource(%s#%d)' , get_resource_type ( $value ), $value );
}
if ( null === $value ) {
return 'null' ;
}
if ( false === $value ) {
return 'false' ;
}
if ( true === $value ) {
return 'true' ;
}
return ( string ) $value ;
}
2016-04-20 09:56:34 -07:00
private function getClassNameFromIncomplete ( \__PHP_Incomplete_Class $value )
{
$array = new \ArrayObject ( $value );
return $array [ '__PHP_Incomplete_Class_Name' ];
}
2015-08-17 17:00:26 -07:00
}