BetterReflection\Reflection\ReflectionClass::__toString PHP 메소드

__toString() 공개 메소드

Get a string representation of this reflection
또한 보기: https://github.com/Roave/BetterReflection/issues/94
public __toString ( ) : string
리턴 string
    public function __toString()
    {
        $isObject = $this instanceof ReflectionObject;
        $format = "%s [ <user> class %s%s%s ] {\n";
        $format .= "  @@ %s %d-%d\n\n";
        $format .= "  - Constants [%d] {%s\n  }\n\n";
        $format .= "  - Static properties [%d] {%s\n  }\n\n";
        $format .= "  - Static methods [%d] {%s\n  }\n\n";
        $format .= "  - Properties [%d] {%s\n  }\n\n";
        $format .= $isObject ? "  - Dynamic properties [%d] {%s\n  }\n\n" : '%s%s';
        $format .= "  - Methods [%d] {%s\n  }\n";
        $format .= "}\n";
        $staticProperties = array_filter($this->getProperties(), function (ReflectionProperty $property) {
            return $property->isStatic();
        });
        $staticMethods = array_filter($this->getMethods(), function (ReflectionMethod $method) {
            return $method->isStatic();
        });
        $defaultProperties = array_filter($this->getProperties(), function (ReflectionProperty $property) {
            return !$property->isStatic() && $property->isDefault();
        });
        $dynamicProperties = array_filter($this->getProperties(), function (ReflectionProperty $property) {
            return !$property->isStatic() && !$property->isDefault();
        });
        $methods = array_filter($this->getMethods(), function (ReflectionMethod $method) {
            return !$method->isStatic();
        });
        $buildString = function (array $items, $indentLevel = 4) {
            if (!count($items)) {
                return '';
            }
            $indent = "\n" . str_repeat(' ', $indentLevel);
            return $indent . implode($indent, explode("\n", implode("\n", $items)));
        };
        $buildConstants = function (array $items, $indentLevel = 4) {
            $str = '';
            foreach ($items as $name => $value) {
                $str .= "\n" . str_repeat(' ', $indentLevel);
                $str .= sprintf('Constant [ %s %s ] { %s }', gettype($value), $name, $value);
            }
            return $str;
        };
        $interfaceNames = $this->getInterfaceNames();
        $str = sprintf($format, $isObject ? 'Object of class' : 'Class', $this->getName(), null !== $this->getParentClass() ? ' extends ' . $this->getParentClass()->getName() : '', count($interfaceNames) ? ' implements ' . implode(', ', $interfaceNames) : '', $this->getFileName(), $this->getStartLine(), $this->getEndLine(), count($this->getConstants()), $buildConstants($this->getConstants()), count($staticProperties), $buildString($staticProperties), count($staticMethods), $buildString($staticMethods), count($defaultProperties), $buildString($defaultProperties), $isObject ? count($dynamicProperties) : '', $isObject ? $buildString($dynamicProperties) : '', count($methods), $buildString($methods));
        return $str;
    }

Usage Example

예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     return $this->betterReflectionClass->__toString();
 }