Commit bbe717c9 by banice

完成控制器析构函数自动记录日志,对象引用造成析构函数

parent 8447bd66
......@@ -45,9 +45,7 @@ class Events
}
static::$redis->select('4');
\Application\route\Api::boot();
var_dump('route boot ');
\Lib\log\Log::bootLog();
......@@ -82,37 +80,29 @@ class Events
}
$command = substr($message, 6, 2);
$api = new Api();
$api->boot();
if (isset(Api::$route[$command])) {
$route = Api::$route[$command];
if (isset($api->route[$command])) {
var_dump(spl_object_hash($route));
$route = $api->route[$command];
if ($route instanceof Route) {
$reflection = $route->getController();
var_dump('1');
$reflection = $route->getController();
$controller = $reflection->newInstanceArgs([$clientId, $message, $route]);
$controller = $reflection->newInstanceArgs([$clientId, $message, $command]);
$method = $route->getMethod();
try {
$controller->$method();
} catch (Exception $exception) {
Log::error($exception->getMessage());
}
unset($controller);
var_dump('unset controller');
unset($route);
var_dump('unset route');
unset($controller);
unset($api);
}
}
......
......@@ -128,30 +128,28 @@ class Controller
protected $route;
protected $command = '';
/**
* Controller constructor.
* @param string $clientId
* @param string $message
* @param Route $route
* @param string $command
*/
public function __construct(string $clientId, string $message, Route $route)
public function __construct(string $clientId, string $message, string $command)
{
var_dump('construct');
var_dump(spl_object_hash($route));
$this->clientId = $clientId;
$this->message = $message;
$this->route = $route;
$this->parseHeader($message, $this->defaultHeader);
$this->command = $command;
$this->parseBody();
$this->response = new Response($this);
$this->response = new Response($this->clientId, $this->headerFlag);
$this->encrypt = $this->headerFlag === '05' ? true : false;
......@@ -159,7 +157,8 @@ class Controller
$this->logRecord->setBody($this->message);
$this->logRecord->setCommand($route->getCommand());
$this->logRecord->setCommand($command);
if (isset($_SESSION['station_id'])) {
$this->logRecord->setStationId($_SESSION['station_id']);
......@@ -177,9 +176,6 @@ class Controller
$logWriter = new GatewayLogWriter();
$logWriter->write($this->logRecord);
var_dump('controller destruct');
}
/**
......@@ -189,7 +185,7 @@ class Controller
{
$tmp = [];
foreach ($this->parameterMap[$this->route->getCommand()] as $key => $length) {
foreach ($this->parameterMap[$this->command] as $key => $length) {
$start = $this->plc;
......
......@@ -34,10 +34,9 @@ class AccessController extends Controller
]
];
public function __construct(string $clientId, string $message, Route $route)
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $route);
parent::__construct($clientId, $message, $command);
}
public function __destruct()
......@@ -100,9 +99,6 @@ class AccessController extends Controller
$_SESSION['port_mac_id'] = $tmp;
$_SESSION['port_id_mac'] = array_flip($tmp);
var_dump($tmp);
$_SESSION['station_id'] = $stationId;
$_SESSION['gateway_id'] = $gatewayId;
$_SESSION['client_id'] = $this->clientId;
......@@ -122,6 +118,8 @@ class AccessController extends Controller
$this->response->send('02', $sessionId);
unset($this->response);
}
}
......
......@@ -30,16 +30,14 @@ class CertifyController extends Controller
],
];
public function __construct(string $clientId, string $message, Route $route)
{
var_dump('certify construct');
parent::__construct($clientId, $message, $route);
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
public function __destruct()
{
var_dump('certify destruct');
parent::__destruct();
}
......
......@@ -15,10 +15,9 @@ use Src\route\Route;
class OverController extends Controller
{
public function __construct(string $clientId, string $message, Route $route)
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $route);
parent::__construct($clientId, $message, $command);
}
public function over()
......
......@@ -29,6 +29,11 @@ class StartController extends Controller
],
];
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
/**
* @throws \GuzzleHttp\Exception\GuzzleException
*/
......
......@@ -23,6 +23,11 @@ class OfflineController extends Controller
]
];
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
/**
*
*/
......
......@@ -22,6 +22,11 @@ class OnlineController extends Controller
]
];
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
/**
* 设备上线
*/
......
......@@ -30,6 +30,11 @@ class StateController extends Controller
]
];
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
public function change()
{
$portLogic = $this->request->get('port_logic');
......
......@@ -20,6 +20,11 @@ class CapacityController extends Controller
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
public function capacity()
{
$gatewayId = $_SESSION['gateway_id'];
......
......@@ -34,6 +34,10 @@ class PowerController extends Controller
]
];
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
public function one()
{
......
......@@ -9,30 +9,29 @@ class Api
{
public static $route = [];
public $route = [];
public static function boot()
public function boot()
{
static::add('01', 'accept\CertifyController@certify');
// static::add('00','HeartController@break');
// static::add('02','accept\AccessController@request');
// static::add('03','accept\AccessController@syncPort');
//
// static::add('04','business\charger\StartController@start');
// static::add('05','business\charger\OverController@over');
//
// static::add('0b','business\port\StateController@change');
//
// static::add('07','business\power\PowerController@plural');
// static::add('17','business\power\PowerController@one');
//
// static::add('06','business\power\CapacityController@capacity');
//
//
// static::add('08','business\port\OnlineController@online');
// static::add('09','business\port\OfflineController@offline');
$this->add('01', 'accept\CertifyController@certify');
$this->add('00','HeartController@break');
$this->add('02','accept\AccessController@request');
$this->add('03','accept\AccessController@syncPort');
$this->add('04','business\charger\StartController@start');
$this->add('05','business\charger\OverController@over');
$this->add('0b','business\port\StateController@change');
$this->add('07','business\power\PowerController@plural');
$this->add('17','business\power\PowerController@one');
$this->add('06','business\power\CapacityController@capacity');
$this->add('08','business\port\OnlineController@online');
$this->add('09','business\port\OfflineController@offline');
......@@ -47,7 +46,7 @@ class Api
* @param array $middlewar
* @return void
*/
public static function add(string $command, string $controllerAction, array $middleware = [])
public function add(string $command, string $controllerAction, array $middleware = [])
{
$route = new Route();
......@@ -90,7 +89,7 @@ class Api
}
static::$route[$command] = $route;
$this->route[$command] = $route;
} else {
......
......@@ -8,10 +8,13 @@
class Container
{
/**
* @var
*/
private $message;
private $api;
private $controller;
public function __construct()
{
}
}
\ No newline at end of file
......@@ -51,12 +51,6 @@ class Record
}
public function __destruct()
{
var_dump('log destruct');
}
/**
* @return int
*/
......
......@@ -64,15 +64,17 @@ class Response
*/
private $responseMessage = '';
/**
* @var Controller
* @var string
*/
private $controller;
private $clientId ='';
public function __construct(Controller $controller)
public function __construct(string $clientId, string $headerFlag)
{
$this->controller = $controller;
$this->clientId = $clientId;
$this->headerFlag = $headerFlag;
}
......@@ -85,11 +87,9 @@ class Response
$this->nonce = sprintf('%02x', dechex(rand(0, 255)));
$this->headerFlag = $this->controller->getEncrypt() ? '05' : '04';
$this->length = sprintf('%04x', (8 + strlen($body) / 2));
Gateway::sendToClient($this->controller->getClientId(), $this->organize());
Gateway::sendToClient($this->clientId, $this->organize());
}
......
......@@ -54,21 +54,6 @@ class Route
*/
private $middleware = [];
public function __construct()
{
var_dump('route');
}
public function __destruct()
{
var_dump(spl_object_hash($this));
var_dump('route destruct');
}
/**
* Get 中间件验证
*
......
......@@ -28,22 +28,16 @@ $dotenv->load();
$startGateway = getenv('START_FILE');
$startGateway = explode('|',$startGateway);
$startGateway = explode('|', $startGateway);
foreach (glob(__DIR__.'/application/start*.php') as $startFile) {
foreach (glob(__DIR__ . '/application/start*.php') as $startFile) {
foreach ($startGateway as $name)
{
if(strstr($startFile,$name))
{
foreach ($startGateway as $name) {
if (strstr($startFile, $name)) {
require_once $startFile;
}
}
}
//Application\route\Api::boot();
//
//\Lib\log\Log::bootLog();
\Workerman\Worker::runAll();
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/21
* Time: 下午6:57
*/
class A{
static $x;
public function __destruct()
{
var_dump('destruct');
}
public function __construct()
{
var_dump('construct');
}
}
$reflection = new \ReflectionClass('A');
var_dump('1');
$x = &$reflection;
//$a = $reflection->newInstanceArgs();
A::$x = new A();
$a1 = A::$x;
var_dump(spl_object_hash($a1));
$a2 = A::$x;
var_dump(spl_object_hash($a2));
unset($a1);
unset($a2);
var_dump('------------------');
//unset($a);
var_dump('sss');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment