| 1: | <?php | 
| 2: | |
| 3: | /* | 
| 4: | * The MIT License (MIT) | 
| 5: | * | 
| 6: | * Copyright (c) 2013 Jonathan Vollebregt (jnvsor@gmail.com), Rokas Šleinius (raveren@gmail.com) | 
| 7: | * | 
| 8: | * Permission is hereby granted, free of charge, to any person obtaining a copy of | 
| 9: | * this software and associated documentation files (the "Software"), to deal in | 
| 10: | * the Software without restriction, including without limitation the rights to | 
| 11: | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | 
| 12: | * the Software, and to permit persons to whom the Software is furnished to do so, | 
| 13: | * subject to the following conditions: | 
| 14: | * | 
| 15: | * The above copyright notice and this permission notice shall be included in all | 
| 16: | * copies or substantial portions of the Software. | 
| 17: | * | 
| 18: | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| 19: | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | 
| 20: | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | 
| 21: | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | 
| 22: | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 
| 23: | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
| 24: | */ | 
| 25: | |
| 26: | namespace Kint\Object; | 
| 27: | |
| 28: | class InstanceObject extends BasicObject | 
| 29: | { | 
| 30: | public $type = 'object'; | 
| 31: | public $classname; | 
| 32: | public $hash; | 
| 33: | public $filename; | 
| 34: | public $startline; | 
| 35: | public $hints = array('object'); | 
| 36: | |
| 37: | public function getType() | 
| 38: | { | 
| 39: | return $this->classname; | 
| 40: | } | 
| 41: | |
| 42: | public function transplant(BasicObject $old) | 
| 43: | { | 
| 44: | parent::transplant($old); | 
| 45: | |
| 46: | if ($old instanceof self) { | 
| 47: | $this->classname = $old->classname; | 
| 48: | $this->hash = $old->hash; | 
| 49: | $this->filename = $old->filename; | 
| 50: | $this->startline = $old->startline; | 
| 51: | } | 
| 52: | } | 
| 53: | |
| 54: | public static function sortByHierarchy($a, $b) | 
| 55: | { | 
| 56: | if (\is_string($a) && \is_string($b)) { | 
| 57: | $aclass = $a; | 
| 58: | $bclass = $b; | 
| 59: | } elseif (!($a instanceof BasicObject) || !($b instanceof BasicObject)) { | 
| 60: | return 0; | 
| 61: | } elseif ($a instanceof self && $b instanceof self) { | 
| 62: | $aclass = $a->classname; | 
| 63: | $bclass = $b->classname; | 
| 64: | } else { | 
| 65: | return 0; | 
| 66: | } | 
| 67: | |
| 68: | if (\is_subclass_of($aclass, $bclass)) { | 
| 69: | return -1; | 
| 70: | } | 
| 71: | |
| 72: | if (\is_subclass_of($bclass, $aclass)) { | 
| 73: | return 1; | 
| 74: | } | 
| 75: | |
| 76: | return 0; | 
| 77: | } | 
| 78: | } | 
| 79: |