@@ -42,12 +42,12 @@ public function process(ContainerBuilder $container): void
4242 $ statements = [];
4343 foreach (array_keys ($ container ->findTaggedServiceIds (Aspect::TAG_NAME )) as $ serviceId ) {
4444 $ reflectionClass = $ this ->getReflectionClass ($ container , $ serviceId );
45- if (! $ reflectionClass ) {
45+ if ($ reflectionClass === null ) {
4646 continue ;
4747 }
4848 foreach ($ reflectionClass ->getMethods (\ReflectionMethod::IS_PUBLIC ) as $ method ) {
4949 foreach ($ method ->getAttributes () as $ attribute ) {
50- /** @var \ReflectionAttribute $attribute */
50+ /** @var \ReflectionAttribute<object> $attribute */
5151 $ name = $ attribute ->getName ();
5252 if (is_subclass_of ($ name , Advice::class)) {
5353 $ instance = $ attribute ->newInstance ();
@@ -77,12 +77,13 @@ public function process(ContainerBuilder $container): void
7777 // 这里为了快速实现,我们使用了表达式组件,跟Spring的实现有差异
7878 $ expressionLanguage = new ExpressionLanguage (null , $ container ->getExpressionLanguageProviders ());
7979 $ expressionLanguage ->addFunction (ExpressionFunction::fromPhp ('count ' ));
80+ $ expressionLanguage ->addFunction (ExpressionFunction::fromPhp ('in_array ' ));
8081 foreach ($ container ->getServiceIds () as $ serviceId ) {
8182 if ($ this ->isInternalService ($ serviceId )) {
8283 continue ;
8384 }
8485 $ reflectionClass = $ this ->getReflectionClass ($ container , $ serviceId );
85- if (! $ reflectionClass ) {
86+ if ($ reflectionClass === null ) {
8687 continue ;
8788 }
8889 // 为了减少循环依赖问题,这里我们暂时忽略Aspect
@@ -105,13 +106,14 @@ public function process(ContainerBuilder $container): void
105106 // 满足条件,我们开始拦截方法
106107 if (
107108 $ statement !== $ fullName
108- && !$ expressionLanguage ->evaluate ($ statement , [
109+ && !( bool ) $ expressionLanguage ->evaluate ($ statement , [
109110 'class ' => $ reflectionClass ,
110111 'method ' => $ method ,
111112 'serviceId ' => $ serviceId ,
112113 'serviceTags ' => $ serviceTags ,
113114 'parentClasses ' => self ::getParentClasses ($ reflectionClass ),
114- ])) {
115+ ])
116+ ) {
115117 continue ;
116118 }
117119
@@ -219,6 +221,8 @@ private function updateInternalServiceId(ContainerBuilder $container, string $se
219221
220222 if (!$ container ->hasDefinition ($ internalId )) {
221223 $ definition = $ container ->getDefinition ($ serviceId );
224+ // 保存原始的 public 状态
225+ $ originalPublic = $ definition ->isPublic ();
222226 if (!$ definition ->isAbstract () && $ serviceId !== 'session.abstract_handler ' ) {
223227 // 声明为public,方便后面动态调用,目前主要在 ServiceCallHandler 中调用
224228 $ definition ->setPublic (true );
@@ -237,10 +241,10 @@ private function updateInternalServiceId(ContainerBuilder $container, string $se
237241 ->setArguments ([
238242 new Reference ($ internalId ),
239243 ])
240- ->setPublic ($ definition -> isPublic () )
244+ ->setPublic ($ originalPublic )
241245 ->setTags ($ existTags ) // 这里重新补上原始服务的tag
242246 //->addTag('aop-proxy')
243- ;
247+ ;
244248 // 覆盖旧的服务名
245249 $ container ->setDefinition ($ serviceId , $ aopNewService );
246250 }
0 commit comments