/** * Create a new Mobi document from data provided * * @throws \Exception */ public function process() { $result = $this->validate(); if (count($result) > 0) { throw new \Exception("Invalid Phindle setup. Additional configuration options required. " . implode('. ', $result)); } $this->generateUniqueId(); $this->sortContent(); //Get the first content item $this->setAttribute('start', reset($this->content)->getAnchorPath()); //If a default instance of TableOfContents provided by this package was used then we need to tell //the TableOfContents instance about the contents of the Phindle file. It is not required that you use //TableOfContents, as long as you implement the ContentsInterface and so in these cases the generate //method may not exist. if ($this->toc instanceof TableOfContents) { $this->toc->generate($this->content); } //We will add the table of contents as a "normal" content element as well because it will implement getHtml //and so we can write it out as a temporary static file as needed $this->addContent($this->toc); $this->sortContent(); $this->setAttribute('toc', $this->toc->getAnchorPath()); //Now we need to generate and write out the static html files for kindlegen to process foreach ($this->content as $content) { $html = $content->getHtml(); //If ingredients are provided then we'll try to automatically set relative static resource paths in html files if ($this->htmlHelper && $this->attributeExists('staticResourcePath')) { $html = $this->htmlHelper->appendRelativeResourcePaths($html); } /** @var \Develpr\Phindle\ContentInterface $content */ $this->fileHandler->writeTempFile($content->getUniqueIdentifier() . '.html', $html); } $this->fileHandler->writeTempFile($this->getAttribute('uniqueId') . '.opf', $this->opfRenderer->render($this->attributes, $this->content, $this->toc)); $this->fileHandler->writeTempFile($this->getAttribute('uniqueId') . '.ncx', $this->ncxRenderer->render($this->attributes, $this->content)); $this->generateMobi(); //Remove all temporary files $this->fileHandler->clean(); return true; }