Exemplo n.º 1
0
 protected function execute($values, EntityInterface $entity = null)
 {
     if (!is_array($values)) {
         $this->throwError('non_array_value', [], IncidentInterface::CRITICAL);
         return false;
     }
     $sanitized = [];
     $image_rule = new ImageRule('image', $this->getOptions());
     foreach ($values as $index => $val) {
         if (!$image_rule->apply($val)) {
             $this->throwIncidentsAsErrors($image_rule, null, ['path_parts' => [$index]]);
             return false;
         }
         $sanitized[] = $image_rule->getSanitizedValue();
     }
     $this->setSanitizedValue($sanitized);
     return true;
 }
Exemplo n.º 2
0
 /**
  * @dataProvider provideInvalidValues
  */
 public function testRejectionOfInvalidValues($invalid_value, $assert_message = '')
 {
     $rule = new ImageRule('scalar', []);
     $this->assertFalse($rule->apply($invalid_value), $assert_message . ' should be rejected');
     $this->assertNull($rule->getSanitizedValue(), $assert_message . ' should be null for an invalid value');
 }