/** * Retrieves the field from the object and returns the desired field, if exists. * @param string The name of the called method * @param string The name of the field to retrieve * @param array The arguments given to the function call * @return mixed The requested field */ private final function retrieveField($name, $fieldName, array $arguments) { $fieldMap = self::validateMap(self::$fieldMap); $virtualMap = self::validateMap(self::$virtualMap); $dataMap = $this->validateInstanceMap($this->data); //check for the existance of a property that adheres to the given fieldName if ($fieldMap->keyExists($fieldName)) { $fieldData = $fieldMap->{$fieldName}; //first check if we are allowed to access this field if (isset($fieldData['noget']) && mb_strtolower((string) $fieldData['noget']) == 'true') { throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not exist in this context.'); } //we retrieve the data from the object $value = $dataMap->{$fieldName}; //if the internal data equals the optional nullify property, we pretend the value to be an empty string, thus uninitialized. if (isset($fieldData['nullify']) && (string) $fieldData['nullify'] == $value) { $value = ''; } //we interpret our data as the given type switch (mb_strtolower((string) $fieldData['type'])) { case \System\Type::TYPE_TIMESTAMP: return \System\Calendar\Time::fromMySQLTimestamp($value); case \System\Type::TYPE_BOOL: case \System\Type::TYPE_BOOLEAN: return (bool) $value; case \System\Type::TYPE_SERIALIZED: //this type is deprecated and we try to convert current existing fields to array type //this type is deprecated and we try to convert current existing fields to array type case \System\Type::TYPE_ARRAY: return self::decodeArray($value); case \System\Type::TYPE_INT: case \System\Type::TYPE_INTEGER: return (int) $value; default: return $value; } } elseif ($virtualMap->keyExists($fieldName)) { //we can use different databases, but default to one used by this instance $db = $this->getDatabase(); //first check the parameter count if (count($arguments) > 1 || count($arguments) == 1 && !$arguments[0] instanceof \System\Db\Database) { throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not accept the given parameters. Expected: ' . $this->getClassName() . '->' . $name . '(\\System\\Db\\Database) or ' . $this->getClassName() . '->' . $name . '().'); } //check if there is an optional database given to use for the virtual function if (count($arguments) == 1 && $arguments[0] instanceof \System\Db\Database) { $db = $arguments[0]; } $virtualMethod = $virtualMap->{$fieldName}; $parameters = new \System\Collection\Vector(); //virtuals only have <value> nodes as children foreach ($virtualMethod->children() as $parameterElement) { //during the creation of the object we included these fields, so we dont need to check their existence in the field list; we know they exist. $queryField = 'virtual_' . (string) $parameterElement; $parameters->add($dataMap[$queryField]); } //do we want the result as a set? $alwaysUseContainer = isset($virtualMethod['alwaysusecontainer']) && (mb_strtolower((string) $virtualMethod['alwaysusecontainer']) == 'true' || mb_strtolower((string) $virtualMethod['alwaysusecontainer']) == 'yes'); return \System\Db\Object::load($db, (string) $virtualMethod['type'], (string) $virtualMethod['condition'], $parameters, $alwaysUseContainer); } else { throw new \System\Error\Exception\InvalidMethodException('Method ' . $this->getClassName() . '->' . $name . '() does not exist in this context.'); } }
/** * Get the timestamp of the onetimecall object * @return \System\Calendar\Time the converted timestamp object */ public final function getTimestamp() { return \System\Calendar\Time::fromMySQLTimestamp($this->internal('getTimestamp')); }