Skip to content

Commit 02cb27c

Browse files
committed
document for v2.1.0
1 parent bb66784 commit 02cb27c

File tree

7 files changed

+47
-53
lines changed

7 files changed

+47
-53
lines changed

Changes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Changes
22

3+
### v2.1.0
4+
5+
* remove setting.ini
6+
* AspectClassHandle api
7+
8+
39
### v2.0.2
410
* support thinkphp5.0.x
511
* support all-in-one

Readme.md

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,84 +6,74 @@ https://github.com/pinpoint-apm/pinpoint-c-agent/labels/php-aop
66

77
## How to Use
88

9-
### Import from packagist
9+
### 1. Import from packagist
1010

1111
Add requirement into composer.json
1212

1313
```Json
1414
"require": {
15-
"pinpoint-apm/pinpoint-php-aop": "dev-master"
15+
"pinpoint-apm/pinpoint-php-aop": "v2.1.0"
1616
}
1717
```
1818

19-
### Write your plugins
20-
This is a plugin template for reference.
19+
### 2. Write your plugins
20+
21+
> UserPlugin
2122
2223
```php
23-
/// Placing "///@hook:" here: aop on function(method) on before,end and Exception
24-
///@hook:app\AppDate::output
25-
class CommonPlugin
24+
use Pinpoint\Common\AbstractMonitor;
25+
class UserPlugin extends AbstractMonitor
2626
{
27-
//$apId: The function(method) name
28-
//$who: If watching a method, $who is that instance
29-
//$args: array parameters $argv = $args[0]
30-
public function __construct($apId,$who,&...$args){
31-
// $this->argv = $args[0];
32-
// $this->funName =$apId;
33-
// $this->instance = $who;
34-
}
35-
// watching before
36-
///@hook:app\DBcontrol::connectDb
3727
public function onBefore(){
3828

3929
}
40-
41-
// watching after
42-
///@hook:app\DBcontrol::getData1 app\DBcontrol::\array_push
4330
public function onEnd(&$ret){
4431

4532
}
46-
47-
// Exception
48-
///@hook:app\DBcontrol::getData2
4933
public function onException($e){
5034
}
5135
}
5236
```
37+
>eg: [OutputMonitor example](lib/Pinpoint/test/OutputMonitor.php)
38+
39+
### 3. Register UserPlugin on target class
40+
41+
```php
42+
use Pinpoint\Common\AspectClassHandle;
43+
...
44+
$classHandler = new AspectClassHandle(\namespace\Abc::class);
45+
$classHandler->addJoinPoint('parseRequest', \UserPlugin::class);
46+
```
47+
48+
### Here is the example for yii framework
49+
50+
For yii2, [Yii2PerRequestPlugins example](lib/Pinpoint/Plugins/Yii2PerRequestPlugins.php)
5351

54-
### Activate plugins
55-
This could be found in PHP/pinpoint_php_example/app/index.php.
5652

5753
``` php
5854
<?php
5955

6056
require_once __DIR__."/../vendor/autoload.php";
6157

6258
// A writable path for caching AOP code
63-
define('AOP_CACHE_DIR',__DIR__.'/../Cache/');
64-
// since 0.2.5+ PINPOINT_USE_CACHE = N, auto_pinpointed.php will generate Cache/* on every request.
65-
define('PINPOINT_USE_CACHE','YES');
66-
// Use pinpoint-php-aop auto_pinpointed.php instead of vendor/autoload.php
67-
require_once __DIR__. '/../vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
59+
define('AOP_CACHE_DIR',__DIR__.'/../Cache/');
60+
// API for register your own plugins eg: \Pinpoint\Plugins\Yii2PerRequestPlugins::class
61+
define('PP_REQ_PLUGINS', \Pinpoint\Plugins\Yii2PerRequestPlugins::class);
62+
// require auto_pinpointed, it must located after other loads
63+
require_once __DIR__. '/vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
6864

6965
```
70-
#### setting.ini
71-
72-
Namespace conversion table for special class/function
73-
74-
> How to use?
75-
76-
[setting.ini](lib/Pinpoint/test/setting.ini)
77-
78-
7966

8067

8168
### How it works
8269

8370
* Use `nikic/PHP-Parser` generating glue layer code
84-
8571
* Use namespace replace to reuse plugins or hook build-in class/function
86-
* Intercept php classloader to redirect origin class bettween proxied class
72+
* Intercept php classloader to redirect origin class to new class
73+
74+
75+
###
76+
8777

8878

8979
> pinpoint-php-aop wrappers your class with an onBefore/onEnd/onException suite.
@@ -95,7 +85,9 @@ Namespace conversion table for special class/function
9585
More details please go to lib/pinpoint/test/Comparison/pinpoint/test
9686

9787

98-
> PS: If you found a bug, please create an issue to us without any hesitate.
88+
#### Needs Help/Issues
89+
90+
[create an issue](https://github.com/pinpoint-apm/pinpoint-c-agent/issues/new?assignees=eeliu&labels=PHP-AGENT&projects=&template=-php--custom-issue-template.md&title=%5BFeat%5D+I+need+a+feature+...)
9991

10092

10193
## Copyright

lib/Pinpoint/Common/PerRequestDefault.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public function __construct()
2727
}
2828
public function joinedClassSet(): array
2929
{
30+
// add your AspectClassHandle here
31+
// $classHandler = new AspectClassHandle(\yii\web\UrlManager::class);
32+
// $classHandler->addJoinPoint('parseRequest', \Pinpoint\Plugins\yii2\UrlRule::class);
33+
// $cls[] = $classHandler;
34+
// return $cls;
3035
return [];
3136
}
3237

lib/Pinpoint/Common/PinpointDriver.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,5 @@ public function start()
9090
}
9191
// save render aop class into index file
9292
Utils::saveCachedClass(MonitorClass::getInstance()->getJointClassMap());
93-
// enable RenderAop class loader
94-
// MonitorClassLoader::start();
9593
}
9694
}

lib/Pinpoint/Common/Utils.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ public static function scanDir($dir, $pattern, &$tree)
5353
public static function checkCacheReady(): bool
5454
{
5555
$cachePath = static::U_INDEX_FILE_PATH;
56-
$useCache = defined('PINPOINT_USE_CACHE') && PINPOINT_USE_CACHE;
57-
Logger::Inst()->debug("cachePath:'$cachePath' useCache '$useCache' ");
58-
return (defined('PINPOINT_USE_CACHE') &&
59-
PINPOINT_USE_CACHE) &&
60-
file_exists(static::U_INDEX_FILE_PATH);
56+
Logger::Inst()->debug("cachePath:'$cachePath'");
57+
return file_exists($cachePath);
6158
}
6259

6360
public static function loadCachedClass(): array

lib/Pinpoint/Plugins/Yii2PerRequestPlugins.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
use Pinpoint\Common\AspectClassHandle;
2525
use Pinpoint\Common\Logger;
2626

27-
28-
29-
3027
class Yii2PerRequestPlugins extends PinpointPerRequestPlugins implements UserFrameworkInterface
3128
{
3229
// private $_yiiLoader = array();

lib/Pinpoint/test/bearRun.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
require_once './bootstrap.php';
66

77
define('AOP_CACHE_DIR', __DIR__ . '/Cache');
8-
define('PINPOINT_USE_CACHE', true);
98
define('APPLICATION_NAME', 'ci-test');
109

1110
require_once __DIR__ . '/../../../auto_pinpointed.php';

0 commit comments

Comments
 (0)