/** * This method returns the value associated with the specified property name. * * @access public * @param string $name the name of the property * @return mixed the value for the specified * property name */ public function __get($name) { if (property_exists($this, $name)) { return $this->{$name}; } return Core\Data\Undefined::instance(); }
/** * This method returns the value associated with the specified property name. * * @access public * @param string $name the name of the property * @return mixed the value for the specified * property name */ public function __get($name) { $property = strtolower($name); if (property_exists($this, $property)) { return $this->{$property}; } return Core\Data\Undefined::instance(); }
/** * This constructor initializes the property to an undefined value. * * @access public * @param mixed $data any data to pre-set */ public function __construct($data = array()) { $properties = get_object_vars($this); $data = Core\Convert::toDictionary($data); foreach ($properties as $name => $value) { $this->{$name} = array_key_exists($name, $data) ? $data[$name] : Core\Data\Undefined::instance(); } }
/** * This method adds a value to the query string. * * @access public * @param string $key the key to be used * @param mixed $value the value to be added * @return string the query string segment */ public function addValue($key, $value) { if (!Core\Data\Undefined::instance()->__equals($value)) { $field = preg_replace('/\\[[^\\]]*\\]/', '[]', $key); $type = isset($this->metadata['schema'][$field]) ? $this->metadata['schema'][$field] : 'string'; $value = Core\Convert::changeType($value, $type); $value = Core\Convert::toString($value); $value = Core\Data\Charset::encode($value, $this->metadata['encoding'][0], $this->metadata['encoding'][1]); $value = urlencode($value); return $key . '=' . $value; } return null; }
/** * This method returns whether the specified value is "zero" (i.e. "null", "undefined", or a * number is equal to "0"). * * @access public * @static * @param mixed $value the value to be evaluated * @return boolean whether the value is "zero" */ public static function isZero($value) { return $value === null || Core\Data\Undefined::instance()->__equals($value) || is_numeric($value) && $value == 0; }
/** * This method puts the key/value mapping to the collection. * * @access public * @override * @param mixed $key the key to be mapped * @param mixed $value the value to be mapped * @return boolean whether the key/value pair was set */ public function putEntry($key, $value) { try { if (Core\Data\Undefined::instance()->__equals($value)) { return $this->removeKey($key); } else { $key = $this->getKey($key); if (isset($this->schema['properties'][$key])) { $definition = $this->schema['properties'][$key]; if (isset($definition['type'])) { switch ($definition['type']) { case 'array': $value = MappingService\Data\Model\JSON\Helper::resolveArrayValue($value, $definition); break; case 'boolean': $value = MappingService\Data\Model\JSON\Helper::resolveBooleanValue($value, $definition); break; case 'integer': $value = MappingService\Data\Model\JSON\Helper::resolveIntegerValue($value, $definition); break; case 'number': $value = MappingService\Data\Model\JSON\Helper::resolveNumberValue($value, $definition); break; case 'null': $value = MappingService\Data\Model\JSON\Helper::resolveNullValue($value, $definition); break; case 'object': $value = MappingService\Data\Model\JSON\Helper::resolveObjectValue($value, $definition); break; case 'string': $value = MappingService\Data\Model\JSON\Helper::resolveStringValue($value, $definition); break; } } $this->elements[$key] = $value; return true; } return false; } } catch (\Exception $ex) { return false; } }
/** * This method converts the specified value to the specified type. * * @access public * @static * @param mixed $value the value to be converted * @param string $type the data type to be applied * @return mixed the new value * @throws \Unicity\Throwable\Parse\Exception indicates that the value could not * be converted */ public static function changeType($value, $type) { $type2 = strtolower($type); switch ($type2) { case 'array': case 'list': return static::toArray($value); case 'assoc': case 'dictionary': case 'map': return static::toDictionary($value); case 'bool': case 'boolean': return static::toBoolean($value); case 'char': return static::toChar($value); case 'date': case 'datetime': case 'time': case 'timestamp': return static::toDateTime($value); case 'decimal': case 'double': case 'float': case 'money': case 'number': case 'real': case 'single': return static::toDouble($value); case 'bit': case 'byte': case 'int': case 'int8': case 'int16': case 'int32': case 'int64': case 'long': case 'short': case 'uint': case 'uint8': case 'uint16': case 'uint32': case 'uint64': case 'integer': case 'word': return static::toInteger($value); case 'object': return static::toObject($value); case 'ord': case 'ordinal': return static::toOrdinal($value); case 'nil': case 'null': return null; case 'nvarchar': case 'string': case 'varchar': return static::toString($value); case 'undefined': return Core\Data\Undefined::instance(); default: throw new Throwable\Parse\Exception('Invalid cast. Could not convert value of type ":type1" to a(n) :type2.', array(':type1' => gettype($value), ':type2' => $type)); } }
/** * This method puts the key/value mapping to the collection. * * @access public * @param mixed $key the key to be mapped * @param mixed $value the value to be mapped */ public function putItem($key, $value) { Core\DataType::enforce('integer|string', $key); if (Core\Data\Undefined::instance()->__equals($value)) { $this->removeKey($key); } else { $this->elements[$key] = $value; } }
/** * This method processes an "undefined" node. * * @access protected * @param \SimpleXMLElement $node a reference to the "undefined" node * @return Core\Data\Undefined the undefined object * @throws Throwable\Instantiation\Exception indicates that problem occurred during * the instantiation */ protected function parseUndefinedElement(\SimpleXMLElement $node) { return Core\Data\Undefined::instance(); }
/** * This method puts the key/value mapping to the collection. * * @access public * @override * @param mixed $key the key to be mapped * @param mixed $value the value to be mapped * @return boolean whether the key/value pair was set */ public function putEntry($key, $value) { if (Core\Data\Undefined::instance()->__equals($value)) { return $this->removeKey($key); } else { return parent::putEntry($key, $value); } }
/** * This method returns an object matching the description specified by the element. * * @access public * @param Spring\Object\Parser $parser a reference to the parser * @param \SimpleXMLElement $element the element to be parsed * @return mixed an object matching the description * specified by the element * @throws Throwable\Parse\Exception indicates that a problem occurred * when parsing * * @see https://vcfvct.wordpress.com/2012/12/03/init-method%E3%80%81postconstruct%E3%80%81afterpropertiesset/ */ public function getObject(Spring\Object\Parser $parser, \SimpleXMLElement $element) { $attributes = $element->attributes(); $class = $object = null; if (isset($attributes['factory-object']) && isset($attributes['factory-method'])) { $factory_object = $parser->valueOf($attributes['factory-object']); if ($parser->isClassName($factory_object) && class_exists($factory_object)) { $class = new \ReflectionClass($factory_object); $factory_method = $parser->valueOf($attributes['factory-method']); if ($parser->isMethodName($factory_method) && $class->hasMethod($factory_method)) { $method = $class->getMethod($factory_method); if (!$method->isPublic() || !$method->isStatic() || $method->isAbstract() || $method->isDestructor()) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid method name, but got ":name".', array(':name' => $factory_method)); } $constructor_args = $this->getConstructorArgs($parser, $element); $object = $method->invokeArgs($class, $constructor_args); } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid method name, but got ":name".', array(':name' => $factory_method)); } } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid class name, but got ":name".', array(':name' => $factory_object)); } } else { if (isset($attributes['type'])) { $type = $parser->valueOf($attributes['type']); if (!$parser->isClassName($type)) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid class name, but got ":type".', array(':type' => $type)); } $type = str_replace('.', '\\', $type); if (preg_match('/^(\\\\)?stdClass$/', $type)) { $object = new \stdClass(); } else { if (preg_match('/^(\\\\)?Unicity\\\\Core\\\\Data\\\\Undefined$/', $type)) { $object = Core\Data\Undefined::instance(); } else { $class = new \ReflectionClass($type); if ($class->isAbstract()) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid class name, but got ":type".', array(':type' => $type)); } $constructor_args = $this->getConstructorArgs($parser, $element); if (isset($attributes['factory-method'])) { $factory_method = $parser->valueOf($attributes['factory-method']); if ($parser->isMethodName($factory_method) && $class->hasMethod($factory_method)) { $method = $class->getMethod($factory_method); if (!$method->isPublic() || !$method->isStatic() || $method->isAbstract() || $method->isDestructor()) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid method name, but got ":name".', array(':name' => $factory_method)); } $object = $method->invokeArgs(null, $constructor_args); } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid method name, but got ":name".', array(':name' => $factory_method)); } } else { $object = $class->newInstanceArgs($constructor_args); } } } } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Tag ":tag" is missing ":attribute" attribute.', array(':tag' => 'object', ':attribute' => 'type')); } } $type = gettype($object); if ($type == 'object') { $this->getProperties($parser, $element, $object); if ($object instanceof Spring\InitializingObject) { $object->afterPropertiesSet(); } if (isset($attributes['init-method'])) { $init_method = $parser->valueOf($attributes['init-method']); if ($parser->isMethodName($init_method) && $class->hasMethod($init_method)) { $method = $class->getMethod($init_method); if (!$method->isPublic() || $method->isStatic() || $method->isAbstract() || $method->isDestructor()) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid method name, but got ":name".', array(':name' => $init_method)); } $method->invoke($object); } else { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected a valid method name, but got ":name".', array(':name' => $init_method)); } } if ($object instanceof Spring\FactoryObject) { $object = $object->getObject(); $type = gettype($object); } } if (!in_array($type, array('object', 'NULL', 'array', 'string'))) { throw new Throwable\Parse\Exception('Unable to process Spring XML. Expected an object to be returned, but got ":type".', array(':type' => $type)); } return $object; }
/** * This method returns the element at the the specified index. * * @access public * @param integer $index the index of the element * @return mixed the element at the specified index * @throws Throwable\InvalidArgument\Exception indicates that an index must be an integer * @throws Throwable\OutOfBounds\Exception indicates that the index is out of bounds */ public function getValue($index) { if (is_integer($index)) { if (array_key_exists($index, $this->elements)) { return $this->elements[$index]; } else { if ($index == $this->count()) { if (isset($this->schema['items'][0])) { $definition = $this->schema['items'][0]; if (isset($definition['type'])) { switch ($definition['type']) { case 'array': $value = new MappingService\Data\Model\JSON\ArrayList($definition, $this->case_sensitive); $this->elements[$index] = $value; return $value; case 'object': $value = new MappingService\Data\Model\JSON\HashMap($definition, $this->case_sensitive); $this->elements[$index] = $value; return $value; } } if (isset($definition['default'])) { $value = $definition['default']; $this->elements[$index] = $value; return $value; } } $value = Core\Data\Undefined::instance(); $this->elements[$index] = $value; return $value; } } throw new Throwable\OutOfBounds\Exception('Unable to get element. Undefined index at ":index" specified', array(':index' => $index)); } throw new Throwable\InvalidArgument\Exception('Unable to get element. ":type" is of the wrong data type.', array(':type' => Core\DataType::info($index)->type)); }
/** * This method parses a child node. * * @access protected * @param \SimpleXMLElement $node a reference to a child node * @return \Unicity\Common\Mutable\ICollection a collection representing the data * in the soap file * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseChildElement(\SimpleXMLElement $node) { $children = $node->children(); if (count($children) > 0) { $list = new Common\Mutable\ArrayList(); $map = new Common\Mutable\HashMap(); foreach ($children as $child) { $name = $child->getName(); $value = $this->parseChildElement($child); $temp = new Common\Mutable\HashMap(); $temp->putEntry($name, $value); $list->addValue($temp); $map->putEntry($name, $value); } return $list->count() > $map->count() || $this->directives->hasKey('expandableProperties') && $this->directives->getValue('expandableProperties')->hasValue($node->getName()) ? $list : $map; } else { $value = dom_import_simplexml($node)->textContent; $value = trim($value); if ($value == '') { $value = Core\Data\Undefined::instance(); } else { if (preg_match('/^(true|false)$/i', $value)) { $value = Core\Convert::toBoolean($value); } else { if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) { $value = Core\Convert::toDouble($value); } else { if (filter_var($value, FILTER_VALIDATE_INT) !== false) { $value = Core\Convert::toInteger($value); } else { $value = Core\Convert::toString($value); } } } } return $value; } }
/** * This method returns an object matching the description specified by the element. * * @access public * @param Spring\Object\Parser $parser a reference to the parser * @param \SimpleXMLElement $element the element to be parsed * @return mixed an object matching the description * specified by the element * @throws Throwable\Parse\Exception indicates that a problem occurred * when parsing */ public function getObject(Spring\Object\Parser $parser, \SimpleXMLElement $element) { return Core\Data\Undefined::instance(); }
/** * This method parses a custom node. * * @access protected * @param \SimpleXMLElement $node a reference to a custom node * @return \Unicity\Common\Mutable\ICollection a collection representing the data * in the soap file * @throws \Unicity\Throwable\Parse\Exception indicates that an unrecognized child * node was encountered */ protected function parseCustomElement(\SimpleXMLElement $node) { $children = $this->getElementChildren($node, null); if (count($children) > 0) { $list = new Common\Mutable\ArrayList(); $map = new Common\Mutable\HashMap(); foreach ($children as $child) { $name = $child->getName(); $value = $this->parseCustomElement($child); $temp = new Common\Mutable\HashMap(); $temp->putEntry($name, $value); $list->addValue($temp); $map->putEntry($name, $value); } return $list->count() > $map->count() || $this->directives->hasKey('expandableProperties') && $this->directives->getValue('expandableProperties')->hasValue($node->getName()) ? $list : $map; } else { $value = dom_import_simplexml($node)->textContent; $value = trim($value); if ($value == '') { $attributes = $node->attributes('xsi', true); if (isset($attributes['nil'])) { $nil = SOAP\Data\XML::valueOf($attributes['nil']); if (!SOAP\Data\XML\Syntax::isBoolean($nil)) { throw new Throwable\Parse\Exception('Unable to process SOAP XML. Expected a valid boolean token, but got ":token".', array(':token' => $nil)); } $value = strtolower($nil) != 'false' ? null : Core\Data\Undefined::instance(); } else { $value = Core\Data\Undefined::instance(); } } else { if (preg_match('/^(true|false)$/i', $value)) { $value = Core\Convert::toBoolean($value); } else { if (preg_match('/^[+-]?(0|[1-9][0-9]*)((\\.[0-9]+)|([eE][+-]?(0|[1-9][0-9]*)))$/', $value)) { $value = Core\Convert::toDouble($value); } else { if (filter_var($value, FILTER_VALIDATE_INT) !== false) { $value = Core\Convert::toInteger($value); } else { $value = Core\Convert::toString($value); } } } } return $value; } }