Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new api #51

Merged
merged 13 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "pinpont-php-aop",
"image": "mcr.microsoft.com/devcontainers/php:7.4",
"remoteUser": "vscode",
"customizations": {
"vscode": {
"extensions": [
"streetsidesoftware.code-spell-checker",
"recca0120.vscode-phpunit",
"donjayamanne.githistory",
"adam-bender.commit-message-editor",
"bmewburn.vscode-intelephense-client",
"xdebug.php-debug",
"streetsidesoftware.code-spell-checker"
]
}
}
}
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---


20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
20 changes: 20 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v1
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.1', '7.2', '7.3', '7.4']
php-versions: [ '7.4','8.0','8.1','8.2']
steps:
- uses: actions/checkout@v2
- name: Setup PHP
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ composer.phar
/vendor/
.idea/
composer.lock
lib/pinpoint/test/Cache
lib/pinpoint/test/Cache/*
lib/pinpoint/test/test.php
*.ast

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
/test_*.php
File renamed without changes.
6 changes: 4 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[![Build](https://github.com/pinpoint-apm/pinpoint-php-aop/workflows/Build/badge.svg?branch=master)](https://github.com/pinpoint-apm/pinpoint-php-aop/actions) [![LICENSE](https://img.shields.io/github/license/pinpoint-apm/pinpoint-php-aop)](LICENSE)

## Issues

https://github.com/pinpoint-apm/pinpoint-c-agent/labels/php-aop

## How to Use

### Import from packagist
Expand Down Expand Up @@ -57,8 +61,6 @@ require_once __DIR__."/../vendor/autoload.php";

// A writable path for caching AOP code
define('AOP_CACHE_DIR',__DIR__.'/../Cache/');
// Your plugins directory: All plugins must have a suffix "Plugin.php",as "CommonPlugin.php mysqlPlugin.php RPCPlugin.php"
define('PLUGINS_DIR',__DIR__.'/../Plugins/');
// since 0.2.5+ PINPOINT_USE_CACHE = N, auto_pinpointed.php will generate Cache/* on every request.
define('PINPOINT_USE_CACHE','YES');
// Use pinpoint-php-aop auto_pinpointed.php instead of vendor/autoload.php
Expand Down
29 changes: 19 additions & 10 deletions auto_pinpointed.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/

namespace Pinpoint;

use Pinpoint\Common\PinpointDriver;
use Pinpoint\Plugins\PerRequestPlugins;
define('CLASS_PREFIX','Proxied_');

if(defined('PP_REQ_PLUGINS') && class_exists(PP_REQ_PLUGINS)){
$plugins = PP_REQ_PLUGINS;
$plugins::instance();
}else{
PerRequestPlugins::instance();
}

PinpointDriver::getInstance()->start();
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"authors": [
{
"name": "eeliu",
"email": "eeliu2009@gmail.com"
"email": "liu.mingyi@navercorp.com"
}
],
"autoload": {
Expand All @@ -16,7 +16,7 @@
},
"minimum-stability": "dev",
"require-dev": {
"phpunit/phpunit": "^7"
"phpunit/phpunit": "^8"
},
"require": {
"php": ">=7",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);
/**
* Copyright 2020-present NAVER Corp.
*
Expand All @@ -25,8 +27,9 @@

use PhpParser\Node;
use PhpParser\PrettyPrinter;

/**
* Class ClassFile
* Class AbstractClassFile
*
* A abstract php-parse node
* namespace node
Expand All @@ -36,23 +39,21 @@
*
* @package pinpoint\Common
*/
abstract class ClassFile
abstract class AbstractClassFile
{
public $appendingFile = array();

public $node;

protected $prefix;
public $newAstNode;

public $npStr;

public $className=''; /// Foo\A Foo\B
public $className = ''; /// Foo\A Foo\B

public $traitName=''; /// trait Foo {}
public $traitName = ''; /// trait Foo {}

public $fileName=''; /// output file Name
public $fileName = ''; /// output file Name

public $myLoaderName=''; /// output name
public $myLoaderName = ''; /// output name

public $classMethod;

Expand All @@ -62,45 +63,42 @@ abstract class ClassFile

public $hasRet;

public $fileNode;

protected $_astPrinter;

public $namespace='';
public $namespace = '';

public function __construct($prefix)
public function __construct()
{
$this->prefix = $prefix;
$this->_astPrinter = new PrettyPrinter\Standard();
}

public function getNode()
{
return $this->node;
}
// public function getNode()
// {
// return $this->node;
// }

public function handleEnterNamespaceNode(&$node)
public function handleEnterNamespaceNode($node)
{
assert($node instanceof Node\Stmt\Namespace_);
$this->namespace = trim($node->name->toString());
}

public function handleEnterClassNode(&$node)
public function handleEnterClassNode($node)
{
assert($node instanceof Node\Stmt\Class_);
if($this->namespace)
{
$this->className = trim($this->namespace.'\\'.$node->name->toString());
}else{
if ($this->namespace) {
$this->className = trim($this->namespace . '\\' . $node->name->toString());
} else {
$this->className = trim($node->name->toString());
}
}

public function handleEnterTraitNode(&$node)
{
assert($node instanceof Node\Stmt\Trait_);
if($this->namespace)
$this->traitName = trim($this->namespace.'\\'.$node->name->toString());
if ($this->namespace)
$this->traitName = trim($this->namespace . '\\' . $node->name->toString());
else
$this->traitName = trim($node->name->toString());
}
Expand All @@ -109,34 +107,37 @@ public function handleClassEnterMethodNode(&$node)
{
assert($node instanceof Node\Stmt\ClassMethod);
$this->funcName = $node->name->toString();
$this->classMethod =$this->className.'::'.$this->funcName;
$this->classMethod = $this->className . '::' . $this->funcName;
$this->hasRet = false;
}

abstract function handleLeaveMethodNode(&$node);

public function markHasReturn(&$node)
{
if(isset($node->expr))
{
if (isset($node->expr)) {
$this->hasRet = true;
}
}

public function markHasYield(&$node)
public function markHasYield()
{
$this->hasRet = true;
}

public function fileNodeDoneCB(&$node, $loaderName)
public function done()
{
$fullPath = AOP_CACHE_DIR.'/'.str_replace('\\','/',$loaderName).'.php';
$context= $this->_astPrinter->prettyPrintFile($node);
RenderAopClass::getInstance()->insertMapping($loaderName,$fullPath);
Utils::saveObj($context,$fullPath);
$fullPath = AOP_CACHE_DIR . '/' . str_replace('\\', '/', $this->className) . '.php';
$context = $this->_astPrinter->prettyPrintFile($this->newAstNode);
MonitorClass::getInstance()->insertMapping($this->className, $fullPath);
Logger::Inst()->debug("map/save new class '$this->className' to '$fullPath' ");
Utils::saveObj($context, $fullPath);
}

abstract function handleAfterTravers(&$nodes);
abstract function handleLeaveNamespace(&$nodes);
abstract function handlerUseNode(&$node);
abstract function handleAfterTraverse($nodes);
abstract function handleLeaveNamespace($nodes);
abstract function handlerUseNode($node);
abstract function handleLeaveMethodNode($node);
abstract function handleEnterClassConstFetch($node);
abstract function handleEnterNew($node);
abstract function handleEnterFuncCall($node);
abstract function handleLeaveClassNode($node);
}
Loading