Merge pull request #811 from limingxinleo/1.1-di

Added init-proxy.sh
This commit is contained in:
李铭昕 2019-10-31 10:48:53 +08:00 committed by GitHub
commit e72d9b30c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 27 deletions

View File

@ -22,6 +22,7 @@
## Changed ## Changed
- [#793](https://github.com/hyperf/hyperf/pull/793) Changed `protected` to `public` for `Pool::getConnectionsInChannel`. - [#793](https://github.com/hyperf/hyperf/pull/793) Changed `protected` to `public` for `Pool::getConnectionsInChannel`.
- [#811](https://github.com/hyperf/hyperf/pull/811) Command `di:init-proxy` does not clear the runtime cache, If you want to delete them, use `vendor/bin/init-proxy.sh` instead.
# v1.1.3 - 2019-10-24 # v1.1.3 - 2019-10-24

View File

@ -30,17 +30,17 @@ runtime/container/proxy/
Re-genenrate command Re-genenrate command
``` ```
php bin/hyperf.php di:init-proxy vendor/bin/init-proxy.sh
``` ```
So the command to run unit test can use the following instead So the command to run unit test can use the following instead
``` ```
php bin/hyperf.php di:init-proxy && composer test vendor/bin/init-proxy.sh && composer test
``` ```
Similarly, the command to start the server can also use the following instead Similarly, the command to start the server can also use the following instead
``` ```
php bin/hyperf.php di:init-proxy && php bin/hyperf.php start vendor/bin/init-proxy.sh && php bin/hyperf.php start
``` ```
## Docker build failure ## Docker build failure

View File

@ -68,4 +68,4 @@ class FooAspect extends AbstractAspect
在部署生产环境时,我们可能会希望 Hyperf 提前将所有代理类提前生成,而不是使用时动态的生成,可以通过 `php bin/hyperf.php di:init-proxy` 命令来生成所有代理类,该命令会忽视现有的代理类缓存,全部重新生成。 在部署生产环境时,我们可能会希望 Hyperf 提前将所有代理类提前生成,而不是使用时动态的生成,可以通过 `php bin/hyperf.php di:init-proxy` 命令来生成所有代理类,该命令会忽视现有的代理类缓存,全部重新生成。
基于以上,我们可以将生成代理类的命令和启动服务的命令结合起来,`php bin/hyperf.php di:init-proxy && php bin/hyperf.php start` 来达到自动重新生成所有代理类缓存然后启动服务的目的。 基于以上,我们可以将生成代理类的命令和启动服务的命令结合起来,`vendor/bin/init-proxy.sh && php bin/hyperf.php start` 来达到自动重新生成所有代理类缓存然后启动服务的目的。

View File

@ -24,28 +24,33 @@ swoole.use_shortname = 'Off'
代理类缓存一旦生成,将不会再重新覆盖。所以当你修改了已经生成代理类的文件时,需要手动清理。 代理类缓存一旦生成,将不会再重新覆盖。所以当你修改了已经生成代理类的文件时,需要手动清理。
代理类位置如下 代理类位置如下
``` ```
runtime/container/proxy/ runtime/container/proxy/
``` ```
重新生成缓存命令,新缓存会覆盖原目录 重新生成缓存命令,新缓存会覆盖原目录
```bash ```bash
php bin/hyperf.php di:init-proxy vendor/bin/init-proxy.sh
``` ```
删除代理类缓存 删除代理类缓存
```bash ```bash
rm -rf ./runtime/container/proxy rm -rf ./runtime/container/proxy
``` ```
所以单测命令可以使用以下代替: 所以单测命令可以使用以下代替:
```bash ```bash
php bin/hyperf.php di:init-proxy && composer test vendor/bin/init-proxy.sh && composer test
``` ```
同理,启动命令可以使用以下代替 同理,启动命令可以使用以下代替
```bash ```bash
php bin/hyperf.php di:init-proxy && php bin/hyperf.php start vendor/bin/init-proxy.sh && php bin/hyperf.php start
``` ```
## PHP7.3下预先生成代理的脚本 执行失败 ## PHP7.3下预先生成代理的脚本 执行失败

View File

@ -37,7 +37,7 @@ require BASE_PATH . '/config/container.php';
``` ```
# 重新生成代理类 # 重新生成代理类
php bin/hyperf.php di:init-proxy vendor/bin/init-proxy.sh
# 运行单元测试 # 运行单元测试
composer test composer test
``` ```

19
src/di/bin/init-proxy.sh Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
basepath=$(cd `dirname $0`; pwd)
echo ../../
if [ ! -f "composer.lock" ]; then
echo "Not found composer.lock, please composer install first."
exit
fi
rm -rf runtime
echo "Runtime cleared"
php bin/hyperf.php di:init-proxy
echo "Finish!"

View File

@ -56,6 +56,7 @@
} }
}, },
"bin": [ "bin": [
"bin/init-proxy.sh"
], ],
"scripts": { "scripts": {
"cs-fix": "php-cs-fixer fix $1", "cs-fix": "php-cs-fixer fix $1",

View File

@ -18,8 +18,6 @@ use Hyperf\Di\Annotation\Scanner;
use Hyperf\Di\Container; use Hyperf\Di\Container;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
class InitProxyCommand extends Command class InitProxyCommand extends Command
{ {
@ -49,23 +47,13 @@ class InitProxyCommand extends Command
public function handle() public function handle()
{ {
$this->warn('This command does not clear the runtime cache, If you want to delete them, use `vendor/bin/init-proxy.sh` instead.');
$this->createAopProxies(); $this->createAopProxies();
$this->output->writeln('<info>Proxy class create success.</info>'); $this->output->writeln('<info>Proxy class create success.</info>');
} }
protected function clearRuntime($paths)
{
$finder = new Finder();
$finder->files()->in($paths)->name(['*.php', '*.cache']);
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$path = $file->getRealPath();
@unlink($path);
}
}
protected function getScanDir() protected function getScanDir()
{ {
if (! defined('BASE_PATH')) { if (! defined('BASE_PATH')) {
@ -91,11 +79,6 @@ class InitProxyCommand extends Command
{ {
$scanDirs = $this->getScanDir(); $scanDirs = $this->getScanDir();
$runtime = BASE_PATH . '/runtime/container/';
if (is_dir($runtime)) {
$this->clearRuntime($runtime);
}
$meta = $this->scanner->scan($scanDirs); $meta = $this->scanner->scan($scanDirs);
$classCollection = array_keys($meta); $classCollection = array_keys($meta);