1<?php 2 3 4namespace GO\Base\Util; 5 6 7class ReflectionClass extends \ReflectionClass { 8 9 10 private $_overriddenMethods; 11 /** 12 * Determine which properties are of the childs class. 13 * Return them as an array. 14 * 15 * @param int $filter The optional filter, for filtering desired property 16 * types. It's configured using the ReflectionProperty constants, and defaults 17 * to all property types. 18 * 19 * @return array 20 */ 21 public function getParentPropertiesDiff($filter=null){ 22 $parent = $this->getParentClass(); 23 return array_diff($this->getProperties($filter),$parent->getProperties($filter)); 24 } 25 26 /** 27 * Determine which methods are of the childs class. 28 * Return them as an array. 29 * 30 * @return array 31 */ 32 public function getParentMethodsDiff(){ 33 $parent = $this->getParentClass(); 34 return array_diff($this->getMethods(),$parent->getMethods()); 35 } 36 37 /** 38 * Returns all methods that override a parent method. 39 * 40 * @return array 41 */ 42 public function getOverriddenMethods() { 43 if(!isset($this->_overriddenMethods)){ 44 $this->_overriddenMethods = array(); 45 46 if (!$parentClass = $this->getParentClass()) 47 return $this->_overriddenMethods; 48 49 //find all public and protected methods in ParentClass 50 $parentMethods = $parentClass->getMethods( 51 \ReflectionMethod::IS_PUBLIC ^ \ReflectionMethod::IS_PROTECTED 52 ); 53 54 //find all parentmethods that were redeclared in ChildClass 55 foreach ($parentMethods as $parentMethod) { 56 $declaringClass = $this->getMethod($parentMethod->getName()) 57 ->getDeclaringClass() 58 ->getName(); 59 60 if ($declaringClass === $this->getName()) { 61 $this->_overriddenMethods[]=$parentMethod->getName(); // print the method name 62 } 63 } 64 } 65 66 return $this->_overriddenMethods; 67 } 68 69 /** 70 * Check if a method is overriding a parent method 71 * 72 * @param StringHelper $method 73 * @return boolean 74 */ 75 public function methodIsOverridden($method){ 76 $overrides = $this->getOverriddenMethods(); 77 return in_array($method, $overrides); 78 } 79 80} 81