/**
  * @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 ArrayFormatter $parameters
  *
  * @return string|null
  */
 public function parse(ArrayFormatter $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) {
         foreach ($values as $value) {
             $dataValue = DataValueFactory::getInstance()->newPropertyValue($property, $value, false, $subject);
             $this->parserData->addDataValue($dataValue);
             $this->messageFormatter->addFromArray($dataValue->getErrors());
             $this->addFieldsToTemplate($template, $dataValue, $property, $value, $count);
         }
     }
     $this->parserData->pushSemanticDataToParserOutput();
     $html = $this->templateRenderer->render() . $this->messageFormatter->addFromArray($parameters->getErrors())->getHtml();
     return array($html, 'noparse' => true, 'isHTML' => true);
 }
 /**
  * Adds property values to the ParserOutput instance
  *
  * @since 1.9
  *
  * @param array $properties
  *
  * @return string
  */
 protected function addPropertyValue(array $properties, $value, $valueCaption)
 {
     $subject = $this->parserData->getSemanticData()->getSubject();
     // Add properties to the semantic container
     foreach ($properties as $property) {
         $dataValue = $this->dataValueFactory->newPropertyValue($property, $value, $valueCaption, $subject);
         if ($this->isEnabledNamespace && $this->isAnnotation) {
             $this->parserData->addDataValue($dataValue);
         }
     }
     // Return the text representation
     $result = $dataValue->getShortWikitext(true);
     // If necessary add an error text
     if ($this->settings->get('smwgInlineErrors') && $this->isEnabledNamespace && $this->isAnnotation && !$dataValue->isValid()) {
         $result .= $dataValue->getErrorText();
     }
     return $result;
 }
 /**
  * Adds property values to the ParserOutput instance
  *
  * @since 1.9
  *
  * @param array $properties
  *
  * @return string
  */
 protected function addPropertyValue(array $properties, $value, $valueCaption)
 {
     $subject = $this->parserData->getSubject();
     // Add properties to the semantic container
     foreach ($properties as $property) {
         $dataValue = $this->dataValueFactory->newPropertyValue($property, $value, $valueCaption, $subject);
         if ($this->isEnabledNamespace && $this->isAnnotation) {
             $this->parserData->addDataValue($dataValue);
         }
     }
     // Return the text representation
     $result = $dataValue->getShortWikitext(true);
     // If necessary add an error text
     if ($this->settings->get('smwgInlineErrors') && $this->isEnabledNamespace && $this->isAnnotation && !$dataValue->isValid()) {
         // Encode `:` to avoid a comment block and instead of the nowiki tag
         // use : as placeholder
         $result = str_replace(':', ':', $result) . $dataValue->getErrorText();
     }
     return $result;
 }
 public function testImportFromParserOutput()
 {
     $import = new ParserData(Title::newFromText(__METHOD__), new ParserOutput());
     $import->addDataValue($this->dataValueFactory->newDataValueByText('Foo', 'Bar'));
     $import->pushSemanticDataToParserOutput();
     $instance = new ParserData(Title::newFromText(__METHOD__), new ParserOutput());
     $instance->importFromParserOutput(null);
     $this->assertNotEquals($import->getSemanticData()->getHash(), $instance->getSemanticData()->getHash());
     $instance->importFromParserOutput($import->getOutput());
     $this->assertEquals($import->getSemanticData()->getHash(), $instance->getSemanticData()->getHash());
 }
示例#6
0
 public function testSemanticDataStateToParserOutput()
 {
     $parserOutput = new ParserOutput();
     $instance = new ParserData(Title::newFromText(__METHOD__), $parserOutput);
     $this->assertEmpty($parserOutput->getProperty('smw-semanticdata-status'));
     $instance->addDataValue($this->dataValueFactory->newPropertyValue('Foo', 'Bar'));
     $instance->setSemanticDataStateToParserOutputProperty();
     $this->assertTrue($parserOutput->getProperty('smw-semanticdata-status'));
 }
 private function addDataValue($property, $value)
 {
     $dataValue = DataValueFactory::getInstance()->newDataValueByText($property, $value, false, $this->subject);
     $this->parserData->addDataValue($dataValue);
 }