Skip to content

Commit

Permalink
[feat] update php-parse 5.x
Browse files Browse the repository at this point in the history
- php-parser : ^4.1 to ^v5.0
- php version: 7.4 || 8.0
- update testcase
  • Loading branch information
eeliu committed Sep 2, 2024
1 parent 238ae40 commit 5d19a44
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-json": "*",
"ext-pinpoint_php": "^0.5.2",
"nikic/php-parser": "^4.1"
"nikic/php-parser": "^5.0"
},
"autoload": {
"psr-4": {
Expand All @@ -28,7 +28,7 @@
"phpunit/phpunit": "^8",
"phpbench/phpbench": "1.0.0",
"ext-pinpoint_php": "^0.5.2",
"nikic/php-parser": "^4.1",
"nikic/php-parser": "^5.0",
"predis/predis": "^3.0@alpha",
"guzzlehttp/guzzle": "8.0.x-dev",
"mongodb/mongodb": "v1.19.x-dev"
Expand Down
7 changes: 4 additions & 3 deletions lib/Pinpoint/Common/GenProxyClassTemplateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public function handleClassLeaveMethodNode($node, $monitorClassFullName)
// 1. make a new method overriding parent's
$originMethodName = $node->name->toString();
$newMethodName = $this->methodNewName($originMethodName);
$node->name = new Node\Name\FullyQualified($newMethodName);
// $node->name = new Node\Name\FullyQualified($newMethodName);
$node->name = new Node\Identifier($newMethodName);

Logger::Inst()->debug("generate pinpoint code block for '$originMethodName'");
$funcVar = new Node\Arg(new Node\Scalar\MagicConst\Method());
Expand Down Expand Up @@ -325,8 +326,8 @@ public function handleClassLeaveMethodNode($node, $monitorClassFullName)
$expArgs
)
);

$catchBlock[] = new Node\Stmt\Throw_(new Node\Expr\Variable("e"));
// "throw $e;"
$catchBlock[] = new Node\Stmt\Expression(new Node\Expr\Throw_(new Node\Expr\Variable("e")));

$catchNode[] = new Node\Stmt\Catch_(
[new Node\Name('\Exception')],
Expand Down
3 changes: 2 additions & 1 deletion lib/Pinpoint/Common/OriginFileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class OriginFileVisitor
public function __construct()
{
$this->traverser = new NodeTraverser();
$this->phpFileParser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
// $this->phpFileParser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
$this->phpFileParser = (new ParserFactory())->createForHostVersion();
}

public function runAllVisitor(string $fullPath, AspectClassHandle $classHandler)
Expand Down
6 changes: 3 additions & 3 deletions lib/Pinpoint/test/php_parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use PDO;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter;
$filename='Bear.php';
$filename = 'Bear.php';
$code = file_get_contents($filename);


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

0 comments on commit 5d19a44

Please sign in to comment.