DebugKit\Panel\VariablesPanel::shutdown PHP Method

shutdown() public method

Shutdown event
public shutdown ( Cake\Event\Event $event ) : void
$event Cake\Event\Event The event
return void
    public function shutdown(Event $event)
    {
        $controller = $event->subject();
        $errors = [];
        $walker = function (&$item) use(&$walker) {
            if ($item instanceof Collection || $item instanceof Query || $item instanceof ResultSet) {
                try {
                    $item = $item->toArray();
                } catch (\Cake\Database\Exception $e) {
                    //Likely issue is unbuffered query; fall back to __debugInfo
                    $item = array_map($walker, $item->__debugInfo());
                } catch (RuntimeException $e) {
                    // Likely a non-select query.
                    $item = array_map($walker, $item->__debugInfo());
                } catch (InvalidArgumentException $e) {
                    $item = array_map($walker, $item->__debugInfo());
                }
            } elseif ($item instanceof Closure || $item instanceof PDO || $item instanceof SimpleXMLElement) {
                $item = 'Unserializable object - ' . get_class($item);
            } elseif ($item instanceof Exception) {
                $item = sprintf('Unserializable object - %s. Error: %s in %s, line %s', get_class($item), $item->getMessage(), $item->getFile(), $item->getLine());
            } elseif (is_object($item) && method_exists($item, '__debugInfo')) {
                // Convert objects into using __debugInfo.
                $item = array_map($walker, $item->__debugInfo());
            }
            return $item;
        };
        // Copy so viewVars is not mutated.
        $vars = $controller->viewVars;
        array_walk_recursive($vars, $walker);
        foreach ($vars as $k => $v) {
            // Get the validation errors for Entity
            if ($v instanceof EntityInterface) {
                $errors[$k] = $this->_getErrors($v);
            } elseif ($v instanceof Form) {
                $formError = $v->errors();
                if (!empty($formError)) {
                    $errors[$k] = $formError;
                }
            }
        }
        $this->_data = ['content' => $vars, 'errors' => $errors];
    }