Skip to content

Commit eaa33df

Browse files
eeliuliu.mingyi
authored andcommitted
feat(aop): remove setting.ini
- refactor aop for addJoinPoint api - tc for addFunctionAlias/addClassNameAlias pinpoint-apm/pinpoint-c-agent#543
1 parent 889127d commit eaa33df

28 files changed

+226
-518
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"streetsidesoftware.code-spell-checker",
99
"recca0120.vscode-phpunit",
1010
"donjayamanne.githistory",
11-
"adam-bender.commit-message-editor"
11+
"adam-bender.commit-message-editor",
12+
"bmewburn.vscode-intelephense-client",
13+
"xdebug.php-debug"
1214
]
1315
}
1416
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ composer.phar
22
/vendor/
33
.idea/
44
composer.lock
5-
lib/pinpoint/test/Cache
5+
lib/pinpoint/test/Cache/
66
lib/pinpoint/test/test.php
77
*.ast
88

99
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
1010
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
1111
# composer.lock
12+
lib/Pinpoint/test/Cache/Pinpoint/test/*.php

lib/Pinpoint/Common/ClassFile.php renamed to lib/Pinpoint/Common/AbstractClassFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use PhpParser\PrettyPrinter;
3030

3131
/**
32-
* Class ClassFile
32+
* Class AbstractClassFile
3333
*
3434
* A abstract php-parse node
3535
* namespace node
@@ -39,7 +39,7 @@
3939
*
4040
* @package pinpoint\Common
4141
*/
42-
abstract class ClassFile
42+
abstract class AbstractClassFile
4343
{
4444
public $appendingFile = array();
4545

lib/Pinpoint/Common/Monitor.php renamed to lib/Pinpoint/Common/AbstractMonitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace Pinpoint\Common;
2121

22-
abstract class Monitor
22+
abstract class AbstractMonitor
2323
{
2424
protected $monitor_name;
2525
protected $who;

lib/Pinpoint/Common/JoinClass.php renamed to lib/Pinpoint/Common/AspectClassHandle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
namespace Pinpoint\Common;
2121

2222

23-
class JoinClass
23+
class AspectClassHandle
2424
{
2525
public string $name;
2626
public $methodJoinPoints = array();

lib/Pinpoint/Common/CodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function enterNode(Node $node)
4444
{
4545
if ($node instanceof Node\Stmt\Namespace_) {
4646
foreach ($this->visitors as $visitor) {
47-
assert($visitor instanceof ClassFile);
47+
assert($visitor instanceof AbstractClassFile);
4848
$visitor->handleEnterNamespaceNode($node);
4949
}
5050
} elseif ($node instanceof Node\Stmt\Use_) {

lib/Pinpoint/Common/GenOriginClassTemplateHelper.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
namespace Pinpoint\Common;
2727

2828
use PhpParser\Node;
29-
use Pinpoint\Common\ClassFile;
29+
use Pinpoint\Common\AbstractClassFile;
3030

31-
class GenOriginClassTemplateHelper extends ClassFile
31+
class GenOriginClassTemplateHelper extends AbstractClassFile
3232
{
3333
protected $originClassFileDir;
3434
protected $originClassFilePath;
@@ -37,18 +37,18 @@ class GenOriginClassTemplateHelper extends ClassFile
3737
protected $funcAlias = [];
3838
protected $suffix_use = [];
3939
protected $methodJoint;
40-
// private $joinClass;
41-
public function __construct(JoinClass $joinClass, string $namePrefix)
40+
// private $classHandler;
41+
public function __construct(AspectClassHandle $classHandler, string $namePrefix)
4242
{
4343
parent::__construct($namePrefix);
44-
$path = Utils::findFile($joinClass->name);
44+
$path = Utils::findFile($classHandler->name);
4545

4646
$this->originClassFileDir = dirname($path);
4747
$this->originClassFilePath = $path;
48-
// $this->joinClass = $joinClass;
49-
$this->classAliasSet = $joinClass->classAlias;
50-
$this->funcAlias = $joinClass->funcAlias;
51-
$this->methodJoint = $joinClass->methodJoinPoints;
48+
// $this->classHandler = $classHandler;
49+
$this->classAliasSet = $classHandler->classAlias;
50+
$this->funcAlias = $classHandler->funcAlias;
51+
$this->methodJoint = $classHandler->methodJoinPoints;
5252
}
5353

5454
private function getRealNp($node)

lib/Pinpoint/Common/GenProxyClassTemplateHelper.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
namespace Pinpoint\Common;
2727

28-
use Pinpoint\Common\ClassFile;
28+
use Pinpoint\Common\AbstractClassFile;
2929
use PhpParser\BuilderFactory;
3030
use PhpParser\Node;
3131
use Pinpoint\Common\PluginParser;
3232

33-
class GenProxyClassTemplateHelper extends ClassFile
33+
class GenProxyClassTemplateHelper extends AbstractClassFile
3434
{
3535
private $factory;
3636

@@ -47,11 +47,11 @@ class GenProxyClassTemplateHelper extends ClassFile
4747
private $handleEndTraverseCb = [];
4848
public $methodJoinPoints = [];
4949

50-
public function __construct(JoinClass $joinClass, $prefix)
50+
public function __construct(AspectClassHandle $classHandler, $prefix)
5151
{
5252
parent::__construct($prefix);
5353
$this->factory = new BuilderFactory();
54-
$this->methodJoinPoints = $joinClass->methodJoinPoints;
54+
$this->methodJoinPoints = $classHandler->methodJoinPoints;
5555
}
5656

5757

@@ -168,7 +168,7 @@ public function handleClassLeaveMethodNode($node, $monitorClassFullName)
168168
/// $_pinpoint_method_var = new pinpoint\Plugins\CommonPlugins(__FUNCTION__,self,$p);
169169
$newPluginsStm = new Node\Stmt\Expression(new Node\Expr\Assign(
170170
new Node\Expr\Variable($varName),
171-
$this->factory->new(new Node\Name\FullyQualified($monitorClassFullName) , $methodParams)
171+
$this->factory->new(new Node\Name\FullyQualified($monitorClassFullName), $methodParams)
172172
));
173173

174174
$thisMethod->addStmt($newPluginsStm);
@@ -540,7 +540,7 @@ function handleMagicConstNode($node)
540540
{
541541
}
542542

543-
function handleLeaveClassNode($node){
544-
543+
function handleLeaveClassNode($node)
544+
{
545545
}
546546
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* Copyright 2020-present NAVER Corp.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
namespace Pinpoint\Common;
21+
22+
interface JoinClassInterface
23+
{
24+
public function joinedClass(): array;
25+
}

lib/Pinpoint/Common/OriginFileVisitor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ public function __construct()
3232
$this->phpFileParser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
3333
}
3434

35-
public function runAllVisitor(string $fullPath, JoinClass $joinClass)
35+
public function runAllVisitor(string $fullPath, AspectClassHandle $classHandler)
3636
{
37-
$this->traverser->addVisitor($this->getVisitor($joinClass));
37+
$this->traverser->addVisitor($this->getVisitor($classHandler));
3838
$code = file_get_contents($fullPath);
3939
$stmts = $this->phpFileParser->parse($code);
4040
$this->traverser->traverse($stmts);
4141
}
4242

43-
private function getVisitor(JoinClass $joinClass)
43+
private function getVisitor(AspectClassHandle $classHandler)
4444
{
4545
$classPrefix = "";
4646
$visitors = [];
47-
if (!empty($joinClass->getMethodJoinPoints())) {
47+
if (!empty($classHandler->getMethodJoinPoints())) {
4848
$classPrefix = CLASS_PREFIX;
49-
$visitors[] = new GenProxyClassTemplateHelper($joinClass, $classPrefix);
49+
$visitors[] = new GenProxyClassTemplateHelper($classHandler, $classPrefix);
5050
}
5151

52-
$visitors[] = new GenOriginClassTemplateHelper($joinClass, $classPrefix);
52+
$visitors[] = new GenOriginClassTemplateHelper($classHandler, $classPrefix);
5353
$codeVisitor = new CodeVisitor($visitors);
5454
return $codeVisitor;
5555
}

lib/Pinpoint/Common/PerRequest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@
1919

2020
namespace Pinpoint\Common;
2121

22-
interface I_PerRequest
23-
{
24-
public function joinedClass(): array;
25-
}
26-
27-
28-
class PerRequestDefault implements I_PerRequest
22+
class PerRequestDefault implements JoinClassInterface
2923
{
3024
public function joinedClass(): array
3125
{

lib/Pinpoint/Common/PinpointDriver.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525

2626
namespace Pinpoint\Common;
2727

28-
use Exception;
29-
use Pinpoint\Plugins\PerRequestPlugins;
3028

3129
class PinpointDriver
3230
{
3331
protected static $instance;
3432
protected $clAr = [];
3533

36-
private I_PerRequest $reqInst;
34+
private JoinClassInterface $reqInst;
3735

3836
public static function getInstance()
3937
{
@@ -48,7 +46,7 @@ final private function __construct()
4846
if (defined('PP_REQ_PLUGINS') && class_exists(PP_REQ_PLUGINS)) {
4947
$userPerRequestClass = PP_REQ_PLUGINS;
5048
$this->reqInst = new $userPerRequestClass();
51-
assertInstanceOf('I_PerRequest', $this->reqInst);
49+
assertInstanceOf('JoinClassInterface', $this->reqInst);
5250
} else {
5351
$this->reqInst = new PerRequestDefault();
5452
}
@@ -80,8 +78,8 @@ public function start()
8078
$fullPath = Utils::findFile($fullClassName);
8179
// Please DO NOT CHEAT ME
8280
assertFileExists($fullPath, "'$fullPath' must exist");
83-
assertInstanceOf("\Pinpoint\Common\Pinpoint\JoinClass", $junction);
84-
81+
assertInstanceOf("\Pinpoint\Common\Pinpoint\AspectClassHandle", $junction);
82+
8583
$visitor = new OriginFileVisitor();
8684
$visitor->runAllVisitor($fullPath, $junction);
8785
}

lib/Pinpoint/Plugins/PerRequestPlugins.php renamed to lib/Pinpoint/Plugins/PinpointPerRequestPlugins.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
require_once __DIR__ . "/__init__.php";
2222

23-
class PerRequestPlugins
23+
class PinpointPerRequestPlugins
2424
{
2525
public $tid = null;
2626
public $sid = null;

lib/Pinpoint/Plugins/Yii2PerRequestPlugins.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/******************************************************************************
34
* Copyright 2020 NAVER Corp. *
45
* *
@@ -19,18 +20,20 @@
1920

2021
use Yii;
2122
use Pinpoint\Common\Utils;
22-
use Pinpoint\Plugins\PerRequestPlugins;
23+
use Pinpoint\Plugins\PinpointPerRequestPlugins;
24+
use Pinpoint\Common\JoinClassInterface;
2325

24-
class Yii2PerRequestPlugins extends PerRequestPlugins
26+
class Yii2PerRequestPlugins extends PinpointPerRequestPlugins implements JoinClassInterface
2527
{
2628
protected function __construct()
2729
{
2830
parent::__construct();
2931
// enable findFile patch
30-
Utils::addLoaderPatch(array($this,'findFileInYii'),null);
32+
Utils::addLoaderPatch(array($this, 'findFileInYii'), null);
3133
}
3234

33-
public function findFileInYii($className):string {
35+
public function findFileInYii($className): string
36+
{
3437
if (isset(Yii::$classMap[$className])) {
3538
$classFile = Yii::$classMap[$className];
3639
if (strpos($classFile, '@') === 0) {
@@ -46,4 +49,8 @@ public function findFileInYii($className):string {
4649
return "";
4750
}
4851

52+
public function joinedClass(): array
53+
{
54+
return [];
55+
}
4956
}

lib/Pinpoint/test/AccessRemote.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)