mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Optimized phar:build
, which can support symlink
package. (#3455)
Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
8e398a6983
commit
f1a0f3d00f
8
.github/workflows/test-components.yml
vendored
8
.github/workflows/test-components.yml
vendored
@ -4,8 +4,12 @@ on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
phar:
|
||||
name: Test for Phar
|
||||
name: Test for Building PHAR ${{ matrix.no-dev }}
|
||||
runs-on: 'ubuntu-latest'
|
||||
strategy:
|
||||
matrix:
|
||||
no-dev: [ '', '--no-dev' ]
|
||||
max-parallel: 2
|
||||
env:
|
||||
SW_VERSION: '4.6.4'
|
||||
steps:
|
||||
@ -25,7 +29,7 @@ jobs:
|
||||
run: |
|
||||
git clone https://github.com/limingxinleo/hyperf-phar-tester.git --depth 1
|
||||
cd hyperf-phar-tester
|
||||
composer update -o --no-dev
|
||||
composer update -o ${{ matrix.no-dev }}
|
||||
rm -rf vendor/hyperf/phar
|
||||
cp -rf ../src/phar vendor/hyperf/phar
|
||||
composer dump-autoload -o
|
||||
|
@ -10,6 +10,7 @@
|
||||
## Optimized
|
||||
|
||||
- [#3453](https://github.com/hyperf/hyperf/pull/3453) Optimized code for releasing instance in `Hyperf\Utils\Channel\Caller`.
|
||||
- [#3455](https://github.com/hyperf/hyperf/pull/3455) Optimized `phar:build`, which can support `symlink` package.
|
||||
|
||||
# v2.1.12 - 2021-03-29
|
||||
|
||||
|
@ -177,18 +177,37 @@ class PharBuilder
|
||||
}
|
||||
// Package all of these dependent components into the packages
|
||||
foreach ($installedPackages as $package) {
|
||||
$dir = $package['name'] . '/';
|
||||
// support custom install path
|
||||
$dir = 'composer/' . $package['install-path'] . '/';
|
||||
if (isset($package['target-dir'])) {
|
||||
$dir .= trim($package['target-dir'], '/') . '/';
|
||||
}
|
||||
|
||||
$dir = $vendorPath . $dir;
|
||||
$packages[] = new Package($package, $dir);
|
||||
$packages[] = new Package($package, $this->canonicalize($dir));
|
||||
}
|
||||
}
|
||||
return $packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the canonicalize path, like realpath.
|
||||
* @param mixed $address
|
||||
*/
|
||||
public function canonicalize($address)
|
||||
{
|
||||
$address = explode('/', $address);
|
||||
$keys = array_keys($address, '..');
|
||||
|
||||
foreach ($keys as $keypos => $key) {
|
||||
array_splice($address, $key - ($keypos * 2 + 1), 2);
|
||||
}
|
||||
|
||||
$address = implode('/', $address);
|
||||
return str_replace('./', '', $address);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the relative path relative to the resource bundle.
|
||||
*/
|
||||
@ -198,7 +217,8 @@ class PharBuilder
|
||||
if (strpos($path, $root) !== 0) {
|
||||
throw new UnexpectedValueException('Path "' . $path . '" is not within base project path "' . $root . '"');
|
||||
}
|
||||
return substr($path, strlen($root)) ?? null;
|
||||
$basePath = substr($path, strlen($root));
|
||||
return empty($basePath) ? null : $this->canonicalize($basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,7 +321,17 @@ EOD;
|
||||
// Add composer depenedencies.
|
||||
foreach ($this->getPackagesDependencies() as $package) {
|
||||
$this->logger->info('Adding dependency "' . $package->getName() . '" from "' . $this->getPathLocalToBase($package->getDirectory()) . '"');
|
||||
$targetPhar->addBundle($package->bundle());
|
||||
// support package symlink
|
||||
if (is_link(rtrim($package->getDirectory(), '/'))) {
|
||||
$bundle = $package->bundle();
|
||||
foreach ($bundle as $resource) {
|
||||
foreach ($resource as $iterator) {
|
||||
$targetPhar->addFile($iterator->getPathname());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$targetPhar->addBundle($package->bundle());
|
||||
}
|
||||
}
|
||||
// Replace ConfigFactory ReadPaths method.
|
||||
$this->logger->info('Replace method "readPaths" in file "vendor/hyperf/config/src/ConfigFactory.php" and change "getRealPath" to "getPathname".');
|
||||
|
Loading…
Reference in New Issue
Block a user