Skip to content

Commit 5e0118f

Browse files
committed
Fix include paths resolution
- Fix inclusions in archive stub - Use realpath when adding files
1 parent 582308f commit 5e0118f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Command/Compile.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ protected function addDirectory(string $directory, string $extensions = null)
9797
* Add a single file to the archive builder
9898
*
9999
* @param string $file
100+
*
100101
*/
101102
protected function addFile(string $file)
102103
{
104+
$fullpath = $this->fullpath($file);
105+
103106
$this->info('+ ' . $file, 'grey');
104-
$this->builder->addFile($file);
107+
$this->builder->addFile($fullpath, $file);
105108
}
106109

107110
/**
@@ -162,6 +165,23 @@ protected function publish(string $output, string $compression = 'GZ'): self
162165
return $this;
163166
}
164167

168+
/**
169+
* Get the full path to the file from the current working dir
170+
*
171+
* @param string $file
172+
*
173+
* @return string
174+
*/
175+
protected function fullpath(string $file): string
176+
{
177+
// If it's an absolute path, let it unchanged
178+
if (realpath($file) === $file) {
179+
return $file;
180+
}
181+
182+
return getcwd() . '/' . $file;
183+
}
184+
165185
/**
166186
* Return the contents wrapped in a comments block
167187
*

src/PharBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static function create(string $main): self
7474
* Visibility is defined private to force using the factory method
7575
*
7676
* @param string $main Path to the main entrypoint script
77+
*
7778
*/
7879
private function __construct(string $main)
7980
{
@@ -169,7 +170,7 @@ protected function stub(string $main, string $banner = null): string
169170
// while still allowing the use of absolute path based requires
170171
// @see https://bugs.php.net/bug.php?id=63028
171172
$lines[] = sprintf('set_include_path("phar://%s/");', $this->pharname);
172-
$lines[] = sprintf('require "phar://%s/%s"; __HALT_COMPILER();', $this->pharname, $main);
173+
$lines[] = sprintf('require "%s"; __HALT_COMPILER();', $main);
173174

174175
return implode(self::EOL, $lines);
175176
}

0 commit comments

Comments
 (0)