示例#1
0
 /**
  * @param $value    string
  * @param $property Reflection_Property
  */
 public function __construct($value, Reflection_Property $property)
 {
     if (!$value) {
         $value = $property->getName();
     }
     parent::__construct($value);
 }
示例#2
0
 /**
  * @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;
     }
 }
示例#3
0
 /**
  * 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;
 }
示例#4
0
 /**
  * @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;
             }
         }
     }
 }
示例#5
0
 /**
  * @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);
         }
     }
 }
示例#6
0
文件: Loc.php 项目: TuxBoy/Demo-saf
 /**
  * @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);
         }
     }
 }
示例#7
0
 /**
  * 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());
 }
示例#8
0
 /**
  * @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()];
 }
示例#10
0
文件: Tests.php 项目: TuxBoy/Demo-saf
 public static function getDefaultPropertyValue(Interfaces\Reflection_Property $property)
 {
     return 'default value for ' . $property->getName();
 }