Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cdz_gateway_v2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨苏杭
cdz_gateway_v2
Commits
bbe717c9
Commit
bbe717c9
authored
Aug 21, 2018
by
banice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成控制器析构函数自动记录日志,对象引用造成析构函数
parent
8447bd66
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
99 additions
and
175 deletions
+99
-175
.idea/workspace.xml
+0
-0
application/Events.php
+8
-18
application/controller/Controller.php
+11
-15
application/controller/accept/AccessController.php
+4
-6
application/controller/accept/CertifyController.php
+3
-5
application/controller/business/charger/OverController.php
+2
-3
application/controller/business/charger/StartController.php
+5
-0
application/controller/business/port/OfflineController.php
+5
-0
application/controller/business/port/OnlineController.php
+5
-0
application/controller/business/port/StateController.php
+5
-0
application/controller/business/power/CapacityController.php
+5
-0
application/controller/business/power/PowerController.php
+4
-0
application/route/Api.php
+22
-23
src/Container.php
+8
-4
src/log/record/Record.php
+0
-6
src/response/Response.php
+8
-8
src/route/Route.php
+0
-15
start.php
+4
-10
test/test.php
+0
-62
No files found.
.idea/workspace.xml
View file @
bbe717c9
This diff is collapsed.
Click to expand it.
application/Events.php
View file @
bbe717c9
...
...
@@ -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
);
}
}
...
...
application/controller/Controller.php
View file @
bbe717c9
...
...
@@ -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
;
...
...
application/controller/accept/AccessController.php
View file @
bbe717c9
...
...
@@ -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
);
}
}
...
...
application/controller/accept/CertifyController.php
View file @
bbe717c9
...
...
@@ -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
();
}
...
...
application/controller/business/charger/OverController.php
View file @
bbe717c9
...
...
@@ -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
()
...
...
application/controller/business/charger/StartController.php
View file @
bbe717c9
...
...
@@ -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
*/
...
...
application/controller/business/port/OfflineController.php
View file @
bbe717c9
...
...
@@ -23,6 +23,11 @@ class OfflineController extends Controller
]
];
public
function
__construct
(
string
$clientId
,
string
$message
,
string
$command
)
{
parent
::
__construct
(
$clientId
,
$message
,
$command
);
}
/**
*
*/
...
...
application/controller/business/port/OnlineController.php
View file @
bbe717c9
...
...
@@ -22,6 +22,11 @@ class OnlineController extends Controller
]
];
public
function
__construct
(
string
$clientId
,
string
$message
,
string
$command
)
{
parent
::
__construct
(
$clientId
,
$message
,
$command
);
}
/**
* 设备上线
*/
...
...
application/controller/business/port/StateController.php
View file @
bbe717c9
...
...
@@ -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'
);
...
...
application/controller/business/power/CapacityController.php
View file @
bbe717c9
...
...
@@ -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'
];
...
...
application/controller/business/power/PowerController.php
View file @
bbe717c9
...
...
@@ -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
()
{
...
...
application/route/Api.php
View file @
bbe717c9
...
...
@@ -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
{
...
...
src/Container.php
View file @
bbe717c9
...
...
@@ -8,10 +8,13 @@
class
Container
{
/**
* @var
*/
private
$message
;
private
$api
;
private
$controller
;
public
function
__construct
()
{
}
}
\ No newline at end of file
src/log/record/Record.php
View file @
bbe717c9
...
...
@@ -51,12 +51,6 @@ class Record
}
public
function
__destruct
()
{
var_dump
(
'log destruct'
);
}
/**
* @return int
*/
...
...
src/response/Response.php
View file @
bbe717c9
...
...
@@ -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
->
c
ontroller
->
getClientId
()
,
$this
->
organize
());
Gateway
::
sendToClient
(
$this
->
c
lientId
,
$this
->
organize
());
}
...
...
src/route/Route.php
View file @
bbe717c9
...
...
@@ -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 中间件验证
*
...
...
start.php
View file @
bbe717c9
...
...
@@ -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
();
test/test.php
deleted
100644 → 0
View file @
8447bd66
<?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'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment