/** * {@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; }
/** * {@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; }
/** * 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; }