Skip to content

Commit

Permalink
Fix seboettg#193 Call to a member function render() on null
Browse files Browse the repository at this point in the history
  • Loading branch information
trackleft committed Jul 5, 2024
1 parent 0a5cce7 commit 9fccf0b
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit 9fccf0b

Please sign in to comment.