コード例 #1
0
ファイル: ZipFileLoader.php プロジェクト: jonhargett/epub
 /**
  * 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;
 }
コード例 #2
0
ファイル: OpfResourceTest.php プロジェクト: jonhargett/epub
 public function testLoadingValidOpenPackagingFormatFile()
 {
     $fixture = $this->getFixture('basic/OEPS/content.opf');
     $opf = new OpfResource($fixture);
     $package = $opf->bind();
     $metadata = $package->getMetadata();
     $this->assertTrue($metadata instanceof Metadata);
     $this->assertTrue($metadata->has('title'));
     $this->assertEquals('Epub Format Construction Guide', $metadata->getValue('title'));
     $manifest = $package->getManifest();
     $this->assertTrue($manifest instanceof Manifest);
     $this->assertEquals(array("ncx", "css", "logo", "title", "contents", "intro", "part1", "part2", "part3", "part4", "specs"), $manifest->keys());
 }