xp-framework / scriptlet
此软件包已被废弃且不再维护。没有建议的替代软件包。
XP Framework 的 Scriptlets
v9.2.2
2018-08-24 23:23 UTC
Requires
- php: >=5.6.0
- xp-framework/core: ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/http: ^9.0 | ^8.0 | ^7.0 | ^6.2
- xp-framework/logging: ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/mail: ^8.0 | ^7.0 | ^6.1
- xp-framework/networking: ^9.0 | ^8.0 | ^7.0 | ^6.6
- xp-framework/rdbms: ^12.0 | ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/xml: ^9.0 | ^8.0 |^7.0 | ^6.3
Requires (Dev)
- xp-framework/unittest: ^9.0 | ^8.0 | 7.0 | ^6.5
- dev-master
- v9.2.2
- v9.2.1
- v9.2.0
- v9.1.1
- v9.1.0
- v9.0.0
- v8.5.0
- v8.4.6
- v8.4.5
- v8.4.4
- v8.4.3
- v8.4.2
- v8.4.1
- v8.4.0
- v8.3.3
- v8.3.2
- v8.3.1
- v8.3.0
- v8.2.5
- v8.2.4
- v8.2.3
- v8.2.2
- v8.2.1
- v8.2.0
- v8.1.2
- v8.1.1
- v8.1.0
- v8.0.2
- v8.0.1
- 8.0.0.x-dev
- v8.0.0
- v7.1.0
- v7.0.1
- 7.0.0.x-dev
- v7.0.0
- v6.3.2
- v6.3.1
- v6.3.0
- v6.2.3
- v6.2.2
- v6.2.1
- v6.2.0
- v6.1.0
- v6.0.3
- v6.0.2
- v6.0.0
- v2.0.1
- dev-cancel-in-setup
- dev-feature/routing
- dev-web-debugging
This package is auto-updated.
Last update: 2020-08-29 04:49:10 UTC
README
在 XP Framework 中运行的任何网页都是脚本,最初都是这样的。每个高级 API 都是从简单的 HttpScriptlet
类派生出来的:RestScriptlet
、WorkflowScriptlet
等...
HttpScriptlet 类
scriptlet.HttpScriptlet
类是任何所谓脚本的基础类。脚本是可以处理 HTTP 请求的东西。
在 XP Framework 中以最简单的方式响应 HTTP 请求如下
namespace com\example\web; class HelloScriptlet extends \scriptlet\HttpScriptlet { /** * Perform GET request * * @param scriptlet.Request $request * @param scriptlet.Response $response * @throws scriptlet.ScriptletException */ public function doGet($request, $response) { $response->write(sprintf('<!DOCTYPE html> <html> <head><title>Hello World scriptlet</title></head> <body> <h1>Hello %s</h1> </body> </html>', htmlspecialchars($request->getParam('name', 'World')) )); } }
此代码生成一个显示标题 "Hello World" 或 "Hello $something" 的 HTML 页面,前提是提供了名为 "name" 的 GET 参数。
覆盖 doPost()
或其他以 HTTP 请求类型命名的任何方法,以提供这些请求类型。
运行它
使用 xp web
运行器来运行您的脚本
$ xp web com.example.web.HelloScriptlet [xpws-dev#7312] running localhost:8080 @ /path/to/web/project - Press <Enter> to exit
现在在您的浏览器中打开 http://localhost:8080/