Comments (4)
可以这么传递
HOOK
/**
* @param({"myVal", "$.myVal"}) onHook将会设置myVal的值,myVal是你自己命名的变量
*/
public function onHook(&$myVal){ //注意这里是引用&
$myVal= xxxx; //设置需要传递的值
}
API
/**
* @param({"myVal", "$.myVal"}) 获取hook设置的值
*/
public function onApi($myVal){
// 这里就可以去处理myVal了
}
from phpboot.
这个方案稍显繁琐,每个api都要声明。
from phpboot.
如果想在某个类的所以方法中都访问某变量,可以这么写,稍微简洁一点。不过不管怎么样,都需要声明,这也是phprs设计的初衷,希望“所有依赖都需要申明”。
/**
*/
public function onApi(){
$this->myVal // 这里就可以去处理myVal了
}
/** @inject("$.myVal") 此处将注入hook设置的myVal值*/
public $myVal;
from phpboot.
Good.
from phpboot.
Related Issues (20)
- 路由算法需要增加严格匹配模式 HOT 13
- 如何定义文件传输的接口呢? HOT 4
- Exceptions throwed by hook, can't be catched. HOT 1
- create \PDO with IoCFactory failed
- cannot extract the “0” node from url path
- how to create the database table for example/users? HOT 1
- 如何自定义配置段 HOT 1
- 求助,"error":"phprs\\util\\exceptions\\NotFound","message HOT 1
- How about add 401 unAuth error response HOT 2
- 想做一个签名校验 HOT 2
- undue sql wrap with ``
- 有版本功能吗? HOT 2
- 想问一下如何添加根据路径的hook HOT 1
- 找不到类的报错 HOT 2
- Class App\Controllers\Books does not exist HOT 1
- 请问RPC调用如何设置超时时间?
- 支持mongodb数据库吗 HOT 2
- 关于APC扩展
- How to access custom values defined in config.php
- conf.json 可能泄漏 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpboot.