count() . " values\n";
$iterator = $object->getIterator();
while ($iterator->valid()) {
print_r($iterator->key() . "=" . $iterator->current() . "\n");
$iterator->next();
}
print_r($iterator);
foreach ($iterator as $key => $value) {
print_r($key . $value);
if (is_object($value)) {
$json .= '{ "text" : "' . $key . ' - ' . get_class($value) . '", "children" : [';
$json .= $this->recursiveObjectToJson($value);
$json .= ']}';
} elseif (is_array($value)) {
$json .= '{ "text" : "' . $key . '", "children" : [';
$json .= $this->recursiveObjectToJson($value);
$json .= ']}';
} else {
$json .= '{ "text" : "' . $value . '" }';
}
}
return $json;
}
private function ObjectToJson($object)
{
$json = '{
"core" : {
"data" : [';
$json .= $this->recursiveObjectToJson($object);
$json .= ']}}';
return $json;
}
/*it comes from https://www.php.net/manual/en/function.var-dump.php */
public function dump_debug($input, $collapse = false)
{
$recursive = function ($data, $level = 0) use (&$recursive, $collapse) {
global $argv;
$isTerminal = isset($argv);
if (!$isTerminal && $level == 0 && !defined("DUMP_DEBUG_SCRIPT")) {
define("DUMP_DEBUG_SCRIPT", true);
echo '' . "\n";
}
$type = !is_string($data) && is_callable($data) ? "Callable" : ucfirst(gettype($data));
$type_data = null;
$type_color = null;
$type_length = null;
switch ($type) {
case "String":
$type_color = "green";
$type_length = strlen($data);
$type_data = "\"" . htmlentities($data) . "\"";
break;
case "Double":
case "Float":
$type = "Float";
$type_color = "#0099c5";
$type_length = strlen($data);
$type_data = htmlentities($data);
break;
case "Integer":
$type_color = "red";
$type_length = strlen($data);
$type_data = htmlentities($data);
break;
case "Boolean":
$type_color = "#92008d";
$type_length = strlen($data);
$type_data = $data ? "TRUE" : "FALSE";
break;
case "NULL":
$type_length = 0;
break;
case "Array":
$type_length = count($data);
}
if (in_array($type, array("Object", "Array"))) {
$notEmpty = false;
foreach ($data as $key => $value) {
if (!$notEmpty) {
$notEmpty = true;
if ($isTerminal) {
echo $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "\n";
} else {
$id = substr(md5(rand() . ":" . $key . ":" . $level), 0, 8);
echo "
";
echo "" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . "";
echo "";
echo "
⤵";
echo "
";
echo "
";
}
for ($i = 0; $i <= $level; $i++) {
echo $isTerminal ? "| " : "| ";
}
echo $isTerminal ? "\n" : "
";
}
for ($i = 0; $i <= $level; $i++) {
echo $isTerminal ? "| " : "| ";
}
echo $isTerminal ? "[" . $key . "] => " : "[" . $key . "] => ";
call_user_func($recursive, $value, $level + 1);
}
if ($notEmpty) {
for ($i = 0; $i <= $level; $i++) {
echo $isTerminal ? "| " : "| ";
}
if (!$isTerminal) {
echo "
";
}
} else {
echo $isTerminal ?
$type . ($type_length !== null ? "(" . $type_length . ")" : "") . " " :
"
" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . " ";
}
} else {
echo $isTerminal ?
$type . ($type_length !== null ? "(" . $type_length . ")" : "") . " " :
"
" . $type . ($type_length !== null ? "(" . $type_length . ")" : "") . " ";
if ($type_data != null) {
echo $isTerminal ? $type_data : "
" . $type_data . "";
}
}
echo $isTerminal ? "\n" : "
";
};
call_user_func($recursive, $input);
}
/**
* @Route("/syf51", name="homepage")
*/
public function indexAction(Request $request)
{
print_r("
");
$session = $this->var_log($this->get('session'));
//$session = json_encode($this->get('session'));
print_r($session);
print_r($_COOKIE);
print_r($_SESSION);
print_r("
");
$_SESSION['test-user51'] = "user51";
// replace this example code with whatever you need
return $this->render('default/page.html.twig', [
'text' => 'homepage', 'json' => $session
]);
}
/**
* @Route("/syf51/page1", name="page1")
*/
public function page1Action(Request $request)
{
// replace this example code with whatever you need
return $this->render('default/page.html.twig', [
'text' => 'page1',
]);
}
/**
* @Route("/syf51/page2", name="page2")
*/
public function page2Action(Request $request)
{
// replace this example code with whatever you need
return $this->render('default/page.html.twig', [
'text' => 'page2',
]);
}
/**
* @Route("/syf51/number")
*/
public function number()
{
print_r("
");
print_r($this->get('session'));
print_r($_COOKIE);
print_r($_SESSION);
$number = random_int(0, 100);
return $this->render('lucky/number.html.twig', [
'number' => $number,
]);
}
}