/**
  * 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);
 }
 /**
  * Overwritten in order to load key-value pairs declared by annotations
  */
 protected function updateValue()
 {
     parent::updateValue();
     if ($this->getObjSourceObject() != null && $this->getStrSourceProperty() != "") {
         $objReflection = new class_reflection($this->getObjSourceObject());
         //try to find the matching source property
         $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_TEMPLATEDIR_ANNOTATION);
         $strSourceProperty = null;
         foreach ($arrProperties as $strPropertyName => $strValue) {
             if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) {
                 $strSourceProperty = $strPropertyName;
             }
         }
         if ($strSourceProperty == null) {
             return;
         }
         $strTemplateDir = $objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_TEMPLATEDIR_ANNOTATION);
         //load templates
         $arrTemplates = class_resourceloader::getInstance()->getTemplatesInFolder($strTemplateDir);
         $arrTemplatesDD = array();
         if (count($arrTemplates) > 0) {
             foreach ($arrTemplates as $strTemplate) {
                 $arrTemplatesDD[$strTemplate] = $strTemplate;
             }
         }
         $this->setArrKeyValues($arrTemplatesDD);
     }
 }
 /**
  * Overwritten in order to load key-value pairs declared by annotations
  */
 protected function updateValue()
 {
     parent::updateValue();
     if ($this->getObjSourceObject() != null && $this->getStrSourceProperty() != "") {
         $objReflection = new class_reflection($this->getObjSourceObject());
         //try to find the matching source property
         $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_DDVALUES_ANNOTATION);
         $strSourceProperty = null;
         foreach ($arrProperties as $strPropertyName => $strValue) {
             if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) {
                 $strSourceProperty = $strPropertyName;
             }
         }
         if ($strSourceProperty == null) {
             return;
         }
         $strDDValues = $objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_DDVALUES_ANNOTATION);
         if ($strDDValues !== null && $strDDValues != "") {
             $arrDDValues = array();
             foreach (explode(",", $strDDValues) as $strOneKeyVal) {
                 $strOneKeyVal = uniSubstr(trim($strOneKeyVal), 1, -1);
                 $arrOneKeyValue = explode("=>", $strOneKeyVal);
                 $strKey = trim($arrOneKeyValue[0]) == "" ? " " : trim($arrOneKeyValue[0]);
                 if (count($arrOneKeyValue) == 2) {
                     $strValue = class_carrier::getInstance()->getObjLang()->getLang(trim($arrOneKeyValue[1]), $this->getObjSourceObject()->getArrModule("modul"));
                     if ($strValue == "!" . trim($arrOneKeyValue[1]) . "!") {
                         $strValue = $arrOneKeyValue[1];
                     }
                     $arrDDValues[$strKey] = $strValue;
                 }
             }
             $this->setArrKeyValues($arrDDValues);
         }
     }
 }
 /**
  * Here comes the magic, generation a where restriction out of the passed property name and the comparator
  *
  * @return string
  * @throws class_orm_exception
  */
 public function getStrWhere()
 {
     $objReflection = new class_reflection($this->getStrTargetClass());
     $strPropertyValue = $objReflection->getAnnotationValueForProperty($this->strPropertyName, class_orm_base::STR_ANNOTATION_TABLECOLUMN);
     if ($strPropertyValue == null) {
         throw new class_orm_exception("Failed to load annotation " . class_orm_base::STR_ANNOTATION_TABLECOLUMN . " for property " . $this->strPropertyName . "@" . $this->getStrTargetClass(), class_exception::$level_ERROR);
     }
     return $this->getInStatement($strPropertyValue);
 }
 /**
  * Here comes the magic, generation a where restriction out of the passed property name and the comparator
  *
  * @return string
  * @throws class_orm_exception
  */
 public function getStrWhere()
 {
     $objReflection = new class_reflection($this->getStrTargetClass());
     $strPropertyValue = $objReflection->getAnnotationValueForProperty($this->strProperty, class_orm_base::STR_ANNOTATION_TABLECOLUMN);
     if ($strPropertyValue == null) {
         throw new class_orm_exception("Failed to load annotation " . class_orm_base::STR_ANNOTATION_TABLECOLUMN . " for property " . $this->strProperty . "@" . $this->getStrTargetClass(), class_exception::$level_ERROR);
     }
     return " AND " . $strPropertyValue . " " . $this->objComparator->getEnumAsSqlString() . " ? ";
 }
 /**
  * Reads the properties marked with templateExport from the current object
  *
  * @return void
  */
 private function readPropertiesFromObject()
 {
     $objReflection = new class_reflection($this->objObject);
     $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_ANNOTATION_TEMPLATEEXPORT);
     foreach (array_keys($arrProperties) as $strOneProperty) {
         $strGetter = $objReflection->getGetter($strOneProperty);
         //get the templatemapper
         $strMapper = $objReflection->getAnnotationValueForProperty($strOneProperty, self::STR_ANNOTATION_TEMPLATEMAPPER);
         if ($strMapper == null) {
             $strMapper = "default";
         }
         $this->addPlaceholder($strOneProperty, call_user_func(array($this->objObject, $strGetter)), $strMapper);
     }
 }
 private function getSourceDir()
 {
     if ($this->getObjSourceObject() != null && $this->getStrSourceProperty() != "") {
         $objReflection = new class_reflection($this->getObjSourceObject());
         //try to find the matching source property
         $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_SOURCEDIR_ANNOTATION);
         $strSourceProperty = null;
         foreach ($arrProperties as $strPropertyName => $strValue) {
             if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) {
                 $strSourceProperty = $strPropertyName;
             }
         }
         if ($strSourceProperty != null) {
             $strDir = $objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_SOURCEDIR_ANNOTATION);
             if ($strDir !== null && $strDir != "") {
                 return $strDir;
             }
         }
     }
     return null;
 }
 /**
  * Returns a textual representation of the formentries' value.
  * May contain html, but should be stripped down to text-only.
  *
  * @return string
  */
 public function getValueAsText()
 {
     //load all matching and possible values based on the prefix
     if ($this->getObjSourceObject() == null || $this->getStrSourceProperty() == "") {
         return $this->getStrValue() . " Error: No target object mapped or missing @fieldValuePrefix annotation!";
     }
     $objReflection = new class_reflection($this->getObjSourceObject());
     //try to find the matching source property
     $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_VALUE_ANNOTATION);
     $strSourceProperty = null;
     foreach ($arrProperties as $strPropertyName => $strValue) {
         if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) {
             $strSourceProperty = $strPropertyName;
         }
     }
     if ($strSourceProperty == null) {
         return $this->getStrValue();
     }
     $strPrefix = trim($objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_VALUE_ANNOTATION));
     if ($this->getStrValue() !== null && $this->getStrValue() !== "") {
         return $this->getObjSourceObject()->getLang($strPrefix . $this->getStrValue());
     }
     return "";
 }
Esempio n. 9
0
 /**
  * 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;
 }
Esempio n. 10
0
 /**
  * @dataProvider additionProvider
  */
 public function testGetAnnotationValueForPropertyParameter($a)
 {
     $objAnnotations = new class_reflection(new C());
     $arrParams = $objAnnotations->getAnnotationValueForProperty("propertyB1", "@propertyTest", class_reflection_enum::PARAMS());
     $this->assertCount(0, $arrParams);
     $arrParams = $objAnnotations->getAnnotationValueForProperty("propertyB1", "@propertyParamTest1", class_reflection_enum::PARAMS());
     $this->assertCount(1, $arrParams);
     $this->assertArrayHasKey("param1", $arrParams);
     $arrParams = $objAnnotations->getAnnotationValueForProperty("propertyB1", "@propertyParamTest2", class_reflection_enum::PARAMS());
     $this->assertCount(0, $arrParams);
     $arrParams = $objAnnotations->getAnnotationValueForProperty("propertyB1", "@propertyParamTest3", class_reflection_enum::PARAMS());
     $this->assertCount(1, $arrParams);
     $this->assertArrayHasKey("param1", $arrParams);
     $arrParams = $objAnnotations->getAnnotationValueForProperty("propertyB1", "@propertyParamTest4", class_reflection_enum::PARAMS());
     $this->assertCount(0, $arrParams);
 }
Esempio n. 11
0
 /**
  * Crreates an object of type '$strClassType'.
  * Only properties which are annotated with @var will be considered
  *
  * @param string $strClassType - the name of the class as a string
  * @param string $strParentId - the parent id of the object to be created
  * @param array $arrExcludeFillProperty - array of poperty names which will not be set
  * @param array $arrPropertyValues - assoziative array which has as key the property name and as value the to be set for the property
  * @param boolean $bitAutofillProperties - if true all properties which have annotation @tablecolumn will be filled with random values
  *
  * @return class_model
  */
 protected function createObject($strClassType, $strParentId, array $arrExcludeFillProperty = array(), array $arrPropertyValues = array(), $bitAutofillProperties = true)
 {
     //get properties with an tablecolumn annotation
     $objObject = new $strClassType();
     $objReflection = new class_reflection($strClassType);
     $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN);
     $arrProperties = array_merge($objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST), $arrProperties);
     //exclude class_root properties
     $objRootReflection = new class_reflection("class_root");
     $arrExcludeFillProperty = array_merge($arrExcludeFillProperty, array_keys($objRootReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN)));
     foreach ($arrProperties as $strPropName => $strValue) {
         //Exclude properties to be set
         if (in_array($strPropName, $arrExcludeFillProperty)) {
             continue;
         }
         //Set properties from array $arrPropertyValues
         if (array_key_exists($strPropName, $arrPropertyValues)) {
             $strSetterMethod = $objReflection->getSetter($strPropName);
             if ($strSetterMethod !== null) {
                 $objValue = $arrPropertyValues[$strPropName];
                 $objObject->{$strSetterMethod}($objValue);
                 continue;
             }
         }
         //check if the property is annotated with @tablecolumn
         if ($bitAutofillProperties) {
             if ($objReflection->hasPropertyAnnotation($strPropName, class_orm_base::STR_ANNOTATION_TABLECOLUMN)) {
                 $strSetterMethod = $objReflection->getSetter($strPropName);
                 if ($strSetterMethod !== null) {
                     //determine the field type
                     $strDataType = $objReflection->getAnnotationValueForProperty($strPropName, "@var");
                     $strFieldType = $objReflection->getAnnotationValueForProperty($strPropName, "@fieldType");
                     $objMethodValue = null;
                     if ($strDataType == "string") {
                         if ($strFieldType == "text" || $strFieldType == "textarea") {
                             $objMethodValue = $strPropName . "_" . $objObject->getStrSystemid();
                             if (uniStrlen($objMethodValue) > 10) {
                                 $objMethodValue = uniStrTrim($objMethodValue, 10, "");
                             }
                         }
                     } else {
                         if ($strDataType == "int" || $strDataType == "numeric") {
                             if ($strFieldType != "dropdown") {
                                 $objMethodValue = 1;
                             }
                         } else {
                             if ($strDataType == "class_date") {
                                 $objMethodValue = new class_date();
                             } else {
                                 if ($strDataType == "bool") {
                                     $objMethodValue = false;
                                 } else {
                                     continue;
                                     //continue with foreach
                                 }
                             }
                         }
                     }
                     $objObject->{$strSetterMethod}($objMethodValue);
                 }
             }
         }
     }
     //save it
     $objObject->updateObjectToDb($strParentId);
     return $objObject;
 }
 /**
  * Adds a new field to the current form.
  * Therefore, the current source-object is inspected regarding the passed propertyname.
  * So it is essential to provide the matching getters and setters in order to have all
  * set up dynamically.
  *
  * @param string $strPropertyName
  * @return class_formentry_base|interface_formentry
  * @throws class_exception
  */
 public function addDynamicField($strPropertyName)
 {
     //try to get the matching getter
     $objReflection = new class_reflection($this->objSourceobject);
     $strGetter = $objReflection->getGetter($strPropertyName);
     if ($strGetter === null) {
         throw new class_exception("unable to find getter for property " . $strPropertyName . "@" . get_class($this->objSourceobject), class_exception::$level_ERROR);
     }
     //load detailed properties
     $strType = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_TYPE_ANNOTATION);
     $strValidator = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_VALIDATOR_ANNOTATION);
     $strMandatory = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_MANDATORY_ANNOTATION);
     $strLabel = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_LABEL_ANNOTATION);
     $strHidden = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_HIDDEN_ANNOTATION);
     $strReadonly = $objReflection->getAnnotationValueForProperty($strPropertyName, self::STR_READONLY_ANNOTATION);
     if ($strType === null) {
         $strType = "text";
     }
     $strStart = uniSubstr($strPropertyName, 0, 3);
     if (in_array($strStart, array("int", "bit", "str", "arr", "obj"))) {
         $strPropertyName = uniStrtolower(uniSubstr($strPropertyName, 3));
     }
     $strStart = uniSubstr($strPropertyName, 0, 4);
     if (in_array($strStart, array("long"))) {
         $strPropertyName = uniStrtolower(uniSubstr($strPropertyName, 4));
     }
     $strStart = uniSubstr($strPropertyName, 0, 5);
     if (in_array($strStart, array("float"))) {
         $strPropertyName = uniStrtolower(uniSubstr($strPropertyName, 5));
     }
     $objField = $this->getFormEntryInstance($strType, $strPropertyName);
     if ($strLabel !== null) {
         $objField->updateLabel($strLabel);
     }
     $bitMandatory = false;
     if ($strMandatory !== null && $strMandatory !== "false") {
         $bitMandatory = true;
     }
     $objField->setBitMandatory($bitMandatory);
     $bitReadonly = false;
     if ($strReadonly !== null && $strReadonly !== "false") {
         $bitReadonly = true;
     }
     $objField->setBitReadonly($bitReadonly);
     if ($strValidator !== null) {
         $objField->setObjValidator($this->getValidatorInstance($strValidator));
     }
     $this->addField($objField, $strPropertyName);
     if ($strHidden !== null) {
         $this->addFieldToHiddenGroup($objField);
     }
     return $objField;
 }
 /**
  * Processes all object assignments in order to generate the relevant tables
  *
  * @param $strClass
  *
  * @return array
  */
 private function collectAssignmentDefinitions($strClass)
 {
     $arrAssignmentTables = array();
     $objReflection = new class_reflection($strClass);
     //get the mapped properties
     $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS());
     foreach ($arrProperties as $strPropertyName => $arrValues) {
         $strTableName = $objReflection->getAnnotationValueForProperty($strPropertyName, class_orm_base::STR_ANNOTATION_OBJECTLIST);
         if (!isset($arrValues["source"]) || !isset($arrValues["target"]) || empty($strTableName)) {
             continue;
         }
         $objTable = new class_orm_schemamanager_table($strTableName);
         $objTable->addRow(new class_orm_schemamanager_row($arrValues["source"], class_db_datatypes::STR_TYPE_CHAR20, false, true));
         $objTable->addRow(new class_orm_schemamanager_row($arrValues["target"], class_db_datatypes::STR_TYPE_CHAR20, false, true));
         $arrAssignmentTables[] = $objTable;
     }
     return $arrAssignmentTables;
 }
 private function getValueForAnnotations(&$strPrefix, &$arrDepends)
 {
     $objReflection = new class_reflection($this->getObjSourceObject());
     //try to find the matching source property
     $arrProperties = $objReflection->getPropertiesWithAnnotation(self::STR_VALUE_ANNOTATION);
     $strSourceProperty = null;
     foreach ($arrProperties as $strPropertyName => $strValue) {
         if (uniSubstr(uniStrtolower($strPropertyName), uniStrlen($this->getStrSourceProperty()) * -1) == $this->getStrSourceProperty()) {
             $strSourceProperty = $strPropertyName;
         }
     }
     if ($strSourceProperty == null) {
         return;
     }
     $strPrefix = trim($objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_VALUE_ANNOTATION));
     $strDependant = trim($objReflection->getAnnotationValueForProperty($strSourceProperty, self::STR_DEPENDS_ANNOTATION));
     $arrDepends = explode(" ", $strDependant);
     array_walk($arrDepends, function (&$strValue) {
         $strValue = trim($strValue);
     });
 }