| 1: | <?php | 
| 2: |  | 
| 3: |  | 
| 4: |  | 
| 5: |  | 
| 6: |  | 
| 7: |  | 
| 8: |  | 
| 9: |  | 
| 10: |  | 
| 11: |  | 
| 12: |  | 
| 13: |  | 
| 14: |  | 
| 15: |  | 
| 16: |  | 
| 17: |  | 
| 18: |  | 
| 19: |  | 
| 20: |  | 
| 21: |  | 
| 22: |  | 
| 23: |  | 
| 24: |  | 
| 25: |  | 
| 26: | namespace Kint\Parser; | 
| 27: |  | 
| 28: | use Kint\Object\BasicObject; | 
| 29: | use Kint\Object\InstanceObject; | 
| 30: | use Kint\Object\Representation\Representation; | 
| 31: | use ReflectionClass; | 
| 32: | use ReflectionProperty; | 
| 33: |  | 
| 34: | class ClassStaticsPlugin extends Plugin | 
| 35: | { | 
| 36: | private static $cache = array(); | 
| 37: |  | 
| 38: | public function getTypes() | 
| 39: | { | 
| 40: | return array('object'); | 
| 41: | } | 
| 42: |  | 
| 43: | public function getTriggers() | 
| 44: | { | 
| 45: | return Parser::TRIGGER_SUCCESS; | 
| 46: | } | 
| 47: |  | 
| 48: | public function parse(&$var, BasicObject &$o, $trigger) | 
| 49: | { | 
| 50: | $class = \get_class($var); | 
| 51: | $reflection = new ReflectionClass($class); | 
| 52: |  | 
| 53: |  | 
| 54: |  | 
| 55: | if (!isset(self::$cache[$class])) { | 
| 56: | $consts = array(); | 
| 57: |  | 
| 58: | foreach ($reflection->getConstants() as $name => $val) { | 
| 59: | $const = BasicObject::blank($name, '\\'.$class.'::'.$name); | 
| 60: | $const->const = true; | 
| 61: | $const->depth = $o->depth + 1; | 
| 62: | $const->owner_class = $class; | 
| 63: | $const->operator = BasicObject::OPERATOR_STATIC; | 
| 64: | $const = $this->parser->parse($val, $const); | 
| 65: |  | 
| 66: | $consts[] = $const; | 
| 67: | } | 
| 68: |  | 
| 69: | self::$cache[$class] = $consts; | 
| 70: | } | 
| 71: |  | 
| 72: | $statics = new Representation('Static class properties', 'statics'); | 
| 73: | $statics->contents = self::$cache[$class]; | 
| 74: |  | 
| 75: | foreach ($reflection->getProperties(ReflectionProperty::IS_STATIC) as $static) { | 
| 76: | $prop = new BasicObject(); | 
| 77: | $prop->name = '$'.$static->getName(); | 
| 78: | $prop->depth = $o->depth + 1; | 
| 79: | $prop->static = true; | 
| 80: | $prop->operator = BasicObject::OPERATOR_STATIC; | 
| 81: | $prop->owner_class = $static->getDeclaringClass()->name; | 
| 82: |  | 
| 83: | $prop->access = BasicObject::ACCESS_PUBLIC; | 
| 84: | if ($static->isProtected()) { | 
| 85: | $prop->access = BasicObject::ACCESS_PROTECTED; | 
| 86: | } elseif ($static->isPrivate()) { | 
| 87: | $prop->access = BasicObject::ACCESS_PRIVATE; | 
| 88: | } | 
| 89: |  | 
| 90: | if ($this->parser->childHasPath($o, $prop)) { | 
| 91: | $prop->access_path = '\\'.$prop->owner_class.'::'.$prop->name; | 
| 92: | } | 
| 93: |  | 
| 94: | $static->setAccessible(true); | 
| 95: | $static = $static->getValue(); | 
| 96: | $statics->contents[] = $this->parser->parse($static, $prop); | 
| 97: | } | 
| 98: |  | 
| 99: | if (empty($statics->contents)) { | 
| 100: | return; | 
| 101: | } | 
| 102: |  | 
| 103: | \usort($statics->contents, array('Kint\\Parser\\ClassStaticsPlugin', 'sort')); | 
| 104: |  | 
| 105: | $o->addRepresentation($statics); | 
| 106: | } | 
| 107: |  | 
| 108: | private static function sort(BasicObject $a, BasicObject $b) | 
| 109: | { | 
| 110: | $sort = ((int) $a->const) - ((int) $b->const); | 
| 111: | if ($sort) { | 
| 112: | return $sort; | 
| 113: | } | 
| 114: |  | 
| 115: | $sort = BasicObject::sortByAccess($a, $b); | 
| 116: | if ($sort) { | 
| 117: | return $sort; | 
| 118: | } | 
| 119: |  | 
| 120: | return InstanceObject::sortByHierarchy($a->owner_class, $b->owner_class); | 
| 121: | } | 
| 122: | } | 
| 123: |  |