예제 #1
0
 protected function execute($values, EntityInterface $entity = null)
 {
     if (!is_array($values)) {
         $this->throwError('non_array_value', [], IncidentInterface::CRITICAL);
         return false;
     }
     $sanitized = [];
     $asset_rule = new AssetRule('asset', $this->getOptions());
     foreach ($values as $index => $val) {
         if (!$asset_rule->apply($val)) {
             $this->throwIncidentsAsErrors($asset_rule, null, ['path_parts' => [$index]]);
             return false;
         }
         $sanitized[] = $asset_rule->getSanitizedValue();
     }
     $this->setSanitizedValue($sanitized);
     return true;
 }
예제 #2
0
 /**
  * @dataProvider provideInvalidValues
  */
 public function testRejectionOfInvalidValues($invalid_value, $assert_message = '')
 {
     $rule = new AssetRule('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');
 }