Skip to content

Commit a4ac96c

Browse files
committed
get full paths
1 parent 8d89b50 commit a4ac96c

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "espresso-tutorials/php-epub",
33
"type": "library",
44
"license": "ISC",
5-
"version": "0.1.0",
5+
"version": "0.2.0",
66
"autoload": {
77
"psr-4": {
88
"EspressoTutorials\\Epub\\": "src/"

src/Container.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
class Container
88
{
9+
protected SimpleXMLElement $element;
10+
911
protected ?RootFile $rootFile = null;
1012

1113
public function __construct(
12-
protected SimpleXMLElement $element,
14+
protected string $file,
1315
) {
16+
$this->element = SimpleXMLElement::fromPath($this->file);
1417
}
1518

1619
public function rootFile(): RootFile
@@ -20,7 +23,7 @@ public function rootFile(): RootFile
2023
}
2124

2225
return $this->rootFile = new RootFile(
23-
(string) $this->element->rootfiles->rootfile->attributes()['full-path']
26+
dirname($this->file, 2) . '/' . (string) $this->element->rootfiles->rootfile->attributes()['full-path'],
2427
);
2528
}
2629
}

src/Content.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
class Content
99
{
10+
protected SimpleXMLElement $element;
11+
1012
protected array $manifest = [];
1113

1214
protected array $spine = [];
1315

1416
public function __construct(
15-
protected SimpleXMLElement $element
17+
protected string $file
1618
) {
19+
$this->element = SimpleXMLElement::fromPath($this->file);
1720
}
1821

1922
public function manifest(): array
@@ -25,7 +28,7 @@ public function manifest(): array
2528
foreach ($this->element->manifest->item as $node) {
2629
$this->manifest[] = new Item(
2730
(string) $node->attributes()['id'],
28-
(string) $node->attributes()['href'],
31+
dirname($this->file) . '/' . $node->attributes()['href'],
2932
(string) $node->attributes()['media-type'],
3033
);
3134
}

src/Epub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function container(): Container
2424
}
2525

2626
return $this->container = new Container(
27-
SimpleXMLElement::fromPath($this->extractionPath . '/META-INF/container.xml')
27+
$this->extractionPath . '/META-INF/container.xml',
2828
);
2929
}
3030

@@ -35,7 +35,7 @@ public function content(): Content
3535
}
3636

3737
return $this->content = new Content(
38-
SimpleXMLElement::fromPath($this->extractionPath . '/' . $this->container()->rootFile()->path())
38+
$this->container()->rootFile()->path()
3939
);
4040
}
4141

0 commit comments

Comments
 (0)