Since: 5.11 (03.12.2015)
Author: Andrii Penchuk (a.penchuk@scalr.com)
Inheritance: extends AbstractSpecObject
Ejemplo n.º 1
0
 /**
  * Check property form spec object
  *
  * @param mixed    $element property value
  * @param Property $schema  property schema generated of api specification
  */
 protected function checkProperty($element, Property $schema)
 {
     $propertyName = $schema->getObjectName();
     //TODO:ape: check element don't empty because pagination type is string AND default is NULL
     if (!empty($element)) {
         switch ($schema->type) {
             case 'string':
                 $error = !is_string($element);
                 break;
             case 'integer':
                 $error = !is_numeric($element);
                 break;
             case 'boolean':
                 $error = !(is_bool($element) || 1 == $element || 0 == $element);
                 break;
             case 'array':
                 $error = !is_array($element);
                 break;
             default:
                 $error = false;
         }
         if ($error) {
             $this->appendError($propertyName, sprintf('This type is\'t not consistency with Api. Type should be %s.', $schema->type));
         }
     }
     if (isset($schema->enum)) {
         if ($schema->getObjectName() == 'builtinAutomation' && empty(static::$ignoreEnumVal['builtinAutomation'])) {
             static::$ignoreEnumVal['builtinAutomation'] = array_merge([null], array_flip(ROLE_BEHAVIORS::GetName(null, true)));
         }
         $enumVal = $schema->enum;
         if (isset(static::$ignoreEnumVal[$propertyName])) {
             $enumVal = array_merge($enumVal, static::$ignoreEnumVal[$propertyName]);
         }
         // check enum properties
         if (!in_array($element, $enumVal)) {
             $this->appendError($propertyName, sprintf('[%s] is not valid allowed value %s %s.', $element, ...count($schema->enum) === 1 ? ['is', array_shift($schema->enum)] : ['are', implode(', ', $schema->enum)]));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Check property form spec object
  *
  * @param mixed    $element property value
  * @param Property $schema  property schema generated of api specification
  */
 protected function checkProperty($element, Property $schema)
 {
     //TODO:ape: check element don't empty because pagination type is string AND default is NULL
     if (!empty($element)) {
         switch ($schema->type) {
             case 'string':
                 $error = !is_string($element);
                 break;
             case 'integer':
                 $error = !is_numeric($element);
                 break;
             case 'boolean':
                 $error = !(is_bool($element) || 1 == $element || 0 == $element);
                 break;
             case 'array':
                 $error = !is_array($element);
                 break;
             default:
                 $error = false;
         }
         if ($error) {
             $this->appendError($schema->getObjectName(), sprintf('This type is\'t not consistency with Api. Type should be %s.', $schema->type));
         }
     }
     // check enum properties
     if (isset($schema->enum) && !in_array($element, $schema->enum) && !in_array($element, static::$ignoreEnumVal)) {
         $this->appendError($schema->getObjectName(), sprintf('[%s] is not valid allowed value %s %s.', $element, ...count($schema->enum) === 1 ? ['is', array_shift($schema->enum)] : ['are', implode(', ', $schema->enum)]));
     }
 }