/** * Static factory to parse the @objectList annotation of a single property * @param $objObject * @param $strProperty * * @return class_orm_assignment_config * @throws class_orm_exception */ public static function getConfigForProperty($objObject, $strProperty) { $objReflection = new class_reflection($objObject); $arrPropertyParams = $objReflection->getAnnotationValueForProperty($strProperty, class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS()); $strTable = $objReflection->getAnnotationValueForProperty($strProperty, class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::VALUES()); $arrTypeFilter = isset($arrPropertyParams["type"]) ? $arrPropertyParams["type"] : null; if (!isset($arrPropertyParams["source"]) || !isset($arrPropertyParams["target"]) || empty($strTable)) { throw new class_orm_exception("@objectList annoation for " . $strProperty . "@" . get_class($objObject) . " is malformed", class_orm_exception::$level_FATALERROR); } return new class_orm_assignment_config($strTable, $arrPropertyParams["source"], $arrPropertyParams["target"], $arrTypeFilter); }
/** * Searches a given annotation for a specified property. If given, the value is returned, otherwise (when not found) null is returned. * * @param string $strProperty * @param string $strAnnotation * @param class_reflection_enum $objEnum - whether to return annotation values or parameters, default is values * * @return null|string */ public function getAnnotationValueForProperty($strProperty, $strAnnotation, class_reflection_enum $objEnum = null) { if ($objEnum == null) { $objEnum = class_reflection_enum::VALUES(); } $arrProperties = $this->objReflectionClass->getProperties(); foreach ($arrProperties as $objOneProperty) { if ($objOneProperty->getName() == $strProperty) { $strFirstAnnotation = $this->searchFirstAnnotationInDoc($objOneProperty->getDocComment(), $strAnnotation); if ($objEnum->equals(class_reflection_enum::VALUES())) { $strFirstAnnotation = $strFirstAnnotation["values"][0]; } else { if ($objEnum->equals(class_reflection_enum::PARAMS())) { $strFirstAnnotation = $strFirstAnnotation["params"][0]; } } if ($strFirstAnnotation !== false) { return $strFirstAnnotation; } } } //check if there's a base-class -> inheritance $objBaseClass = $this->objReflectionClass->getParentClass(); if ($objBaseClass !== false) { $objBaseAnnotations = new class_reflection($objBaseClass->getName()); return $objBaseAnnotations->getAnnotationValueForProperty($strProperty, $strAnnotation, $objEnum); } return null; }