This commit is contained in:
2021-03-29 16:17:22 +08:00
parent 8bc0971f25
commit ce0ba186a7
5 changed files with 88 additions and 11 deletions
+31
View File
@@ -13,6 +13,7 @@ use Exception;
use JetBrains\PhpStorm\Pure;
use ReflectionException;
use Snowflake\Aop;
use Snowflake\Error\Logger;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
@@ -145,6 +146,36 @@ class BaseObject implements Configure
}
/**
* @param string $name
* @param array $arguments
* @return mixed
* @throws Exception
*/
public function __call(string $name, array $arguments): mixed
{
if (!Snowflake::app()->has('aop')) {
return call_user_func([$this, $name], $arguments);
}
return \aop([$this, $name], $arguments);
}
/**
* @param string $name
* @param array $arguments
* @return mixed
* @throws Exception
*/
public static function __callStatic(string $name, array $arguments): mixed
{
if (!Snowflake::app()->has('aop')) {
return call_user_func([get_called_class(), $name], $arguments);
}
return \aop([get_called_class(), $name], $arguments);
}
/**
* @param mixed $message
* @param string $method
+7 -8
View File
@@ -4,6 +4,7 @@
namespace Snowflake\Error;
use JetBrains\PhpStorm\Pure;
use Snowflake\IAspect;
@@ -22,26 +23,24 @@ class LoggerAspect implements IAspect
* LoggerAspect constructor.
* @param array $handler
*/
public function __construct(public array $handler)
#[Pure] public function __construct(public array $handler)
{
$this->className = get_class($this->handler[0]);
$this->methodName = $this->handler[1];
}
/**
* @return mixed|void
*/
public function invoke()
/**
* @return mixed
*/
public function invoke(): mixed
{
$startTime = microtime(true);
$data = call_user_func($this->handler, func_get_args());
$this->print_runtime($startTime);
if ($data === null) {
return;
}
return $data;
}