Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/CiteProc.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,35 @@ private function parse(SimpleXMLElement $style)
/**
* @param DataList $data
* @return string
* @throws CiteProcException
*/
protected function bibliography($data)
{

return self::$context->getBibliography()->render($data);
$bibliography = self::$context->getBibliography();
if ($bibliography === null) {
throw new CiteProcException('Bibliography is not set in context.');
}
return $bibliography->render($data);
}

/**
* @param DataList $data
* @param ArrayList $citationItems
* @return string
* @throws CiteProcException
*/
protected function citation($data, $citationItems)
{
return self::$context->getCitation()->render($data, $citationItems);
$citation = self::$context->getCitation();
if ($citation === null) {
throw new CiteProcException('Citation is not set in context.');
}
return $citation->render($data, $citationItems);
}

/**
* Renders the bibliography or citation based on the provided mode.
*
* @param array|DataList $data
* @param string $mode (citation|bibliography)
* @param array $citationItems
Expand Down Expand Up @@ -199,7 +210,8 @@ public function render($data, $mode = "bibliography", $citationItems = [], $cita
}

/**
* initializes CiteProc and start parsing XML stylesheet
* Initializes CiteProc and starts parsing the XML stylesheet.
*
* @param bool $citationAsArray
* @throws CiteProcException
*/
Expand All @@ -212,6 +224,10 @@ public function init($citationAsArray = false)
self::$context->setMarkupExtension($this->markupExtension);
$this->styleSheetXml = new SimpleXMLElement($this->styleSheet);
$this->parse($this->styleSheetXml);

if (self::$context->getBibliography() === null) {
throw new CiteProcException('Bibliography was not initialized correctly.');
}
}

/**
Expand Down