/**
  * Converts a PHP variable to a string.
  *
  * @param mixed $var
  *        	A PHP variable
  *        	
  * @return string The string representation of the variable
  */
 protected function varToString($var)
 {
     if (null === $this->valueExporter) {
         $this->valueExporter = new ValueExporter();
     }
     return $this->valueExporter->exportValue($var);
 }
 public function dumpValue($value)
 {
     if (null === $this->valueExporter) {
         $this->valueExporter = new ValueExporter();
     }
     return $this->valueExporter->exportValue($value);
 }
Example #3
0
 public function testIncompleteClass()
 {
     $foo = new \__PHP_Incomplete_Class();
     $array = new \ArrayObject($foo);
     $array['__PHP_Incomplete_Class_Name'] = 'AppBundle/Foo';
     $this->assertSame('__PHP_Incomplete_Class(AppBundle/Foo)', $this->valueExporter->exportValue($foo));
 }
 public function testDateTimeImmutable()
 {
     if (!class_exists('DateTimeImmutable', false)) {
         $this->markTestSkipped('Test skipped, class DateTimeImmutable does not exist.');
     }
     $dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
     $this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
 }
Example #5
0
 protected function prepareParams($params)
 {
     $data = array();
     foreach ($params as $key => $value) {
         $data[$key] = htmlentities($this->exporter->exportValue($value), ENT_QUOTES, 'UTF-8', false);
     }
     return $data;
 }
Example #6
0
 protected function prepareParams($params)
 {
     $data = array();
     foreach ($params as $key => $value) {
         if (is_object($value) && Str::is('Illuminate\\*\\Events\\*', get_class($value))) {
             $value = $this->prepareParams(get_object_vars($value));
         }
         $data[$key] = htmlentities($this->exporter->exportValue($value), ENT_QUOTES, 'UTF-8', false);
     }
     return $data;
 }
 public function testCollectConfig()
 {
     $this->builder->add('id', 'text');
     $this->builder->add('name', 'text', array('format' => '#%s!', 'title' => 'name'));
     $table = $this->builder->getTable();
     $valueExporter = new ValueExporter();
     $dataCollector = new TableDataCollector($valueExporter);
     $this->resolvedOptions['_passed_options'] = array('a' => 1, 'b' => 'x');
     $dataCollector->collectConfig($table, null, $this->resolvedOptions);
     $columns = $this->builder->getColumns();
     $expected = array('test' => array('id' => 'foo', 'name' => 'foo', 'type' => 'foo', 'type_class' => 'EMC\\TableBundle\\Tests\\Table\\Type\\FooType', 'passed_options' => array('a' => 1, 'b' => 'x'), 'resolved_options' => array('allow_select' => 'false', 'attrs' => '[]', 'caption' => '', 'data' => 'null', 'data_provider' => $valueExporter->exportValue($this->dataProvider), 'default_sorts' => '[]', 'limit' => '10', 'name' => 'foo', 'params' => '[]', 'route' => '_table', 'rows_pad' => 'true', 'rows_params' => '[]', 'subtable' => 'null', 'subtable_options' => '[]', 'subtable_params' => '[]', 'subtable_params' => '[]', 'export' => '[]', 'export_route' => '_table_export', 'select_route' => '_table_select'), 'columns' => array('id' => array('id' => 'id', 'name' => 'id', 'type' => NULL, 'type_class' => get_class($columns['id']->getType()), 'passed_options' => array('name' => 'id', 'params' => '[0 => id]', 'allow_sort' => 'false'), 'resolved_options' => array('name' => 'id', 'title' => '', 'params' => '[0 => id]', 'attrs' => '[]', 'data' => 'null', 'default' => 'null', 'format' => 'null', 'allow_sort' => 'false', 'allow_filter' => 'false', 'width' => 'null', 'anchor_route' => 'null', 'anchor_params' => '[]', 'anchor_args' => '[]', 'anchor_text' => '', 'anchor_title' => '')), 'name' => array('id' => 'name', 'name' => 'name', 'type' => NULL, 'type_class' => get_class($columns['name']->getType()), 'passed_options' => array('format' => '#%s!', 'title' => 'name', 'name' => 'name', 'params' => '[0 => name]', 'allow_sort' => '[0 => name, 1 => id]', 'allow_filter' => 'true'), 'resolved_options' => array('name' => 'name', 'title' => 'name', 'params' => '[0 => name]', 'attrs' => '[]', 'data' => 'null', 'default' => 'null', 'format' => '#%s!', 'allow_sort' => '[0 => name, 1 => id]', 'allow_filter' => 'true', 'width' => 'null', 'anchor_route' => 'null', 'anchor_params' => '[]', 'anchor_args' => '[]', 'anchor_text' => '', 'anchor_title' => '')))));
     $this->assertEquals($expected, $dataCollector->getTables());
 }
 public function exportValue($value, $depth = 1, $deep = false)
 {
     if (is_a($value, 'Closure')) {
         $reflector = new \ReflectionObject($value);
         return (string) $reflector->getMethod('__invoke');
     }
     return parent::exportValue($value, $depth, $deep);
 }
Example #9
0
 /**
  * @deprecated since 3.2, to be removed in 4.0. Use the dumpData() method instead.
  */
 public function dumpValue($value)
 {
     @trigger_error(sprintf('The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use the dumpData() method instead.', __METHOD__), E_USER_DEPRECATED);
     if (null === $this->valueExporter) {
         $this->valueExporter = new ValueExporter();
     }
     return $this->valueExporter->exportValue($value);
 }
Example #10
0
 /**
  * Converts a PHP variable to a string.
  *
  * @param mixed $var A PHP variable
  *
  * @return string The string representation of the variable
  *
  * @deprecated Deprecated since version 3.2, to be removed in 4.0. Use cloneVar() instead.
  */
 protected function varToString($var)
 {
     @trigger_error(sprintf('The %() method is deprecated since version 3.2 and will be removed in 4.0. Use cloneVar() instead.', __METHOD__), E_USER_DEPRECATED);
     if (null === $this->valueExporter) {
         $this->valueExporter = new ValueExporter();
     }
     return $this->valueExporter->exportValue($var);
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 protected function cloneVar($var, $isClass = false)
 {
     if ($var instanceof Data) {
         return $var;
     }
     if (null === $this->cloner) {
         if (class_exists(ClassStub::class)) {
             $this->cloner = new VarCloner();
             $this->cloner->setMaxItems(25);
             $this->cloner->addCasters(array('*' => function ($v, array $a, Stub $s, $isNested) {
                 if ($isNested && !$v instanceof \DateTimeInterface) {
                     $s->cut = -1;
                     $a = array();
                 }
                 return $a;
             }, \Exception::class => function (\Exception $e, array $a, Stub $s) {
                 if (isset($a[$k = "Exceptionprevious"])) {
                     unset($a[$k]);
                     ++$s->cut;
                 }
                 return $a;
             }, FormInterface::class => function (FormInterface $f, array $a) {
                 return array(Caster::PREFIX_VIRTUAL . 'name' => $f->getName(), Caster::PREFIX_VIRTUAL . 'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())));
             }, ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
                 return array(Caster::PREFIX_VIRTUAL . 'root' => $v->getRoot(), Caster::PREFIX_VIRTUAL . 'path' => $v->getPropertyPath(), Caster::PREFIX_VIRTUAL . 'value' => $v->getInvalidValue());
             }));
         } else {
             @trigger_error(sprintf('Using the %s() method without the VarDumper component is deprecated since version 3.2 and won\'t be supported in 4.0. Install symfony/var-dumper version 3.2 or above.', __METHOD__), E_USER_DEPRECATED);
             $this->cloner = false;
         }
     }
     if (false === $this->cloner) {
         if (null === $this->valueExporter) {
             $this->valueExporter = new ValueExporter();
         }
         return $this->valueExporter->exportValue($var);
     }
     if (null === $var) {
         $type = $hash = 'null';
     } elseif (array() === $var) {
         $type = $hash = 'array';
     } elseif ('object' === ($type = gettype($var))) {
         $hash = spl_object_hash($var);
     } elseif ('double' === $type) {
         $hash = (string) $var;
     } elseif ('integer' === $type || 'string' === $type) {
         $hash = $var;
     } else {
         $type = null;
     }
     if (null !== $type && null !== ($cache =& $this->clonerCache[$type][$hash])) {
         return $cache;
     }
     if ($isClass) {
         return $cache = $this->cloner->cloneVar(array(new ClassStub($var)))->seek(0);
     }
     return $cache = $this->cloner->cloneVar($var);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function extractViewVariables(FormView $view)
 {
     $data = array();
     // Set the ID in case no FormInterface object was collected for this
     // view
     if (isset($view->vars['id'])) {
         $data['id'] = $view->vars['id'];
     }
     foreach ($view->vars as $varName => $value) {
         $data['view_vars'][$varName] = $this->valueExporter->exportValue($value);
     }
     ksort($data['view_vars']);
     return $data;
 }
Example #13
0
 public function collectData(TableInterface $table, $data = null, array $options = array())
 {
     if (!isset($options['_tid'])) {
         throw new \RuntimeException();
     }
     $id = $options['_tid'];
     $this->init();
     if (!isset($this->data['tables'][$id])) {
         $this->extractConfig($table, $data, $options);
     }
     $data =& $this->data['tables'][$id];
     $data['query_result'] = array('query' => $this->valueExporter->exportValue($options['_query']), 'total' => $table->getData()->getCount());
     $rows = $table->getData()->getRows();
     $count = count($rows);
     for ($idx = 0; $idx < $count; $idx++) {
         $row = $rows[$idx];
         $data['query_result']['rows ' . $idx] = $this->valueExporter->exportValue($row);
         if ($idx === 10) {
             $data['query_result']['...'] = '';
             $idx = max($idx, count($rows) - 4);
         }
     }
     unset($data);
 }
Example #14
0
 public function testDateTimeImmutable()
 {
     $dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
     $this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
 }