示例#1
0
 /**
  * {@inheritdoc}
  *
  * @param ProcessorConfig $config
  * @param array           $input
  *
  * @throws \InvalidArgumentException When provided input is not an array
  */
 public function process(ProcessorConfig $config, $input)
 {
     if (!is_array($input)) {
         throw new \InvalidArgumentException('Provided in input must be an array.');
     }
     if (0 === count($input)) {
         return;
     }
     $this->config = $config;
     $valuesGroup = new ValuesGroup(isset($input['logical-case']) ? $input['logical-case'] : ValuesGroup::GROUP_LOGICAL_AND);
     $this->processGroup($input, $valuesGroup, 0, 0);
     $condition = new SearchCondition($config->getFieldSet(), $valuesGroup);
     if ($condition->getValuesGroup()->hasErrors(true)) {
         throw new InvalidSearchConditionException($condition);
     }
     return $condition;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function process(ProcessorConfig $config, $input)
 {
     if (!is_string($input)) {
         throw new UnexpectedTypeException($input, 'string');
     }
     $input = trim($input);
     if (empty($input)) {
         return;
     }
     $document = simplexml_import_dom(XmlUtil::parseXml($input, __DIR__ . '/schema/dic/input/xml-input-1.0.xsd'));
     $this->config = $config;
     $valuesGroup = new ValuesGroup(isset($document['logical']) ? (string) $document['logical'] : ValuesGroup::GROUP_LOGICAL_AND);
     $this->processGroup($document, $valuesGroup, 0, 0);
     $condition = new SearchCondition($config->getFieldSet(), $valuesGroup);
     if ($condition->getValuesGroup()->hasErrors(true)) {
         throw new InvalidSearchConditionException($condition);
     }
     return $condition;
 }
示例#3
0
 /**
  * Process the input and returns the result.
  *
  * @param ProcessorConfig $config
  * @param string          $input
  *
  * @throws InvalidSearchConditionException
  *
  * @return null|SearchCondition Returns null on empty input
  */
 public function process(ProcessorConfig $config, $input)
 {
     if (!is_string($input)) {
         throw new UnexpectedTypeException($input, 'string');
     }
     $input = trim($input);
     if ('' === $input) {
         return;
     }
     $condition = new SearchCondition($config->getFieldSet(), $this->parse($config, $input));
     if ($condition->getValuesGroup()->hasErrors(true)) {
         throw new InvalidSearchConditionException($condition);
     }
     return $condition;
 }
示例#4
0
 /**
  * Checks if the maximum group count is exceeded.
  *
  * @param int $groupIdx
  * @param int $count
  * @param int $nestingLevel
  *
  * @throws GroupsOverflowException
  */
 protected function validateGroupsCount($groupIdx, $count, $nestingLevel)
 {
     if ($count > $this->config->getMaxGroups()) {
         throw new GroupsOverflowException($this->config->getMaxGroups(), $count, $groupIdx, $nestingLevel);
     }
 }