/** * Reads in a ePub file and builds the Package definition * * @param string $file * * @return \ePub\Definition\Package */ public function load($file) { $resource = new ZipFileResource($file); $package = $resource->getXML('META-INF/container.xml'); if (!($opfFile = (string) $package->rootfiles->rootfile['full-path'])) { $ns = $package->getNamespaces(); foreach ($ns as $key => $value) { $package->registerXPathNamespace($key, $value); $items = $package->xpath('//' . $key . ':rootfile/@full-path'); $opfFile = (string) $items[0]['full-path']; } } $data = $resource->get($opfFile); // all files referenced in the OPF are relative to it's directory if ('.' !== ($dir = dirname($opfFile))) { $resource->setDirectory($dir); } $opfResource = new OpfResource($data, $resource); $package = $opfResource->bind(); $package->opfDirectory = dirname($opfFile); if ($package->navigation->src->href) { $ncx = $resource->get($package->navigation->src->href); $ncxResource = new NcxResource($ncx); $package = $ncxResource->bind($package); } return $package; }
public function close() { if ($this->resource) { $this->resource->close(); } }