Exemple #1
0
 protected function initElement($variable, $json)
 {
     $this->object = new IsUncertainDate($variable);
     $data = new Data();
     $data->set($json);
     Container::setData($data);
 }
Exemple #2
0
 /**
  * Set the basic data as JSON-Array to create the citation/bibliography from.
  *
  * @param string $input JSON array
  * @return \Geissler\CSL\CSL
  */
 public function setInput($input)
 {
     if ($input != '') {
         $data = new Data();
         $data->set($input);
         Container::setData($data);
     }
     return $this;
 }
Exemple #3
0
 protected function initElement($layout, $json, $language = 'en-US')
 {
     $locale = Factory::locale();
     $locale->readFile($language);
     Container::setLocale($locale);
     $data = new Data();
     $data->set($json);
     Container::setData($data);
     $xml = new \SimpleXMLElement($layout);
     $this->object = new Label($xml);
 }
Exemple #4
0
 protected function initElement($layout, $json)
 {
     $data = new Data();
     $data->set($json);
     Container::setData($data);
     $xml = new \SimpleXMLElement($layout);
     $this->object = new Group($xml);
 }
Exemple #5
0
 protected function initElement($variable, $json, $match = 'all')
 {
     $data = new Data();
     $data->set($json);
     Container::setData($data);
     $this->object = new IsNumeric($variable, $match);
 }
Exemple #6
0
 protected function initElement($layout, $json, $citation, $mode = 'citation')
 {
     $data = new Data();
     $data->set($json);
     Container::setData($data);
     $citationItems = new CitationItems();
     $citationItems->set($citation);
     Container::setCitationItem($citationItems);
     Container::getContext()->setName($mode);
     $xml = new \SimpleXMLElement($layout);
     $this->object = new Layout($xml);
     $this->object->setOptions(new Citation(new \SimpleXMLElement('<xml/>')));
 }
Exemple #7
0
 protected function initElement($layout, $json, $context = '<citation><layout></layout></citation>', $language = 'en-US')
 {
     Container::clear();
     $locale = Factory::locale();
     $locale->readFile($language);
     Container::setLocale($locale);
     $data = new Data();
     $data->set($json);
     Container::setData($data);
     if (strpos($context, 'citation') !== false) {
         Container::getContext()->setName('citation');
         Container::setCitation(new Citation(new \SimpleXMLElement($context)));
     } else {
         Container::getContext()->setName('bibliography');
         Container::setBibliography(new Bibliography(new \SimpleXMLElement($context)));
     }
     $xml = new \SimpleXMLElement($layout);
     $this->object = new Names($xml);
 }
Exemple #8
0
 /**
  * Running PHPUnit test
  * @param $text
  * @param $name
  * @return array
  */
 protected function runTestFromFile($text, $name)
 {
     Container::clear();
     preg_match('/MODE [=]+>>(.*)<<[=]+ MODE/s', $text, $match);
     $mode = preg_replace('/\\s\\s+/', '', $match[1]);
     $mode = preg_replace('/\\n/', '', $mode);
     preg_match('/RESULT [=]+>>(.*)<<[=]+ RESULT/s', $text, $match);
     $result = preg_replace('/\\s\\s+/', '', $match[1]);
     $result = preg_replace('/^\\n/', '', $result);
     $result = preg_replace('/\\n$/', '', $result);
     preg_match('/CSL [=]+>>(.*)<<[=]+ CSL/s', $text, $match);
     $csl = preg_replace('/^\\n/', '', $match[1]);
     preg_match('/INPUT [=]+>>(.*)<<[=]+ INPUT/s', $text, $match);
     $json = preg_replace('/\\s\\s+/', '', $match[1]);
     $style = new Style();
     if (strpos($csl, '<') !== false) {
         $style->readXml(new \SimpleXMLElement($csl));
     } else {
         $csl = preg_replace('/\\n/', '', $csl);
         $csl = str_replace('.csl', '', $csl);
         $style->setDir(__DIR__ . $this->style)->readFile($csl);
     }
     $data = new Data();
     $data->set($json);
     Container::setData($data);
     Container::getContext()->setName($mode);
     // Abbreviations
     if (preg_match('/ABBREVIATIONS [=]+>>(.*)<<[=]+ ABBREVIATIONS/s', $text, $match) == 1) {
         $json = preg_replace('/\\s\\s+/', '', $match[1]);
         $abbreviation = new Abbreviation();
         $abbreviation->set($json);
         Container::setAbbreviation($abbreviation);
     }
     // CitationItems items
     if (preg_match('/CITATION-ITEMS[ ]+[=]+>>(.*)<<[=]+[ ]+CITATION-ITEMS/s', $text, $match) == 1) {
         $json = preg_replace('/\\s\\s+/', '', $match[1]);
         $citation = new CitationItems();
         $citation->set($json);
         Container::setCitationItem($citation);
     } elseif (preg_match('/CITATIONS[ ]+[=]+>>(.*)<<[=]+[ ]+CITATIONS/s', $text, $match) == 1) {
         // Citations items
         $json = preg_replace('/\\s\\s+/', '', $match[1]);
         $citation = new Citations();
         $citation->set($json);
         Container::setCitationItem($citation);
     }
     if ($mode == 'citation') {
         return array($result, Container::getCitation()->render(''), $name);
     } elseif ($mode == 'bibliography') {
         return array($result, Container::getBibliography()->render(''), $name);
     } elseif ($mode == 'bibliography-nosort') {
         Container::getBibliography()->setDoNotSort(true);
         return array($result, Container::getBibliography()->render(''), $name);
     } else {
         return array('Missing mode', '', $name);
     }
 }
Exemple #9
0
 /**
  * @covers Geissler\CSL\Rendering\Text::__construct
  * @covers Geissler\CSL\Rendering\Text::render
  * @covers Geissler\CSL\Rendering\Text::hasAccessEmptyVariable
  */
 public function testRenderAndAccessEmpty()
 {
     $layout = '<text variable="title" prefix="(" suffix=")"></text>';
     $data = new Data();
     $data->set('[{}]');
     Container::setData($data);
     $this->initElement($layout);
     $this->assertEquals('', $this->object->render('blue'));
     $this->assertTrue($this->object->hasAccessEmptyVariable());
 }