/** * @since 1.9 * * @param ParserParameterProcessor $parameters * * @return string|null */ public function parse(ParserParameterProcessor $parameters) { $count = 0; $template = ''; $subject = $this->parserData->getSemanticData()->getSubject(); $parametersToArray = $parameters->toArray(); if (isset($parametersToArray['template'])) { $template = $parametersToArray['template'][0]; unset($parametersToArray['template']); } foreach ($parametersToArray as $property => $values) { $last = count($values) - 1; // -1 because the key starts with 0 foreach ($values as $key => $value) { $dataValue = DataValueFactory::getInstance()->newDataValueByText($property, $value, false, $subject); if ($this->parserData->canModifySemanticData()) { $this->parserData->addDataValue($dataValue); } $this->messageFormatter->addFromArray($dataValue->getErrors()); $this->addFieldsToTemplate($template, $dataValue, $property, $value, $last == $key, $count); } } $this->parserData->pushSemanticDataToParserOutput(); $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml(); return array($html, 'noparse' => $template === '', 'isHTML' => false); }
/** * @since 1.9 * * @param ParserParameterProcessor $parameters * * @return string|null */ public function parse(ParserParameterProcessor $parameters) { $this->initRecurringEvents($parameters->toArray()); $this->messageFormatter->addFromArray($this->recurringEvents->getErrors()); foreach ($this->recurringEvents->getDates() as $date_str) { // Override existing parameters array with the returned // pre-processed parameters array from recurring events $parameters->setParameters($this->recurringEvents->getParameters()); // Add the date string as individual property / value parameter $parameters->addParameter($this->recurringEvents->getProperty(), $date_str); // @see SubobjectParserFunction::addDataValuesToSubobject // Each new $parameters set will add an additional subobject // to the instance if ($this->addDataValuesToSubobject($parameters)) { $this->parserData->getSemanticData()->addSubobject($this->subobject); } // Collect errors that occurred during processing $this->messageFormatter->addFromArray($this->subobject->getErrors()); } // Update ParserOutput $this->parserData->pushSemanticDataToParserOutput(); return $this->messageFormatter->addFromArray($this->parserData->getErrors())->getHtml(); }
/** * @dataProvider firstParameterDataProvider */ public function testGetFirst(array $parameters, array $expected) { $instance = new ParserParameterProcessor($parameters); $this->assertEquals($expected['identifier'], $instance->getFirst()); }
private function transformParametersToArray(ParserParameterProcessor $parameters) { if ($this->useFirstElementForPropertyLabel) { $parameters->addParameter($parameters->getFirst(), $this->parserData->getTitle()->getPrefixedText()); } return $parameters->toArray(); }
private function doPrepareParameters(ParserParameterProcessor $parserParameterProcessor) { if ($parserParameterProcessor->hasParameter(self::PARAM_LINKWITH)) { $val = $parserParameterProcessor->getParameterValuesByKey(self::PARAM_LINKWITH); $parserParameterProcessor->addParameter(end($val), $this->parserData->getTitle()->getPrefixedText()); $parserParameterProcessor->removeParameterByKey(self::PARAM_LINKWITH); } if ($this->isEnabledFirstElementAsPropertyLabel) { $parserParameterProcessor->addParameter($parserParameterProcessor->getFirst(), $this->parserData->getTitle()->getPrefixedText()); } $parameters = $parserParameterProcessor->toArray(); // FIXME 3.0 make sorting default by 3.0 // Only sort for a modified sobj otherwise existing ID will change $sort = false; // This ensures that an unordered array is ordered and will produce // the same ID even if elements are placed differently if ($sort) { ksort($parameters); } return $parameters; }