Skip to content

Commit 5d19a44

Browse files
committed
[feat] update php-parse 5.x
- php-parser : ^4.1 to ^v5.0 - php version: 7.4 || 8.0 - update testcase
1 parent 238ae40 commit 5d19a44

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.1 || ^8.0",
13+
"php": "^7.4 || ^8.0",
1414
"ext-json": "*",
1515
"ext-pinpoint_php": "^0.5.2",
16-
"nikic/php-parser": "^4.1"
16+
"nikic/php-parser": "^5.0"
1717
},
1818
"autoload": {
1919
"psr-4": {
@@ -28,7 +28,7 @@
2828
"phpunit/phpunit": "^8",
2929
"phpbench/phpbench": "1.0.0",
3030
"ext-pinpoint_php": "^0.5.2",
31-
"nikic/php-parser": "^4.1",
31+
"nikic/php-parser": "^5.0",
3232
"predis/predis": "^3.0@alpha",
3333
"guzzlehttp/guzzle": "8.0.x-dev",
3434
"mongodb/mongodb": "v1.19.x-dev"

lib/Pinpoint/Common/GenProxyClassTemplateHelper.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ public function handleClassLeaveMethodNode($node, $monitorClassFullName)
159159
// 1. make a new method overriding parent's
160160
$originMethodName = $node->name->toString();
161161
$newMethodName = $this->methodNewName($originMethodName);
162-
$node->name = new Node\Name\FullyQualified($newMethodName);
162+
// $node->name = new Node\Name\FullyQualified($newMethodName);
163+
$node->name = new Node\Identifier($newMethodName);
163164

164165
Logger::Inst()->debug("generate pinpoint code block for '$originMethodName'");
165166
$funcVar = new Node\Arg(new Node\Scalar\MagicConst\Method());
@@ -325,8 +326,8 @@ public function handleClassLeaveMethodNode($node, $monitorClassFullName)
325326
$expArgs
326327
)
327328
);
328-
329-
$catchBlock[] = new Node\Stmt\Throw_(new Node\Expr\Variable("e"));
329+
// "throw $e;"
330+
$catchBlock[] = new Node\Stmt\Expression(new Node\Expr\Throw_(new Node\Expr\Variable("e")));
330331

331332
$catchNode[] = new Node\Stmt\Catch_(
332333
[new Node\Name('\Exception')],

lib/Pinpoint/Common/OriginFileVisitor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class OriginFileVisitor
2929
public function __construct()
3030
{
3131
$this->traverser = new NodeTraverser();
32-
$this->phpFileParser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
32+
// $this->phpFileParser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
33+
$this->phpFileParser = (new ParserFactory())->createForHostVersion();
3334
}
3435

3536
public function runAllVisitor(string $fullPath, AspectClassHandle $classHandler)

lib/Pinpoint/test/php_parse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use PDO;
88
use PhpParser\ParserFactory;
99
use PhpParser\PrettyPrinter;
10-
$filename='Bear.php';
10+
$filename = 'Bear.php';
1111
$code = file_get_contents($filename);
1212

1313

14-
$parser = (new ParserFactory)->create(ParserFactory::ONLY_PHP7);
14+
$parser = (new ParserFactory)->createForHostVersion();
1515
$ast = $parser->parse($code);
1616
$prettyPrinter = new PrettyPrinter\Standard();
1717
echo $prettyPrinter->prettyPrintFile($ast);
18-
file_put_contents($filename.'_6.ast', print_r($ast,true));
18+
file_put_contents($filename . '_6.ast', print_r($ast, true));

0 commit comments

Comments
 (0)