| 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\Renderer; |
| 27: | |
| 28: | use Kint\Object\BasicObject; |
| 29: | use Kint\Object\InstanceObject; |
| 30: | |
| 31: | abstract class Renderer |
| 32: | { |
| 33: | const SORT_NONE = 0; |
| 34: | const SORT_VISIBILITY = 1; |
| 35: | const SORT_FULL = 2; |
| 36: | |
| 37: | protected $call_info = array(); |
| 38: | protected $statics = array(); |
| 39: | protected $show_trace = true; |
| 40: | |
| 41: | abstract public function render(BasicObject $o); |
| 42: | |
| 43: | abstract public function renderNothing(); |
| 44: | |
| 45: | public function setCallInfo(array $info) |
| 46: | { |
| 47: | if (!isset($info['params'])) { |
| 48: | $info['params'] = null; |
| 49: | } |
| 50: | |
| 51: | if (!isset($info['modifiers']) || !\is_array($info['modifiers'])) { |
| 52: | $info['modifiers'] = array(); |
| 53: | } |
| 54: | |
| 55: | if (!isset($info['callee'])) { |
| 56: | $info['callee'] = null; |
| 57: | } |
| 58: | |
| 59: | if (!isset($info['caller'])) { |
| 60: | $info['caller'] = null; |
| 61: | } |
| 62: | |
| 63: | if (!isset($info['trace']) || !\is_array($info['trace'])) { |
| 64: | $info['trace'] = array(); |
| 65: | } |
| 66: | |
| 67: | $this->call_info = array( |
| 68: | 'params' => $info['params'], |
| 69: | 'modifiers' => $info['modifiers'], |
| 70: | 'callee' => $info['callee'], |
| 71: | 'caller' => $info['caller'], |
| 72: | 'trace' => $info['trace'], |
| 73: | ); |
| 74: | } |
| 75: | |
| 76: | public function getCallInfo() |
| 77: | { |
| 78: | return $this->call_info; |
| 79: | } |
| 80: | |
| 81: | public function setStatics(array $statics) |
| 82: | { |
| 83: | $this->statics = $statics; |
| 84: | $this->setShowTrace(!empty($statics['display_called_from'])); |
| 85: | } |
| 86: | |
| 87: | public function getStatics() |
| 88: | { |
| 89: | return $this->statics; |
| 90: | } |
| 91: | |
| 92: | public function setShowTrace($show_trace) |
| 93: | { |
| 94: | $this->show_trace = $show_trace; |
| 95: | } |
| 96: | |
| 97: | public function getShowTrace() |
| 98: | { |
| 99: | return $this->show_trace; |
| 100: | } |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | public function matchPlugins(array $plugins, array $hints) |
| 111: | { |
| 112: | $out = array(); |
| 113: | |
| 114: | foreach ($hints as $key) { |
| 115: | if (isset($plugins[$key])) { |
| 116: | $out[$key] = $plugins[$key]; |
| 117: | } |
| 118: | } |
| 119: | |
| 120: | return $out; |
| 121: | } |
| 122: | |
| 123: | public function filterParserPlugins(array $plugins) |
| 124: | { |
| 125: | return $plugins; |
| 126: | } |
| 127: | |
| 128: | public function preRender() |
| 129: | { |
| 130: | return ''; |
| 131: | } |
| 132: | |
| 133: | public function postRender() |
| 134: | { |
| 135: | return ''; |
| 136: | } |
| 137: | |
| 138: | public static function sortPropertiesFull(BasicObject $a, BasicObject $b) |
| 139: | { |
| 140: | $sort = BasicObject::sortByAccess($a, $b); |
| 141: | if ($sort) { |
| 142: | return $sort; |
| 143: | } |
| 144: | |
| 145: | $sort = BasicObject::sortByName($a, $b); |
| 146: | if ($sort) { |
| 147: | return $sort; |
| 148: | } |
| 149: | |
| 150: | return InstanceObject::sortByHierarchy($a->owner_class, $b->owner_class); |
| 151: | } |
| 152: | |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | |
| 158: | |
| 159: | |
| 160: | |
| 161: | public static function sortProperties(array $contents, $sort) |
| 162: | { |
| 163: | switch ($sort) { |
| 164: | case self::SORT_VISIBILITY: |
| 165: | |
| 166: | $containers = array( |
| 167: | BasicObject::ACCESS_PUBLIC => array(), |
| 168: | BasicObject::ACCESS_PROTECTED => array(), |
| 169: | BasicObject::ACCESS_PRIVATE => array(), |
| 170: | BasicObject::ACCESS_NONE => array(), |
| 171: | ); |
| 172: | |
| 173: | foreach ($contents as $item) { |
| 174: | $containers[$item->access][] = $item; |
| 175: | } |
| 176: | |
| 177: | return \call_user_func_array('array_merge', $containers); |
| 178: | case self::SORT_FULL: |
| 179: | \usort($contents, array('Kint\\Renderer\\Renderer', 'sortPropertiesFull')); |
| 180: | |
| 181: | default: |
| 182: | return $contents; |
| 183: | } |
| 184: | } |
| 185: | } |
| 186: | |