generic path display callback, can be configured in the settings; purpose is to show relevant path info and hide
as much of the path as possible.
public static shortenPath ( string $file ) : string | ||
$file | string | |
return | string |
public function parse(&$variable) { if (!$variable instanceof Closure) { return false; } $this->name = 'Closure'; $reflection = new ReflectionFunction($variable); $ret = array('Parameters' => array()); if ($val = $reflection->getParameters()) { foreach ($val as $parameter) { // todo http://php.net/manual/en/class.reflectionparameter.php $ret['Parameters'][] = $parameter->name; } } if ($val = $reflection->getStaticVariables()) { $ret['Uses'] = $val; } if (method_exists($reflection, 'getClousureThis') && ($val = $reflection->getClosureThis())) { $ret['Uses']['$this'] = $val; } if ($val = $reflection->getFileName()) { $this->value = Kint::shortenPath($val) . ':' . $reflection->getStartLine(); } return $ret; }
protected function _parse(&$variable) { if (!is_object($variable) || !$variable instanceof SplFileInfo) { return false; } $this->type = 'object'; $this->subtype = 'SplFileInfo'; $this->value = Kint::shortenPath($variable->getRealPath()); }
public static function decorateTrace($traceData) { $output = '<dl class="kint-trace">'; foreach ($traceData as $i => $step) { $class = 'kint-parent'; if (Kint::$expandedByDefault) { $class .= ' kint-show'; } $output .= '<dt class="' . $class . '">' . '<b>' . ($i + 1) . '</b> ' . '<nav></nav>' . '<var>'; if (isset($step['file'])) { $output .= Kint::shortenPath($step['file'], $step['line']); } else { $output .= 'PHP internal call'; } $output .= '</var>'; $output .= $step['function']; if (isset($step['args'])) { $output .= '(' . implode(', ', array_keys($step['args'])) . ')'; } $output .= '</dt><dd>'; $firstTab = ' class="kint-active-tab"'; $output .= '<ul class="kint-tabs">'; if (!empty($step['source'])) { $output .= "<li{$firstTab}>Source</li>"; $firstTab = ''; } if (!empty($step['args'])) { $output .= "<li{$firstTab}>Arguments</li>"; $firstTab = ''; } if (!empty($step['object'])) { kintParser::reset(); $calleeDump = kintParser::factory($step['object']); $output .= "<li{$firstTab}>Callee object [{$calleeDump->subtype}]</li>"; } $output .= '</ul><ul>'; if (!empty($step['source'])) { $output .= "<li><pre class=\"kint-source\">{$step['source']}</pre></li>"; } if (!empty($step['args'])) { $output .= "<li>"; foreach ($step['args'] as $k => $arg) { kintParser::reset(); $output .= self::decorate(kintParser::factory($arg, $k)); } $output .= "</li>"; } if (!empty($step['object'])) { $output .= "<li>" . self::decorate($calleeDump) . "</li>"; } $output .= '</ul></dd>'; } $output .= '</dl>'; return $output; }
public function render($o) { $children = $this->renderer->renderChildren($o); if (!$o instanceof Kint_Object_Closure) { $header = Kint_Renderer_Rich::renderHeader($o); } else { $header = ''; if (($s = $o->getModifiers()) !== null) { $header .= '<var>' . $s . '</var> '; } if (($s = $o->getName()) !== null) { $header .= '<dfn>' . Kint_Object_Blob::escape($s . '(' . $o->getParams() . ')') . '</dfn> '; } $header .= '<var>Closure</var>'; $header .= Kint_Object_Blob::escape(Kint::shortenPath($o->filename)) . ':' . (int) $o->startline; } $header = Kint_Renderer_Rich::renderHeaderWrapper($o, (bool) strlen($children), $header); return '<dl>' . $header . $children . '</dl>'; }
public function render($r) { if (!$r instanceof Kint_Object_Representation_Docstring) { return false; } $docstring = array(); foreach (explode("\n", $r->contents) as $line) { $docstring[] = trim($line); } $docstring = implode("\n", $docstring); $location = ''; if ($r->file && $r->line) { if (strlen($docstring)) { $location = "\n\n"; } $location .= '<small>Defined in ' . Kint_Object_Blob::escape(Kint::shortenPath($r->file)) . ':' . (int) $r->line . '</small>'; } if (strlen($docstring) === 0 && strlen($location) === 0) { return ''; } return '<pre>' . Kint_Object_Blob::escape($docstring) . $location . '</pre>'; }
public function render($o) { $children = $this->renderer->renderChildren($o); if (!$o instanceof Kint_Object_TraceFrame) { $header = Kint_Renderer_Rich::renderHeader($o); } else { if (!empty($o->trace['file']) && !empty($o->trace['line'])) { $header = '<var>' . Kint_Object_Blob::escape(Kint::shortenPath($o->trace['file'])) . ':' . (int) $o->trace['line'] . '</var> '; } else { $header = '<var>PHP internal call</var> '; } if ($o->trace['class']) { $header .= Kint_Object_Blob::escape($o->trace['class'] . $o->trace['type']); } if (is_string($o->trace['function'])) { $function = $o->trace['function'] . '()'; } else { $function = $o->trace['function']->getName() . '(' . $o->trace['function']->getParams() . ')'; } $header .= '<dfn>' . Kint_Object_Blob::escape($function) . '</dfn>'; } $header = Kint_Renderer_Rich::renderHeaderWrapper($o, (bool) strlen($children), $header); return '<dl>' . $header . $children . '</dl>'; }
private static function _parse_resource(&$variable, kintVariableData $variableData) { $variableData->type = 'resource'; $variableData->subtype = get_resource_type($variable); if ($variableData->subtype === 'stream' && ($meta = stream_get_meta_data($variable))) { if (isset($meta['uri'])) { $file = $meta['uri']; if (function_exists('stream_is_local')) { // Only exists on PHP >= 5.2.4 if (stream_is_local($file)) { $file = Kint::shortenPath($file); } } $variableData->value = $file; } } }
protected function _parse(&$variable) { if (!is_object($variable)) { return false; } $className = get_class($variable); // Assuming class definition will not change inside one request if (!isset(self::$cache[$className])) { $reflection = new \ReflectionClass($variable); $public = $private = $protected = array(); // Class methods foreach ($reflection->getMethods() as $method) { $params = array(); // Access type $access = implode(' ', \Reflection::getModifierNames($method->getModifiers())); // Method parameters foreach ($method->getParameters() as $param) { $paramString = ''; if ($param->isArray()) { $paramString .= 'array '; } else { try { if ($paramClassName = $param->getClass()) { $paramString .= $paramClassName->name . ' '; } } catch (ReflectionException $e) { preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches); $paramClassName = isset($matches[1]) ? $matches[1] : ''; $paramString .= ' UNDEFINED CLASS (' . $paramClassName . ') '; } } $paramString .= ($param->isPassedByReference() ? '&' : '') . '$' . $param->getName(); if ($param->isDefaultValueAvailable()) { if (is_array($param->getDefaultValue())) { $arrayValues = array(); foreach ($param->getDefaultValue() as $key => $value) { $arrayValues[] = $key . ' => ' . $value; } $defaultValue = 'array(' . implode(', ', $arrayValues) . ')'; } elseif ($param->getDefaultValue() === null) { $defaultValue = 'NULL'; } elseif ($param->getDefaultValue() === false) { $defaultValue = 'false'; } elseif ($param->getDefaultValue() === true) { $defaultValue = 'true'; } elseif ($param->getDefaultValue() === '') { $defaultValue = '""'; } else { $defaultValue = $param->getDefaultValue(); } $paramString .= ' = ' . $defaultValue; } $params[] = $paramString; } $output = new \kintVariableData(); // Simple DocBlock parser, look for @return if ($docBlock = $method->getDocComment()) { $matches = array(); if (preg_match_all('/@(\\w+)\\s+(.*)\\r?\\n/m', $docBlock, $matches)) { $lines = array_combine($matches[1], $matches[2]); if (isset($lines['return'])) { $output->operator = '->'; # since we're outputting code, assumption that the string is utf8 is most likely correct # and saves resources $output->type = self::_escape($lines['return'], 'UTF-8'); } } } $output->name = ($method->returnsReference() ? '&' : '') . $method->getName() . '(' . implode(', ', $params) . ')'; $output->access = $access; if (is_string($docBlock)) { $lines = array(); foreach (explode("\n", $docBlock) as $line) { $line = trim($line); if (in_array($line, array('/**', '/*', '*/'))) { continue; } elseif (strpos($line, '*') === 0) { $line = substr($line, 1); } $lines[] = self::_escape(trim($line), 'UTF-8'); } $output->extendedValue = implode("\n", $lines) . "\n\n"; } $declaringClass = $method->getDeclaringClass(); $declaringClassName = $declaringClass->getName(); if ($declaringClassName !== $className) { $output->extendedValue .= "<small>Inherited from <i>{$declaringClassName}</i></small>\n"; } $fileName = \Kint::shortenPath($method->getFileName(), $method->getStartLine()); if ($fileName) { $output->extendedValue .= "<small>Defined in {$fileName}</small>"; } $sortName = $access . $method->getName(); if ($method->isPrivate()) { $private[$sortName] = $output; } elseif ($method->isProtected()) { $protected[$sortName] = $output; } else { $public[$sortName] = $output; } } if (!$private && !$protected && !$public) { self::$cache[$className] = false; } ksort($public); ksort($protected); ksort($private); self::$cache[$className] = $public + $protected + $private; } $this->value = self::$cache[$className]; $this->type = 'Available methods'; $this->size = count(self::$cache[$className]); }
private static function _buildCalleeString($callee) { $url = Kint::getIdeLink($callee['file'], $callee['line']); $shortenedName = Kint::shortenPath($callee['file']) . ':' . $callee['line']; if (Kint::enabled() === Kint::MODE_PLAIN) { if (strpos($url, 'http://') === 0) { $calleeInfo = "<a href=\"#\"onclick=\"" . "X=new XMLHttpRequest;" . "X.open('GET','{$url}');" . "X.send();" . "return!1\">{$shortenedName}</a>"; } else { $calleeInfo = "<a href=\"{$url}\">{$shortenedName}</a>"; } } else { $calleeInfo = $shortenedName; } return $calleeInfo; }
private static function ideLink($file, $line) { $shortenedPath = Kint_Object_Blob::escape(Kint::shortenPath($file)); if (!Kint::$file_link_format) { return $shortenedPath . ':' . $line; } $ideLink = Kint::getIdeLink($file, $line); $class = strpos($ideLink, 'http://') === 0 ? 'class="kint-ide-link" ' : ''; return "<a {$class}href=\"{$ideLink}\">{$shortenedPath}:{$line}</a>"; }
private function parseResource(&$var, Kint_Object $o) { $resource = $o->transplant(new Kint_Object_Resource()); $resource->resource_type = get_resource_type($var); if ($resource->resource_type === 'stream' && ($meta = stream_get_meta_data($var))) { if (isset($meta['uri'])) { $file = $meta['uri']; if (stream_is_local($file)) { $file = Kint::shortenPath($file); } $rep = new Kint_Object_Representation('Stream'); $rep->contents = $file; $resource->addRepresentation($rep); } } return $resource; }