| 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\Object; |
| 27: | |
| 28: | use Kint\Utils; |
| 29: | use ReflectionException; |
| 30: | use ReflectionParameter; |
| 31: | |
| 32: | class ParameterObject extends BasicObject |
| 33: | { |
| 34: | public $type_hint; |
| 35: | public $default; |
| 36: | public $position; |
| 37: | public $hints = array('parameter'); |
| 38: | |
| 39: | public function __construct(ReflectionParameter $param) |
| 40: | { |
| 41: | parent::__construct(); |
| 42: | |
| 43: | if (KINT_PHP70) { |
| 44: | if ($type = $param->getType()) { |
| 45: | $this->type_hint = Utils::getTypeString($type); |
| 46: | } |
| 47: | } else { |
| 48: | if ($param->isArray()) { |
| 49: | $this->type_hint = 'array'; |
| 50: | } else { |
| 51: | try { |
| 52: | if ($this->type_hint = $param->getClass()) { |
| 53: | $this->type_hint = $this->type_hint->name; |
| 54: | } |
| 55: | } catch (ReflectionException $e) { |
| 56: | \preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches); |
| 57: | $this->type_hint = isset($matches[1]) ? $matches[1] : ''; |
| 58: | } |
| 59: | } |
| 60: | } |
| 61: | |
| 62: | $this->reference = $param->isPassedByReference(); |
| 63: | $this->name = $param->getName(); |
| 64: | $this->position = $param->getPosition(); |
| 65: | |
| 66: | if ($param->isDefaultValueAvailable()) { |
| 67: | |
| 68: | $default = $param->getDefaultValue(); |
| 69: | switch (\gettype($default)) { |
| 70: | case 'NULL': |
| 71: | $this->default = 'null'; |
| 72: | break; |
| 73: | case 'boolean': |
| 74: | $this->default = $default ? 'true' : 'false'; |
| 75: | break; |
| 76: | case 'array': |
| 77: | $this->default = \count($default) ? 'array(...)' : 'array()'; |
| 78: | break; |
| 79: | default: |
| 80: | $this->default = \var_export($default, true); |
| 81: | break; |
| 82: | } |
| 83: | } |
| 84: | } |
| 85: | |
| 86: | public function getType() |
| 87: | { |
| 88: | return $this->type_hint; |
| 89: | } |
| 90: | |
| 91: | public function getName() |
| 92: | { |
| 93: | return '$'.$this->name; |
| 94: | } |
| 95: | |
| 96: | public function getDefault() |
| 97: | { |
| 98: | return $this->default; |
| 99: | } |
| 100: | } |
| 101: | |