Skip to content

Instantly share code, notes, and snippets.

@Berdir
Created April 21, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Berdir/7ba4cf0f6c4bcbd9a4a3 to your computer and use it in GitHub Desktop.
Save Berdir/7ba4cf0f6c4bcbd9a4a3 to your computer and use it in GitHub Desktop.
Trace me
diff --git a/core/lib/Drupal/Core/Form/FormCache.php b/core/lib/Drupal/Core/Form/FormCache.php
index a35000d..6ddcccc 100644
--- a/core/lib/Drupal/Core/Form/FormCache.php
+++ b/core/lib/Drupal/Core/Form/FormCache.php
@@ -212,8 +212,40 @@ public function setCache($form_build_id, $form, FormStateInterface $form_state)
$form_state->addBuildInfo('safe_strings', SafeMarkup::getAll());
if ($data = $form_state->getCacheableArray()) {
+ $this->traceMe($data);
$this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id, $data, $expire);
}
}
+ protected function traceMe(array $array, $depth = 0) {
+ if ($depth == 10) {
+ print str_repeat('- ', $depth) . "RECURSION\n";
+ return;
+ }
+ foreach ($array as $key => $value) {
+ if (is_array($value)) {
+ print str_repeat('- ', $depth) . "$key:\n";
+ $this->traceMe($value, $depth + 1);
+ }
+ elseif (is_object($value)) {
+ print str_repeat('- ', $depth) . "$key: " . get_class($value) . "\n";
+ if (method_exists($value, '__sleep')) {
+ $properties = $value->__sleep();
+ $reflection_object = new \ReflectionObject($value);
+ $value_array = [];
+
+ foreach ($properties as $property) {
+ $reflection_property = $reflection_object->getProperty($property);
+ $reflection_property->setAccessible(TRUE);
+ $value_array[$property] = $reflection_property->getValue($value);
+ }
+ }
+ else {
+ $value_array = (array) $value;
+ }
+ $this->traceMe($value_array, $depth + 1);
+ }
+ }
+ }
+
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment