/** * Returns the fitting form generator for the model. The result is cached so that the a model returns always the * same instance * * @param interface_model $objInstance * @return class_admin_formgenerator * @throws class_exception */ public static function createByModel(interface_model $objInstance) { // check whether the form was already generated $objForm = self::getFormForModel($objInstance); if ($objForm !== null) { return $objForm; } // check whether a specific form generator class was specified per annotation $objReflection = new class_reflection($objInstance); $arrValues = $objReflection->getAnnotationValuesFromClass(self::STR_FORMGENERATOR_ANNOTATION); if (!empty($arrValues)) { $strClass = current($arrValues); if (class_exists($strClass)) { $objForm = new $strClass($objInstance->getArrModule("module"), $objInstance); } else { throw new class_exception("Provided form generator class does not exist", class_exception::$level_ERROR); } } else { $objForm = new class_admin_formgenerator($objInstance->getArrModule("module"), $objInstance); } // check whether we have an correct instance if ($objForm instanceof class_admin_formgenerator) { $objForm->generateFieldsFromObject(); return self::$arrForms[self::getKeyByModel($objInstance)] = $objForm; } else { throw new class_exception("Provided form generator must be an instance of class_admin_formgenerator", class_exception::$level_ERROR); } }
/** * 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); } } }
/** * @param interface_admin|interface_portal $objViewInstance */ private function runSingleFile($objViewInstance) { $objReflection = new ReflectionClass($objViewInstance); $arrMethods = $objReflection->getMethods(); $objAnnotations = new class_reflection(get_class($objViewInstance)); //collect the autotestable annotations located on class-level foreach ($objAnnotations->getAnnotationValuesFromClass("@autoTestable") as $strValue) { foreach (explode(",", $strValue) as $strOneMethod) { echo "found method " . get_class($objViewInstance) . "@" . $strOneMethod . " marked as class-based @autoTestable, preparing call\n"; echo " calling via action() method\n"; $objViewInstance->action($strOneMethod); } } /** @var ReflectionMethod $objOneMethod */ foreach ($arrMethods as $objOneMethod) { if ($objAnnotations->hasMethodAnnotation($objOneMethod->getName(), "@autoTestable")) { echo "found method " . get_class($objViewInstance) . "@" . $objOneMethod->getName() . " marked as @autoTestable, preparing call\n"; if (uniSubstr($objOneMethod->getName(), 0, 6) == "action" && $objReflection->hasMethod("action")) { echo " calling via action() method\n"; $objViewInstance->action(uniSubstr($objOneMethod->getName(), 6)); } else { echo " direct call"; $objOneMethod->invoke($objViewInstance); } } } }
/** * Restores all properties marked as versionable * * @param interface_versionable $objObject * @param class_date $objTimestamp */ public function restoreObject(interface_versionable $objObject, class_date $objTimestamp) { $objReflection = new class_reflection($objObject); $arrProperties = $objReflection->getPropertiesWithAnnotation(self::ANNOTATION_PROPERTY_VERSIONABLE); foreach ($arrProperties as $strProperty => $strAnnotation) { $this->restoreProperty($objObject, $objTimestamp, $strProperty); } }
public function setValueToObject() { $objReflection = new class_reflection($this->getObjSourceObject()); $strSetter = $objReflection->getSetter($this->getStrSourceProperty()); if ($strSetter !== null && uniStrtolower(uniSubstr($strSetter, 0, 6)) == "setobj" && !$this->getStrValue() instanceof class_date && $this->getStrValue() > 0) { $this->setStrValue(new class_date($this->getStrValue())); } return parent::setValueToObject(); }
/** * 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() . " ? "; }
/** * returns the table used by the element * * @return string */ public function getTable() { $objAnnotations = new class_reflection($this); $arrTargetTables = $objAnnotations->getAnnotationValuesFromClass(class_orm_base::STR_ANNOTATION_TARGETTABLE); if (count($arrTargetTables) != 0) { $arrTable = explode(".", $arrTargetTables[0]); return _dbprefix_ . $arrTable[0]; } //legacy code return $this->getArrModule("table"); }
/** * 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); }
/** * Injects the lazy loading objects for assignment properties into the current object * @return void */ private function initAssignmentProperties() { $objReflection = new class_reflection($this->getObjObject()); //get the mapped properties $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS()); foreach ($arrProperties as $strPropertyName => $arrValues) { $objPropertyLazyLoader = new class_orm_assignment_array($this->getObjObject(), $strPropertyName, $this->getIntCombinedLogicalDeletionConfig()); $strSetter = $objReflection->getSetter($strPropertyName); if ($strSetter !== null) { call_user_func(array($this->getObjObject(), $strSetter), $objPropertyLazyLoader); } } }
/** * Reads the properties marked with templateExport from the current object * * @return void */ private function readPropertiesFromObject() { $objReflection = new class_reflection($this->objObject); $properties = $this->getPropertyNames(); foreach ($properties as $strOneProperty) { $strGetter = $objReflection->getGetter($strOneProperty); $strValue = call_user_func(array($this->objObject, $strGetter)); if ($strValue instanceof class_date) { $strValue = date(DateTime::ATOM, $strValue->getTimeInOldStyle()); } $this->arrMapping[$strOneProperty] = $strValue; } }
/** * Clears the assignments of the current object, if given * * @return bool */ private function deleteAssignments() { $bitReturn = true; $objReflection = new class_reflection($this->getObjObject()); $objDB = class_carrier::getInstance()->getObjDB(); //get the mapped properties $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_OBJECTLIST, class_reflection_enum::PARAMS()); foreach ($arrProperties as $strPropertyName => $arrValues) { $objCfg = class_orm_assignment_config::getConfigForProperty($this->getObjObject(), $strPropertyName); $bitReturn = $bitReturn && $objDB->_pQuery("DELETE FROM " . $objDB->encloseTableName(_dbprefix_ . $objCfg->getStrTableName()) . " WHERE " . $objDB->encloseColumnName($objCfg->getStrSourceColumn()) . " = ? ", array($this->getObjObject()->getSystemid())); } return $bitReturn; }
public function setValueToObject() { $objSourceObject = $this->getObjSourceObject(); if ($objSourceObject == null) { return ""; } $objReflection = new class_reflection($objSourceObject); $strSetter = $objReflection->getSetter($this->getStrSourceProperty()); if ($strSetter === null) { throw new class_exception("unable to find setter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR); } return call_user_func(array($objSourceObject, $strSetter), json_encode($this->getStrValue())); }
/** * 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); } }
/** * Creates an model based on an serialized string * * @return interface_model */ public static function unserialize($strData) { $arrData = json_decode($strData, true); $objModel = self::getObjectFromJson($arrData); $objReflection = new class_reflection(get_class($objModel)); $arrProperties = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrProperties as $strAttributeName => $strAttributeValue) { $strSetter = $objReflection->getSetter($strAttributeName); if ($strSetter != null && isset($arrData[$strAttributeName])) { $objModel->{$strSetter}($arrData[$strAttributeName]); } } return $objModel; }
public function testModuleModels() { echo "preparing object saves...\n"; class_carrier::getInstance()->getObjRights()->setBitTestMode(true); $arrFiles = class_resourceloader::getInstance()->getFolderContent("/system", array(".php"), false, function ($strOneFile) { if (uniStripos($strOneFile, "class_module_") !== false) { $objClass = new ReflectionClass(uniSubstr($strOneFile, 0, -4)); if (!$objClass->isAbstract() && $objClass->isSubclassOf("class_model")) { $objAnnotations = new class_reflection(uniSubstr($strOneFile, 0, -4)); //block from autotesting? if ($objAnnotations->hasClassAnnotation("@blockFromAutosave")) { echo "skipping class " . uniSubstr($strOneFile, 0, -4) . " due to @blockFromAutosave annotation" . "\n"; return false; } return true; } } return false; }, function (&$strOneFile) { $strOneFile = uniSubstr($strOneFile, 0, -4); $strOneFile = new $strOneFile(); }); $arrSystemids = array(); /** @var $objOneInstance class_model */ foreach ($arrFiles as $objOneInstance) { echo "testing object of type " . get_class($objOneInstance) . "@" . $objOneInstance->getSystemid() . "\n"; $this->assertTrue($objOneInstance->updateObjectToDb(), "saving object " . get_class($objOneInstance)); $arrSystemids[$objOneInstance->getSystemid()] = get_class($objOneInstance); echo " ...saved object of type " . get_class($objOneInstance) . "@" . $objOneInstance->getSystemid() . "\n"; } $objObjectfactory = class_objectfactory::getInstance(); foreach ($arrSystemids as $strSystemid => $strClass) { echo "instantiating " . $strSystemid . "@" . $strClass . "\n"; $objInstance = $objObjectfactory->getObject($strSystemid); $this->assertTrue($objInstance != null); $this->assertEquals(get_class($objInstance), $strClass); echo "deleting " . $strSystemid . "@" . $strClass . "\n"; $objInstance->deleteObjectFromDatabase(); } class_carrier::getInstance()->getObjRights()->setBitTestMode(false); }
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 ""; }
/** * The real "download" or "upload" should be handled right here. * All packages have to be downloaded to /project/temp in order to be processed afterwards. * * @return string the filename of the package downloaded */ public function processPackageUpload() { //fetch the upload, validate a few settings and copy the package to /project/temp $arrSource = class_carrier::getInstance()->getParam("provider_local_file"); $strTarget = "/project/temp/" . generateSystemid() . ".zip"; $objFilesystem = new class_filesystem(); //Check file for correct filters $strSuffix = uniStrtolower(uniSubstr($arrSource["name"], uniStrrpos($arrSource["name"], "."))); if (in_array($strSuffix, array(".zip"))) { if ($objFilesystem->copyUpload($strTarget, $arrSource["tmp_name"])) { class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("uploaded package " . $arrSource["name"] . " to " . $strTarget, class_logger::$levelInfo); class_resourceloader::getInstance()->flushCache(); class_classloader::getInstance()->flushCache(); class_reflection::flushCache(); return $strTarget; } } class_logger::getInstance(class_logger::PACKAGEMANAGEMENT)->addLogRow("error in uploaded package " . $arrSource["name"] . " either wrong format or not writeable target folder", class_logger::$levelInfo); @unlink($arrSource["tmp_name"]); return null; }
/** * @xml * @permissions edit * @return string */ protected function actionUpdateObjectProperty() { $strReturn = ""; //get the object to update /** @var $objObject class_module_pages_element */ $objObject = class_objectfactory::getInstance()->getObject($this->getSystemid()); if ($objObject->rightEdit()) { //differ between two modes - page-elements or regular objects if ($objObject instanceof class_module_pages_pageelement) { $strPageSystemid = $objObject->getPrevId(); $objLockmanager = new class_lockmanager($objObject->getSystemid()); if (!$objLockmanager->isLocked()) { $objLockmanager->lockRecord(); } if ($objLockmanager->isLockedByCurrentUser()) { //and finally create the object /** @var class_module_pages_pageelement $objElement */ $strElementClass = str_replace(".php", "", $objObject->getStrClassAdmin()); //and finally create the object /** @var $objElement class_element_admin */ $objElement = new $strElementClass(); $objElement->setSystemid($this->getSystemid()); $arrElementData = $objElement->loadElementData(); //see if we could set the param to the element if ($this->getParam("property") != "") { $strProperty = null; //try to fetch the matching setter $objReflection = new class_reflection($objElement); //try to fetch the property based on the orm annotations $strTargetTable = $objReflection->getAnnotationValuesFromClass(class_orm_base::STR_ANNOTATION_TARGETTABLE); if (count($strTargetTable) > 0) { $strTargetTable = $strTargetTable[0]; } $arrTable = explode(".", $strTargetTable); if (count($arrTable) == 2) { $strTargetTable = $arrTable[0]; } $arrOrmProperty = $objReflection->getPropertiesWithAnnotation(class_orm_base::STR_ANNOTATION_TABLECOLUMN); foreach ($arrOrmProperty as $strCurProperty => $strValue) { if ($strValue == $strTargetTable . "." . $this->getParam("property")) { $strProperty = $strCurProperty; } } if ($strProperty == null) { $strProperty = $this->getParam("property"); } $strSetter = $objReflection->getSetter($strProperty); if ($strSetter != null) { call_user_func(array($objElement, $strSetter), $this->getParam("value")); } else { $arrElementData[$this->getParam("property")] = $this->getParam("value"); $objElement->setArrParamData($arrElementData); } } //pass the data to the element, maybe the element wants to update some data $objElement->doBeforeSaveToDb(); //check, if we could save the data, so the element needn't to //woah, we are soooo great $objElement->updateForeignElement(); //Edit Date of page & unlock $objPage = class_objectfactory::getInstance()->getObject($strPageSystemid); $objPage->updateObjectToDb(); $objLockmanager->unlockRecord(); //allow the element to run actions after saving $objElement->doAfterSaveToDb(); //Loading the data of the corresp site $this->flushCompletePagesCache(); $strReturn = "<message><success>element update succeeded</success></message>"; } } else { //any other object - try to find the matching property and write the value if ($this->getParam("property") == "") { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST); return "<message><error>missing property param</error></message>"; } $objReflection = new class_reflection($objObject); $strSetter = $objReflection->getSetter($this->getParam("property")); if ($strSetter == null) { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_BADREQUEST); return "<message><error>setter not found</error></message>"; } call_user_func(array($objObject, $strSetter), $this->getParam("value")); $objObject->updateObjectToDb(); $this->flushCompletePagesCache(); $strReturn = "<message><success>object update succeeded</success></message>"; } } else { class_response_object::getInstance()->setStrStatusCode(class_http_statuscodes::SC_UNAUTHORIZED); $strReturn = "<message><error>" . $this->getLang("ds_gesperrt") . "." . $this->getLang("commons_error_permissions") . "</error></message>"; } return $strReturn; }
/** * Internal helper, does the parsing of the comment. * Returns an array of all annotations. * * @param string $strDoc * @return array ["annotation_name" => array("values" => values, "params" => params)] */ private function searchAllAnnotationsInDoc($strDoc) { $strDoc = uniStrReplace(array("\r\n", "\r"), "\n", $strDoc); //replace needed as regex on windows or mac won't work properly $arrReturn = array(); $strCacheKey = md5($strDoc); if (isset($this->arrCurrentCache[self::$STR_DOC_COMMENT_PROPERTIES_CACHE][$strCacheKey])) { return $this->arrCurrentCache[self::$STR_DOC_COMMENT_PROPERTIES_CACHE][$strCacheKey]; } $arrMatches = array(); if (preg_match_all("/(@[a-zA-Z0-9]+)(\\s+.*)?(\\s+\\(.*\\))?\$/Um", $strDoc, $arrMatches, PREG_SET_ORDER) !== false) { foreach ($arrMatches as $arrOneMatch) { $strName = $arrOneMatch[1]; $strValue = isset($arrOneMatch[2]) ? $arrOneMatch[2] : ""; $strParams = isset($arrOneMatch[3]) ? $arrOneMatch[3] : ""; if (!isset($arrReturn[$strName])) { $arrReturn[$strName] = array("values" => array(), "params" => array()); } $arrReturn[$strName]["values"][] = trim($strValue); $arrReturn[$strName]["params"][] = $this->params2Array(trim($strParams)); } } $this->arrCurrentCache[self::$STR_DOC_COMMENT_PROPERTIES_CACHE][$strCacheKey] = $arrReturn; self::$bitCacheSaveRequired = true; return $arrReturn; }
/** * @permissions edit * @return string */ protected function actionCopyPack() { $objForm = $this->getPackAdminForm(); $strPackName = $this->getParam("pack_name"); $strPackName = createFilename($strPackName, true); if ($strPackName != "" && is_dir(_realpath_ . _templatepath_ . "/" . $strPackName)) { $objForm->addValidationError("name", $this->getLang("pack_folder_existing")); } if (!$objForm->validateForm()) { return $this->actionNew($objForm); } $objFilesystem = new class_filesystem(); $objFilesystem->folderCreate(_templatepath_ . "/" . $strPackName); $objFilesystem->folderCreate(_templatepath_ . "/" . $strPackName . "/tpl"); $objFilesystem->folderCreate(_templatepath_ . "/" . $strPackName . "/css"); $objFilesystem->folderCreate(_templatepath_ . "/" . $strPackName . "/js"); $arrModules = $this->getParam("pack_modules"); foreach ($arrModules as $strName => $strValue) { if ($strValue != "") { $objFilesystem->folderCopyRecursive(class_resourceloader::getInstance()->getCorePathForModule($strName) . "/" . $strName . "/templates/default", _templatepath_ . "/" . $strPackName); } } class_resourceloader::getInstance()->flushCache(); class_classloader::getInstance()->flushCache(); class_reflection::flushCache(); $this->adminReload(class_link::getLinkAdminHref($this->getArrModule("modul"), "listTemplates")); return ""; }
/** * @param string $strSystemid */ public function __construct($strSystemid = "") { //Generating all the required objects. For this we use our cool cool carrier-object //take care of loading just the necessary objects $objCarrier = class_carrier::getInstance(); $this->objConfig = $objCarrier->getObjConfig(); $this->objSession = $objCarrier->getObjSession(); $this->objLang = $objCarrier->getObjLang(); $this->objTemplate = $objCarrier->getObjTemplate(); //Setting SystemID if ($strSystemid == "") { $this->setSystemid(class_carrier::getInstance()->getParam("systemid")); } else { $this->setSystemid($strSystemid); } //And keep the action $this->setAction($this->getParam("action")); //in most cases, the list is the default action if no other action was passed if ($this->getAction() == "") { $this->setAction("list"); } //try to load the current module-name and the moduleId by reflection $objReflection = new class_reflection($this); if (!isset($this->arrModule["modul"])) { $arrAnnotationValues = $objReflection->getAnnotationValuesFromClass(self::STR_MODULE_ANNOTATION); if (count($arrAnnotationValues) > 0) { $this->setArrModuleEntry("modul", trim($arrAnnotationValues[0])); } $this->setArrModuleEntry("module", trim($arrAnnotationValues[0])); } if (!isset($this->arrModule["moduleId"])) { $arrAnnotationValues = $objReflection->getAnnotationValuesFromClass(self::STR_MODULEID_ANNOTATION); if (count($arrAnnotationValues) > 0) { $this->setArrModuleEntry("moduleId", constant(trim($arrAnnotationValues[0]))); } } $this->strLangBase = $this->getArrModule("modul"); }
/** * Returns a short description of the saved content * Overwrite if needed * * @return string */ public function getContentTitle() { $objAnnotations = new class_reflection($this); $arrProperties = $objAnnotations->getPropertiesWithAnnotation(class_element_admin::STR_ANNOTATION_ELEMENTCONTENTTITLE); if (count($arrProperties) > 0) { $this->loadElementData(); $arrKeys = array_keys($arrProperties); $strGetter = $objAnnotations->getGetter($arrKeys[0]); if ($strGetter != null) { //explicit casts required? could be relevant, depending on the target column type / database system return call_user_func(array($this, $strGetter)); } } return ""; }
/** * Scans the passed object and tries to find all properties marked with the annotation @versionable. * @param interface_versionable|class_model $objCurrentObject * * @return array|null */ private function readVersionableProperties(interface_versionable $objCurrentObject) { if (!$this->isVersioningAvailable($objCurrentObject)) { return null; } if (validateSystemid($objCurrentObject->getSystemid())) { $arrCurrentValues = array(); $objReflection = new class_reflection($objCurrentObject); $arrProperties = $objReflection->getPropertiesWithAnnotation(self::ANNOTATION_PROPERTY_VERSIONABLE); foreach ($arrProperties as $strProperty => $strAnnotation) { $strValue = ""; //all prerequisites match, start creating query $strGetter = $objReflection->getGetter($strProperty); if ($strGetter !== null) { $strValue = call_user_func(array($objCurrentObject, $strGetter)); } if (is_array($strValue) || $strValue instanceof ArrayAccess) { $arrNewValues = array(); foreach ($strValue as $objOneValue) { if (is_object($objOneValue) && $objOneValue instanceof class_root) { $arrNewValues[] = $objOneValue->getSystemid(); } else { $arrNewValues[] = $objOneValue . ""; } } sort($arrNewValues); $strValue = implode(",", $arrNewValues); } $arrCurrentValues[$strProperty] = $strValue; } return $arrCurrentValues; } return null; }
public function setValueToObject() { $objSourceObject = $this->getObjSourceObject(); if ($objSourceObject == null) { return ""; } $objReflection = new class_reflection($objSourceObject); // get database object which we can not change $strGetter = $objReflection->getGetter($this->getStrSourceProperty()); if ($strGetter === null) { throw new class_exception("unable to find getter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR); } $arrObjects = call_user_func(array($objSourceObject, $strGetter)); $arrNotObjects = array_values(array_filter((array) $arrObjects, function (class_model $objObject) { return !$objObject->rightView(); })); // merge objects $arrNewObjects = array_merge($this->toObjectArray(), $arrNotObjects); // filter double object ids $arrObjects = array(); foreach ($arrNewObjects as $objObject) { $arrObjects[$objObject->getStrSystemid()] = $objObject; } $arrObjects = array_values($arrObjects); // set value $strSetter = $objReflection->getSetter($this->getStrSourceProperty()); if ($strSetter === null) { throw new class_exception("unable to find setter for value-property " . $this->getStrSourceProperty() . "@" . get_class($objSourceObject), class_exception::$level_ERROR); } return call_user_func(array($objSourceObject, $strSetter), $arrObjects); }
/** * @param interface_usersources_group|class_model $objGroup * * @return class_admin_formgenerator */ private function getGroupForm(interface_usersources_group $objGroup) { $objForm = new class_admin_formgenerator("group", $objGroup); //add the global group-name $objForm->addField(new class_formentry_text("group", "name"))->setBitMandatory(true)->setStrLabel($this->getLang("group_name"))->setStrValue($this->getParam("group_name")); if ($objGroup->isEditable()) { //adding elements is more generic right here - load all methods $objAnnotations = new class_reflection($objGroup); $arrProperties = $objAnnotations->getPropertiesWithAnnotation("@fieldType"); foreach ($arrProperties as $strProperty => $strValue) { $objForm->addDynamicField($strProperty); } } $objGroup->updateAdminForm($objForm); return $objForm; }
/** * @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); }
/** * Internal helper to fetch the values of an assignment property. * Capable of handling both, objects and systemids. * * @param string $strPropertyName * @param string[]|null $arrClassFilter * @return array */ private function getAssignmentValuesFromObject($strPropertyName, $arrClassFilter) { $objReflection = new class_reflection($this->getObjObject()); $strGetter = $objReflection->getGetter($strPropertyName); $arrValues = array(); if ($strGetter !== null) { $arrValues = call_user_func(array($this->getObjObject(), $strGetter)); if (!is_array($arrValues) && !$arrValues instanceof ArrayObject) { $arrValues = array(); } } $arrReturn = array(); foreach ($arrValues as $objOneValue) { if (is_object($objOneValue) && $objOneValue instanceof class_model) { if ($arrClassFilter == null || count(array_filter($arrClassFilter, function ($strSingleClass) use($objOneValue) { return $objOneValue instanceof $strSingleClass; })) > 0) { $arrReturn[] = $objOneValue->getSystemid(); } } else { if (is_string($objOneValue) && validateSystemid($objOneValue)) { $arrReturn[] = $objOneValue; } } } return $arrReturn; }