class Kint_Parsers_ClassMethods

Hierarchy

Expanded class hierarchy of Kint_Parsers_ClassMethods

File

kint/kint/parsers/custom/classmethods.php, line 3

View source
class Kint_Parsers_ClassMethods extends kintParser {
    private static $cache = array();
    protected function _parse(&$variable) {
        if (!KINT_PHP53 || !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();
                $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;
        }
        if (count(self::$cache[$className]) === 0) {
            return false;
        }
        $this->value = self::$cache[$className];
        $this->type = 'Available methods';
        $this->size = count(self::$cache[$className]);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
kintParser::$_customDataTypes private static property
kintParser::$_dealingWithGlobals private static property
kintParser::$_level private static property
kintParser::$_marker private static property
kintParser::$_objectParsers private static property
kintParser::$_objects private static property
kintParser::$_placeFullStringInValue private static property
kintParser::$_skipAlternatives private static property
kintParser::escape public static function
kintParser::factory final public static function * the only public entry point to return a parsed representation of a variable
*
* @static
*
*
kintParser::reset public static function
kintParser::_checkDepth private static function
kintParser::_decorateCell private static function
kintParser::_init private static function
kintParser::_isArrayTabular private static function
kintParser::_parse_array private static function
kintParser::_parse_boolean private static function
kintParser::_parse_double private static function
kintParser::_parse_integer private static function
kintParser::_parse_null private static function
kintParser::_parse_object private static function
kintParser::_parse_resource private static function
kintParser::_parse_string private static function
kintParser::_parse_unknown private static function
kintVariableData::$access public property @var string
kintVariableData::$extendedValue public property * * the array is a separate possible representation of the dumped var
kintVariableData::$name public property @var string
kintVariableData::$operator public property @var string
kintVariableData::$size public property @var int
kintVariableData::$type public property @var string
kintVariableData::$value public property @var string inline value
kintVariableData::$_alternatives public property @var kintVariableData[] array of alternative representations for same variable, don't use in custom parsers
kintVariableData::$_supportedCharsets private static property
kintVariableData::_detectEncoding protected static function
kintVariableData::_isSequential protected static function * returns whether the array:
* 1) is numeric and
* 2) in sequence starting from zero
*
*
kintVariableData::_strlen protected static function
kintVariableData::_substr protected static function
Kint_Parsers_ClassMethods::$cache private static property
Kint_Parsers_ClassMethods::_parse protected function * main and usually single method a custom parser must implement
*
*
Overrides kintParser::_parse