X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fhelper%2Fclass_BaseHelper.php;h=ff4646f749a7cb2d9e5318b3845e2eddd635bded;hp=5cd4ea88b0247d3f567f4185d6408e093f064b0c;hb=36e4d0eb331bd724db0bd23071271d5eaeb37b17;hpb=1dfce1c5d3a9102021322559085bd69f49c981cc diff --git a/inc/classes/main/helper/class_BaseHelper.php b/inc/classes/main/helper/class_BaseHelper.php index 5cd4ea88..ff4646f7 100644 --- a/inc/classes/main/helper/class_BaseHelper.php +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -27,6 +27,11 @@ class BaseHelper extends BaseFrameworkSystem { */ private $valueInstance = null; + /** + * Extra instance to the class which provides field values + */ + private $extraInstance = null; + /** * Rendered content created by the helper class */ @@ -58,9 +63,6 @@ class BaseHelper extends BaseFrameworkSystem { private $totalCounter = 0; // Exception constants - const EXCEPTION_XML_PARSER_ERROR = 0x1e0; - const EXCEPTION_XML_NODE_UNKNOWN = 0x1e1; - const EXCEPTION_XML_NODE_MISMATCH = 0x1e2; const EXCEPTION_GROUP_NOT_OPENED = 0x1e3; const EXCEPTION_GROUP_ALREADY_FOUND = 0x1e4; const EXCEPTION_SUB_GROUP_ALREADY_FOUND = 0x1e5; @@ -173,6 +175,7 @@ class BaseHelper extends BaseFrameworkSystem { public function assignFieldWithFilter ($fieldName, $filterMethod) { // Get the value $fieldValue = $this->getValueField($fieldName); + //* DEBUG: */ $this->debugOutput($fieldName.'='.$fieldValue); // Now filter it through the value through the filter method $filteredValue = call_user_func_array(array($this, 'doFilter' . $this->convertToClassName($filterMethod)), array($fieldValue)); @@ -190,28 +193,33 @@ class BaseHelper extends BaseFrameworkSystem { * @throws NullPointerException If recovery of requested value instance failed */ public function prefetchValueInstance ($registryKey, $extraKey = null) { + //* DEBUG: */ $this->debugOutput('O:'.$registryKey.'/'.$extraKey); try { // Get the required instance $this->valueInstance = Registry::getRegistry()->getInstance($registryKey); } catch (NullPointerException $e) { // Not set in registry // @TODO Try to log it here + //* DEBUG: */ $this->debugOutput($registryKey.'=NULL!'); } - // Is the value instance valid? - if (is_null($this->valueInstance)) { - // Try to create it "from scratch", by first init extra instance - $extraInstance = null; - - // Shall we get an extra instance? - if (!is_null($extraKey)) { + // Shall we get an extra instance? + if (!is_null($extraKey)) { + try { // Get the extra instance. - $extraInstance = Registry::getRegistry()->getInstance($extraKey); - } // END - if + $this->extraInstance = Registry::getRegistry()->getInstance($extraKey); + } catch (NullPointerException $e) { + // Try to create it + $this->extraInstance = ObjectFactory::createObjectByConfiguredName($extraKey . '_class', array($this->valueInstance)); + } + //* DEBUG: */ $this->debugOutput($extraKey.'='.$this->extraInstance.' - EXTRA!'); + } // END - if + // Is the value instance valid? + if (is_null($this->valueInstance)) { try { // Get the requested instance - $this->valueInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class', array($extraInstance)); + $this->valueInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class', array($this->extraInstance)); } catch (FrameworkException $e) { // Okay, nothing found so throw a null pointer exception here throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); @@ -391,7 +399,7 @@ class BaseHelper extends BaseFrameworkSystem { // Now "walk" through all groups and sub-groups for ($idx = 1; $idx <= $this->totalCounter; $idx++) { - // Is this a group and is it closed? + // Is this a sub/group and is it closed? if ((isset($this->groups[$idx])) && ($this->groups[$this->groups[$idx]]['opened'] === false)) { // Then add it's content $groupContent = trim($this->groups[$this->groups[$idx]]['content']); @@ -449,6 +457,13 @@ class BaseHelper extends BaseFrameworkSystem { // Get the field value $fieldValue = $this->getValueInstance()->getField($fieldName); + //* DEBUG: */ $this->debugOutput($fieldName.'[]='.gettype($fieldValue).'('.strlen($fieldValue).')'); + + // Is it null? + if ((is_null($fieldValue)) && (!is_null($this->extraInstance))) { + // So try the extra instance + $fieldValue = $this->extraInstance->getField($fieldName); + } // END - if // Return it return $fieldValue;