Exemplo n.º 1
0
 /**
  * Return 'yes' or 'no' depending on the value of the boolean
  * If the property has a @values annotation : the first value is for 'no', the second for 'yes'
  *
  * @param $value
  * @return string
  */
 protected function formatBoolean($value)
 {
     $values = $this->property->getListAnnotation('values')->values();
     if (count($values) == 2) {
         return $value ? $values[0] : $values[1];
     }
     return is_null($value) && $this->property->getAnnotation('null')->value ? null : ($value ? 'yes' : 'no');
 }
Exemplo n.º 2
0
 /**
  * Get current environment name possible values
  *
  * @return mixed[]
  */
 public function values()
 {
     $type = $this->property->getType();
     if ($type->isClass()) {
         return Dao::readAll($this->property->getType()->asString(), [Dao::sort()]);
     } elseif ($values = $this->property->getListAnnotation('values')->values()) {
         return array_combine($values, $values);
     } else {
         trigger_error("Unable to get {$this->property->name} environment values from type " . $type->asString(), E_USER_ERROR);
         return null;
     }
 }
Exemplo n.º 3
0
 /**
  * @param $multiline boolean keep this value empty, it is not used because the @multiline
  *        annotation is automatically used
  * @param $values    string[] keep this value empty, it is not used because the @values annotation
  *        is automatically used
  * @return Element
  */
 protected function buildString($multiline = false, $values = null)
 {
     $values_captions = [];
     $values = $this->property->getListAnnotation('values')->values();
     foreach ($values as $value) {
         $values_captions[$value] = Names::propertyToDisplay($value);
     }
     if ($values_captions && !in_array($this->value, $values_captions)) {
         $values_captions[$this->value] = $this->value;
     }
     $element = parent::buildString($this->property->getAnnotation('multiline')->value, $values_captions);
     if ($this->property->getAnnotation('mandatory')->value) {
         $element->setAttribute('required', true);
     }
     if ($this->property->getAnnotation('password')->value) {
         $element->setAttribute('type', 'password');
         $element->setAttribute('value', strlen($this->value) ? Password::UNCHANGED : '');
     }
     return $element;
 }
Exemplo n.º 4
0
 /**
  * Gets mysql expression for a property type
  *
  * @param $property Reflection_Property
  * @return string
  */
 private static function propertyTypeToMysql(Reflection_Property $property)
 {
     $property_type = $property->getType();
     if ($property_type->isBasic() || $property->getAnnotation('store')->value == 'string') {
         if ($property_type->hasSize()) {
             /** @var integer $max_length */
             $max_length = $property->getAnnotation('max_length')->value;
             $max_value = $property->getAnnotation('max_value')->value;
             $min_value = $property->getAnnotation('min_value')->value;
             $precision = $property->getAnnotation('precision')->value;
             $signed = $property->getAnnotation('signed')->value;
             $signed_length = $max_length + ($signed ? 1 : 0);
             if (!isset($max_length)) {
                 if ($property_type->isNumeric()) {
                     $max_length = 18;
                     $signed_length = 18;
                 } else {
                     $max_length = 255;
                 }
             }
             if ($property_type->isInteger()) {
                 if (!isset($signed) && $max_value < 0 || $min_value < 0) {
                     $signed = true;
                 }
                 return $max_length <= 3 && $min_value >= -128 && $max_value <= 127 && $signed ? 'tinyint(' . $signed_length . ')' : ($max_length <= 3 && $min_value >= 0 && $max_value <= 255 && !$signed ? 'tinyint(' . $max_length . ') unsigned' : ($max_length <= 5 && $min_value >= -32768 && $max_value <= 32767 ? 'smallint(' . $signed_length . ')' : ($max_length <= 5 && $min_value >= 0 && $max_value <= 65535 ? 'smallint(' . $max_length . ') unsigned' : ($max_length <= 7 && $min_value >= -8388608 && $max_value <= 8388607 ? 'mediumint(' . $signed_length . ')' : ($max_length <= 8 && $min_value >= 0 && $max_value <= 16777215 ? 'mediumint(' . $max_length . ') unsigned' : ($max_length <= 10 && $min_value >= -2147483648.0 && $max_value <= 2147483647 ? 'int(' . $signed_length . ')' : ($max_length <= 10 && $min_value >= 0 && $max_value <= 4294967295.0 ? 'int(' . $max_length . ') unsigned' : ($max_length <= 19 && $min_value >= -9.223372036854776E+18 && $max_value <= 9.223372036854776E+18 ? 'bigint(' . $signed_length . ')' : 'bigint(' . $max_length . ') unsigned'))))))));
             } elseif ($property_type->isFloat()) {
                 return $precision ? 'decimal(' . $signed_length . ', ' . $precision . ')' : 'double';
             } elseif ($property->getAnnotation('binary')->value) {
                 return $max_length <= 65535 ? 'blob' : ($max_length <= 16777215 ? 'mediumblob' : 'longblob');
             } else {
                 return $max_length <= 3 ? 'char(' . $max_length . ')' : ($max_length <= 255 ? 'varchar(' . $max_length . ')' : ($max_length <= 65535 ? 'text' : ($max_length <= 16777215 ? 'mediumtext' : 'longtext'))) . ' CHARACTER SET utf8 COLLATE utf8_general_ci';
             }
         }
         switch ($property_type->asString()) {
             case Type::_ARRAY:
                 return null;
             case Type::BOOLEAN:
                 return 'tinyint(1)';
             case Type::_CALLABLE:
                 return null;
             case Type::null:
             case Type::NULL:
                 return null;
             case Type::RESOURCE:
                 return null;
             case DateTime::class:
             case Date_Time::class:
                 return 'datetime';
             default:
                 return 'char(255)';
         }
     } elseif ($property_type->asString() === Type::STRING_ARRAY) {
         /** @var $values string[] */
         $values = [];
         foreach ($property->getListAnnotation('values')->values() as $key => $value) {
             $values[$key] = str_replace(Q, Q . Q, $value);
         }
         return $values ? ($property->getAnnotation('set')->value ? 'set' : 'enum') . "('" . join("','", $values) . "')" : 'text';
     } else {
         return 'bigint(18) unsigned';
     }
 }
Exemplo n.º 5
0
 /**
  * @param $property Reflection_Property
  * @return array[]
  */
 private function getPropertyBlocks(Reflection_Property $property)
 {
     $blocks = [];
     if ($property->getListAnnotation('integrated')->has('block')) {
         $blocks[$property->path] = $property->path;
     }
     foreach ($property->getListAnnotation('block')->values() as $block) {
         $blocks[$block] = $block;
     }
     return $blocks;
 }