/** * @covers Geissler\CSL\Context\Options::set */ public function testSet() { $layout = '<citation delimiter-precedes-last="always"> </citation>'; $this->assertInstanceOf('\\Geissler\\CSL\\Context\\Options', $this->object->set('style', new \SimpleXMLElement($layout))); $this->assertEquals('always', Container::getContext()->getValue('delimiterPrecedesLast')); }
/** * Parses the style configuration from the SimpleXMLElement object. * * @param \SimpleXMLElement $xml * @return \Geissler\CSL\Style\Style */ public function readXml(\SimpleXMLElement $xml) { // store "global" configuration options in the context object Container::getContext()->addStyle('initializeWithHyphen', true); Container::getContext()->addStyle('demoteNonDroppingParticle', 'display-and-sort'); foreach ($xml->attributes() as $name => $value) { switch ($name) { case 'class': Container::getContext()->addStyle('class', (string) $value); break; case 'default-locale': $locale = Factory::locale(); $locale->readFile((string) $value); Container::setLocale($locale); break; } } // set global options and inheritable name options $options = new Options(); $options->set('style', $xml); foreach ($xml->children() as $child) { switch ($child->getName()) { case 'citation': Container::setCitation(new Citation($child)); break; case 'bibliography': Container::setBibliography(new Bibliography($child)); break; case 'macro': $macroName = ''; foreach ($child->attributes() as $name => $value) { if ($name == 'name') { $macroName = (string) $value; break; } } if ($macroName !== '') { Container::addMacro($macroName, new Macro($child)); } break; case 'locale': Container::getLocale()->addXml($child); break; } } return $this; }
/** * Parses the CitationItems configuration. * * @param \SimpleXMLElement $xml * @throws \ErrorException If layout is missing */ public function __construct(\SimpleXMLElement $xml) { // init child elements foreach ($xml->children() as $child) { switch ($child->getName()) { case 'layout': $this->layout = new Layout($child); break; case 'sort': $this->sort = new Sort($child); break; } } if (isset($this->layout) == false) { throw new \ErrorException('Missing layout!'); } // citation options $this->layout->setOptions(new CitationOptions($xml)); // set global options and inheritable name options $options = new Options(); $options->set('citation', $xml); }