Exemplo n.º 1
0
 /**
  * Check required element
  *
  * @param stdClass     $element object with required element
  * @param ObjectEntity $schema  schema value generated of api specification
  */
 protected function checkRequired($element, $schema)
 {
     $ignore = isset(static::$ignoreRequiredVal[$schema->getObjectName()]) ? static::$ignoreRequiredVal[$schema->getObjectName()] : [];
     foreach (array_diff_key(array_flip($schema->required), (array) $element, array_flip($ignore)) as $key => $value) {
         $this->appendError($key, 'this element is required.');
     }
 }
Exemplo n.º 2
0
 /**
  * Check adapter rules
  *
  * @param ObjectEntity $objectEntity api object entity generated form specs
  * @param array $rules list of rules
  */
 public function checkAdapterRules(ObjectEntity $objectEntity, $rules)
 {
     //check filterable properties
     if (isset($rules[ApiEntityAdapter::RULE_TYPE_FILTERABLE]) && !in_array($objectEntity->getObjectName(), $this->ignoreCheckRules)) {
         $diffProperties = array_diff($rules[ApiEntityAdapter::RULE_TYPE_FILTERABLE], $objectEntity->filterable);
         $this->assertEmpty($diffProperties, sprintf('filterable properties %s in specifications and adapter rules do not match', implode(' , ', $diffProperties)));
     }
     //check alterable properties. Alterable properties can not be createOnly
     if (isset($rules[ApiEntityAdapter::RULE_TYPE_ALTERABLE])) {
         $intersectProp = array_intersect($rules[ApiEntityAdapter::RULE_TYPE_ALTERABLE], $objectEntity->createOnly);
         $this->assertEmpty($intersectProp, sprintf("The property %s is mutually exclusive. should be alterable or create-only. Object %s", implode(' , ', $intersectProp), $objectEntity->getObjectName()));
         //alterable properties can not be readOnly
         $intersectProp = array_intersect($rules[ApiEntityAdapter::RULE_TYPE_ALTERABLE], $objectEntity->readOnly);
         $this->assertEmpty($intersectProp, sprintf("The property %s is mutually exclusive. should be alterable or read-only. Object %s", implode(' , ', $intersectProp), $objectEntity->getObjectName()));
     }
     // check data and specification properties
     if (isset($rules[ApiEntityAdapter::RULE_TYPE_TO_DATA]) && !in_array($objectEntity->getObjectName(), $this->ignoreCheckRules)) {
         $dataRules = $rules[ApiEntityAdapter::RULE_TYPE_TO_DATA];
         if (!empty($rules[ApiEntityAdapter::RULE_TYPE_SETTINGS])) {
             $dataRules = array_merge($dataRules, $rules[ApiEntityAdapter::RULE_TYPE_SETTINGS]);
         }
         $diffProperties = array_diff(array_keys($objectEntity->getProperties()), $dataRules);
         $this->assertEmpty($diffProperties, sprintf('Properties %s in specifications and adapter rules do not match', implode(' , ', $diffProperties)));
     }
 }