Skip to content

Commit

Permalink
Merge pull request #74 from zhamao-robot/fix-onsetup-attribute-exec
Browse files Browse the repository at this point in the history
Fix OnSetup Attribute execution bug (release 2.7.3)
  • Loading branch information
crazywhalecc authored Mar 25, 2022
2 parents b40dc1e + d3f4ade commit b6e135a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/ZM/Annotation/Swoole/OnTick.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ZM\Annotation\Swoole;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
Expand All @@ -16,6 +17,7 @@
* @Target("METHOD")
* @since 1.2
*/
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class OnTick extends AnnotationBase
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/ZM/Annotation/Swoole/SwooleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ZM\Annotation\Swoole;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Required;
use Doctrine\Common\Annotations\Annotation\Target;
Expand All @@ -15,6 +16,7 @@
* @NamedArgumentConstructor()
* @Target("ALL")
*/
#[Attribute(Attribute::TARGET_ALL)]
class SwooleHandler extends AnnotationBase
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/ZM/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class ConsoleApplication extends Application
{
public const VERSION_ID = 451;
public const VERSION_ID = 453;

public const VERSION = '2.7.3';

Expand Down
5 changes: 5 additions & 0 deletions src/ZM/Http/MiddlewareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace ZM\Http;

use ZM\Annotation\Http\Middleware;

/**
* @property Middleware $middleware
*/
interface MiddlewareInterface
{
}
18 changes: 3 additions & 15 deletions src/ZM/script_setup_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
declare(strict_types=1);

use Doctrine\Common\Annotations\AnnotationReader;
use Koriym\Attributes\AttributeReader;
use Koriym\Attributes\DualReader;
use ZM\Annotation\Swoole\OnSetup;
use ZM\Annotation\Swoole\SwooleHandler;
use ZM\ConsoleApplication;
Expand Down Expand Up @@ -36,7 +38,7 @@
$all_event_class = array_merge($all_event_class, ZMUtil::getClassesPsr4($autoload_path, $namespace));
}

$reader = new AnnotationReader();
$reader = new DualReader(new AnnotationReader(), new AttributeReader());
$event_list = [];
$setup_list = [];
foreach ($all_event_class as $v) {
Expand Down Expand Up @@ -68,17 +70,3 @@
fclose($stderr);
exit(1);
}

/*
记迷惑,这里的代码是不是可以放到一个单独的文件里面,这样就不会出现每次都要重新加载的问题了?
然后这个文件就实现了,就是这个。
但是还有个什么问题呢?为了 reload 牺牲了太多太多,但是关键时刻好像又不是很能用到。
但又不能没有。
所以我很纠结很纠结。
如何让用户的代码能像 php-fpm 那样随时重置呢?
我不知道诶。
那这段代码干了个啥?
在最开始单独启动进程,加载一遍所有类,获取需要在启动前就执行的类,然后在启动的时候执行。
这样就可以不在爷进程里面加载所有类,在爹进程里面 Fork 的子进程再加载所有类,每次 reload 时可以重新加载了。
以上均为乱写的,请勿完全当真,本人对待框架代码还是比较认真的。
*/

0 comments on commit b6e135a

Please sign in to comment.