Skip to content

Commit 4fff6a4

Browse files
committed
format some codes for bean component
1 parent cd082a9 commit 4fff6a4

7 files changed

Lines changed: 27 additions & 29 deletions

File tree

src/bean/src/Container.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -890,13 +890,14 @@ private function newBean(string $beanName, string $id = '')
890890

891891
// Get object definition
892892
$objectDefinition = $this->getNewObjectDefinition($beanName);
893+
$propertyInjects = $objectDefinition->getPropertyInjections();
893894

894-
$scope = $objectDefinition->getScope();
895-
$alias = $objectDefinition->getAlias();
896-
$className = $objectDefinition->getClassName();
895+
$scope = $objectDefinition->getScope();
896+
$alias = $objectDefinition->getAlias();
897897

898898
// Cache reflection class info
899-
Reflections::cache($className);
899+
$className = $objectDefinition->getClassName();
900+
$reflectClass = Reflections::cache($className);
900901

901902
// Before initialize bean
902903
$this->beforeInit($beanName, $className, $objectDefinition);
@@ -907,18 +908,21 @@ private function newBean(string $beanName, string $id = '')
907908
$constructArgs = $this->getConstructParams($constructInject, $id);
908909
}
909910

910-
$propertyInjects = $objectDefinition->getPropertyInjections();
911-
912-
// Proxy class
911+
// It's proxy class. eg: AOP, RPC client class
913912
if ($this->handler) {
913+
$oldCName = $className;
914914
$className = $this->handler->classProxy($className);
915+
916+
// New class name from handler->classProxy()
917+
if ($oldCName !== $className) {
918+
$reflectClass = new ReflectionClass($className);
919+
}
915920
}
916921

917-
$reflectionClass = new ReflectionClass($className);
918-
$reflectObject = $this->newInstance($reflectionClass, $constructArgs);
922+
$reflectObject = $this->newInstance($reflectClass, $constructArgs);
919923

920924
// Inject properties values
921-
$this->newProperty($reflectObject, $reflectionClass, $propertyInjects, $id);
925+
$this->newProperty($reflectObject, $reflectClass, $propertyInjects, $id);
922926

923927
// Alias name
924928
// Fix: $aliasId !== $id for deny loop get
@@ -927,7 +931,7 @@ private function newBean(string $beanName, string $id = '')
927931
}
928932

929933
// Call init method if exist
930-
if ($reflectionClass->hasMethod(self::INIT_METHOD)) {
934+
if ($reflectClass->hasMethod(self::INIT_METHOD)) {
931935
$reflectObject->{self::INIT_METHOD}();
932936
}
933937

@@ -1147,7 +1151,7 @@ private function getRefValue($value, string $id = '')
11471151
$value = substr($value, 1);
11481152

11491153
// Other: read config reference
1150-
if ($this->handler !== null) {
1154+
if ($this->handler) {
11511155
$value = $this->handler->getReferenceValue($value);
11521156
}
11531157

src/bean/src/Contract/HandlerInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php declare(strict_types=1);
22

3-
43
namespace Swoft\Bean\Contract;
54

65
use Swoft\Bean\Definition\ObjectDefinition;
@@ -39,4 +38,4 @@ public function classProxy(string $className): string;
3938
* @return mixed
4039
*/
4140
public function getReferenceValue($value);
42-
}
41+
}

src/bean/src/Definition/ObjectDefinition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class ObjectDefinition
3030
*
3131
* @var string
3232
*/
33-
private $scope = Bean::SINGLETON;
33+
private $scope;
3434

3535
/**
3636
* @var string
3737
*/
38-
private $alias = '';
38+
private $alias;
3939

4040
/**
4141
* Constructor parameter injection.
@@ -194,4 +194,4 @@ public function setAlias(string $alias): void
194194
{
195195
$this->alias = $alias;
196196
}
197-
}
197+
}

src/bean/src/Handler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php declare(strict_types=1);
22

3-
43
namespace Swoft\Bean;
54

65
use Swoft\Bean\Contract\HandlerInterface;
@@ -49,4 +48,4 @@ public function getReferenceValue($value)
4948
{
5049
return $value;
5150
}
52-
}
51+
}

src/process/src/ProcessPool.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<?php declare(strict_types=1);
22

3-
43
namespace Swoft\Process;
54

65
use Swoft\Bean\Annotation\Mapping\Bean;
76
use Swoft\Co;
8-
use Swoft\Exception\SwoftException;
97
use Swoft\Log\Helper\CLog;
108
use Swoft\Process\Exception\ProcessException;
119
use Swoft\Server\Helper\ServerHelper;
@@ -159,8 +157,6 @@ public function stop(): bool
159157

160158
/**
161159
* Quick restart
162-
*
163-
* @throws SwoftException
164160
*/
165161
public function restart(): void
166162
{

src/process/src/UserProcess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class UserProcess implements UserProcessInterface
2929
/**
3030
* @var \Swoole\Process
3131
*/
32-
private $swooleProcess;
32+
protected $swooleProcess;
3333

3434
/**
3535
* @return bool

src/stdlib/src/Reflections.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ public static function get(string $className): array
6666
/**
6767
* @param string $className
6868
*
69+
* @return ReflectionClass
6970
* @throws ReflectionException
7071
*/
71-
public static function cache(string $className): void
72+
public static function cache(string $className): ReflectionClass
7273
{
73-
if (isset(self::$pool[$className])) {
74-
return;
75-
}
76-
7774
$reflectionClass = new ReflectionClass($className);
7875

76+
// Cache some metadata for the class
7977
self::cacheReflectionClass($reflectionClass);
78+
79+
return $reflectionClass;
8080
}
8181

8282
/**

0 commit comments

Comments
 (0)