* */ class libraries_objectparser { /** * The data model object that will be processed * * @var object * @access protected */ protected $obj; /** * A list of methods that should be skipped when processing an object * * @var array * @access protected */ protected $skipList; /** * Constructor object for the class * * @param ems_framework_registry $param * @access public * @return void */ public function __construct($obj) { $this->obj = $obj; // this list are group of methods that shouldn't be processed as they don't return meaningful data or could cause the processing routine to get caught in an infinite loop $this->skipList = array("__construct","setDataSouce","getData","getDataByEmail","getDataByCreatedID","save","delete","getCD","getAddressByFunc","getPhoneByFunc","getUser","getSecurity","getCreated","getEdited","getParent","getSearchName","getParseMethods"); } /** * This method will return an array of values that are processed by this class. It uses lazy load so that if it's called a second time, the processed list is returned instead of running the expensive operation a second time. * * @param none * @access public * @return array */ public function getMethodValues() { $valueList = array(); $processedObjects = array(); // this is a list of objects that we've already processed. That way, the processing method doesn't process an object it's already done. try { $this->processMethodValues($this->obj,$valueList,$processedObjects); } catch (exception $e) {} return $valueList; } /** * This is the meat of the objectparser, it looks at the currently passed object and uses reflection to determine it's methods. It then calls each in turn (if they aren't in the skip list). If an object is returned, then this method is recursed with that object so you can index a whole data structure in this way. * * @param object $obj, referenced array $valueList, referenced array of processed objects * @access public * @return array */ protected function processMethodValues($obj,&$valueList,&$processedObjects) { // exit this run of the method if the current $obj is in $processedObjects foreach ($processedObjects as $tempObj) { if ($obj == $tempObj) return; } $processedObjects[] = $obj; $reflection = new ReflectionClass(get_class($obj)); $methods = $reflection->getMethods(); // this will process any methods that a specific data model defines for itself try { $parseMethodsReflection = new ReflectionMethod(get_class($obj),"getParseMethods"); $specifiedMethods = $obj->getParseMethods(); // getParseMethods is an override method that a data model can define if it wants to control what calls get indexed if (count($specifiedMethods) > 0) { $tempList = array(); foreach ($methods as $methodReflection) { if (in_array($methodReflection->getName(),$specifiedMethods)) { $tempList[] = $methodReflection; } } $methods = $tempList; } } catch (exception $e) {} // this processes all the methods found in the reflection foreach ($methods as $methodReflection) { $methodName = $methodReflection->getName(); // make sure it's a public method (meaning it's part of that class's API) and it's not in the skip list, and that it's a getter method, meaning that it returns some kind of data if ($methodReflection->isPublic() && !in_array($methodName,$this->skipList) && strpos($methodName,"get") === 0) { try { // we run the method call through value processor $vp = new libraries_valueprocessor(null,$obj,$methodName,"func"); $val = $vp->getValue(); // we handle email in a particular fashion because of how the indexer works if (strpos(strtolower($methodName),"email") !== false && strpos($val,"@") !== false) { $email = $val; $part_1 = substr($email, 0, strpos($email, "@")); $part_2 = substr($email, (strpos($email, "@") + 1), (strrpos($email, ".") - strpos($email, "@") - 1)); if (is_string($part_1) || is_numeric($part_1)) $valueList[] = $part_1; if (is_string($part_2) || is_numeric($part_2)) $valueList[] = $part_2; } // if we have a number of string, we add it to the valuelist if (is_string($val) || is_numeric($val)) $valueList[] = $val; // if the returned value is a collection of child elements, we process those too if (is_object($val) && $val instanceof libraries_collection) { $it = $val->createIterator(); while ($it->hasNext()) { $childObj = $it->next(); $this->processMethodValues($childObj,$valueList,$processedObjects); // recursive call } } } catch (exception $e) {} } // if method public and other checks } // foreach of methods } // end of method } ?>