コード例 #1
0
 /**
  * process
  *
  * @param mixed   $data
  * @param Options $options
  *
  * @return ProcessorResult
  * @throws \Exception
  */
 public function process($data, Options $options)
 {
     $name = $options->get('name', 'default');
     $processors = $options->get('processors', []);
     if (empty($processors)) {
         throw new \Exception('Processors not found in options');
     }
     $results = new ProcessorResult($name, $data, $this, true);
     foreach ($processors as $key => $processorOptionsArray) {
         $processorOptions = $options->createOptions($processorOptionsArray);
         $processorServiceName = $processorOptions->get('processor', null);
         if ($processorServiceName === null) {
             throw new \Exception('Processor not found in options');
         }
         /** @var Processor $processor */
         $processor = $this->getProcessor($processorServiceName);
         // over-ride name
         $processorOptions->set('name', $name);
         $result = $processor->process($data, $processorOptions);
         $data = $result->getValue();
         if (!$result->isValid()) {
             $results->setValid(false);
             //                    self::DEFAULT_CODE,
             //                    $options,
             //                    self::DEFAULT_MESSAGE
             //                );
             foreach ($result->getMessages() as $code => $message) {
                 $results->setMessage($code, $message);
             }
         }
     }
     $results->setValue($data);
     return $results;
 }
コード例 #2
0
 /**
  * process
  *
  * @param mixed   $data
  * @param Options $options
  *
  * @return ProcessorResult
  * @throws \Exception
  */
 public function process($data, Options $options)
 {
     $name = $options->get('name', 'default');
     $fieldOptions = $options->getOptions('dataSet');
     $context = $data;
     $results = new ProcessorResult($name, $data, $this, true);
     /** @var Processor $processor */
     foreach ($data as $fieldName => $value) {
         $fieldOption = $fieldOptions->getOptions($fieldName);
         $fieldOption->set('context', $context);
         $fieldOption->set('name', $fieldName);
         $processorName = $fieldOption->get('processor', null);
         if ($processorName === null) {
             throw new \Exception('Processor not found in options');
         }
         $processor = $this->getProcessor($processorName);
         $result = $processor->process($value, $fieldOption);
         $data[$fieldName] = $result->getValue();
         if (!$result->isValid()) {
             $results->setError(self::DEFAULT_CODE, $options, self::DEFAULT_MESSAGE);
             $results->addResult($result);
         }
     }
     $results->setValue($data);
     return $results;
 }
コード例 #3
0
ファイル: Adapter.php プロジェクト: jerv13/input-filter
 /**
  * process Filter and/or Validate
  *
  * @param mixed $data
  * @param Options $options
  *
  * @return Result
  */
 public function process($data, Options $options)
 {
     $name = $options->get('name', 'default');
     $filterClass = $options->get('zendFilter');
     $filterOptions = $options->get('zendFilterOptions', []);
     /** @var \Zend\Filter\AbstractFilter $filter */
     $filter = new $filterClass();
     $filter->setOptions($filterOptions);
     $filteredData = $filter->filter($data);
     $result = new ProcessorResult($name, $data, $this, true);
     $result->setSuccess($filteredData);
     return $result;
 }
コード例 #4
0
ファイル: Adapter.php プロジェクト: jerv13/input-filter
 /**
  * process Validator and/or Validate
  *
  * @param mixed   $data
  * @param Options $options
  *
  * @return Result
  */
 public function process($data, Options $options)
 {
     $name = $options->get('name', 'default');
     $validatorClass = $options->get('zendValidator');
     $validatorOptions = $options->get('zendValidatorOptions', []);
     $context = $options->get('context', []);
     /** @var \Zend\Validator\AbstractValidator $validator */
     $validator = new $validatorClass($validatorOptions);
     $isValid = $validator->isValid($data, $context);
     $messages = $validator->getMessages();
     $result = new ProcessorResult($name, $data, $this, true);
     $result->setSuccess($data);
     foreach ($messages as $code => $message) {
         $result->setError($code, $options, $message);
     }
     return $result;
 }