/** * @param $value string * @param $property Reflection_Property */ public function __construct($value, Reflection_Property $property) { if (!$value) { $value = $property->getName(); } parent::__construct($value); }
/** * @param $value string * @param $property Reflection_Property ie the contextual Reflection_Property object */ public function __construct($value, Reflection_Property $property) { parent::__construct($value); // default value for @null is true when the property links to a non mandatory object if (!$this->value && !$property->getAnnotation('mandatory')->value && $property->getAnnotation('link')->value == Link_Annotation::OBJECT) { $this->value = true; } }
/** * Guess value for @link using the type of the property (@var) * - property is a Date_Time (or a child class) : @link will be 'DateTime' * - property is a single object : @link will be 'Object' * - property is a collection object with '@var Object[] All' : @link will be 'All' * - property is a collection object with '@var Object[] Collection' : @link will be 'Collection' * - property is a collection object with '@var Object[] Map' : @link will be 'Map' * - property is a collection object without telling anything : * - @link will be 'Collection' if the object is a Component * - @link will be 'Map' if the object is not a Component * * @param $property Reflection_Property * @return string returned guessed value for @link */ private function guessValue(Reflection_Property $property) { if ($property->getType()->isMultiple()) { /** @var $var_annotation Var_Annotation */ $value = lParse($property->getAnnotation('var'), SP); if (empty($value)) { $value = isA($property->getType()->getElementTypeAsString(), Component::class) ? self::COLLECTION : self::MAP; } } else { $value = isA($property->getType()->asString(), Date_Time::class) ? self::DATETIME : self::OBJECT; } return $value; }
/** * @param $value string * @param $property Reflection_Property ie the contextual Reflection_Property object */ public function __construct($value, Reflection_Property $property) { parent::__construct($value); if (empty($this->value)) { foreach ($property->getFinalClass()->getAnnotations('group') as $group) { /** @var $group Class_\Group_Annotation */ if ($group->has($property->getName())) { $this->value = $property->getName(); break; } } } }
/** * @param $value string * @param $reflection_property Reflection_Property */ public function __construct($value, Reflection_Property $reflection_property) { parent::__construct($value); if (isset($value)) { $type = $reflection_property->getType(); switch ($type->getElementTypeAsString()) { case Type::FLOAT: $function = 'floatval'; break; case Type::INTEGER: $function = 'intval'; break; default: $function = 'strval'; } foreach ($this->values() as $key => $value) { $this->value[$key] = $function($value); } } }
/** * @param $property Reflection_Property * @param $value boolean|integer|float|string|array */ public function beforeObjectBuilderArrayBuildBasicValue(Reflection_Property $property, &$value) { if (isset($value)) { if (is_array($value) && !empty($value)) { if ($property->getAnnotation('link')->value == Link_Annotation::COLLECTION) { $class = new Reflection_Class($property->getType()->getElementTypeAsString()); $properties = $class->accessProperties(); reset($value); if (!is_numeric(key($value))) { $value = arrayFormRevert($value); } foreach ($value as $key => $element) { foreach ($element as $property_name => $property_value) { if (isset($property_value) && isset($properties[$property_name])) { $value[$key][$property_name] = self::propertyToIso($properties[$property_name], $property_value); } } } } } else { $value = self::propertyToIso($property, $value); } } }
/** * Change an ISO value into a locale formatted value, knowing it's property * * @param $property Reflection_Property * @param $value string * @return string */ public function propertyToLocale(Reflection_Property $property, $value = null) { if ($property instanceof Reflection_Property_Value && !isset($value)) { $value = $property->value(); } return is_null($value) && $property->getAnnotation('null')->value ? $value : $this->toLocale($value, $property->getType()); }
/** * @param $property Reflection_Property * @return Reflection_Class */ private function getForeignClass(Reflection_Property $property) { $type = $property->getType(); $foreign_class_name = Builder::className($type->getElementTypeAsString()); if ($property instanceof PHP\Reflection_Property) { $foreign_class = PHP\Reflection_Class::of($foreign_class_name); } else { $reflection_class = new Reflection\Reflection_Class(get_class($property->getDeclaringClass())); $foreign_class = $reflection_class->newInstance($foreign_class_name); } return $foreign_class; }
/** * @param $property Reflection_Property * @return string[] */ private function defaultObject(Reflection_Property $property) { return [$property->getName()]; }
public static function getDefaultPropertyValue(Interfaces\Reflection_Property $property) { return 'default value for ' . $property->getName(); }