heimrichhannot / contao-request
此包已被弃用,不再维护。作者建议使用 heimrichhannot/contao-request-bundle 包。
一个请求类,将 symfony/http-foundation 引入 contao。
1.5.0
2022-01-13 09:45 UTC
Requires
- php: ~5.4 || ~7.0 || ^8.0
- contao-community-alliance/composer-plugin: ~2.4 || ~3.0
- contao/core-bundle: ^3.5.1 || ~4.1
- symfony/http-foundation: >=2.7
- wa72/htmlpagedom: ^1.3 || ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.2
- phpunit/phpunit: ~5.6 || ~6.0
- satooshi/php-coveralls: ^1.0
README
Contao 使用自己的 Input
类,用于检查 $_GET、$_POST 以及更多参数。这是直接在 $_GET、$_POST 服务器参数上进行的,对于测试来说,无法模拟 HTTP-Server。在这里,HeimrichHannot\Request
通过 symfony/http-foundation
提供了模拟自己的 HTTP-Server 对象的功能。
技术说明
对于 contao 的 Input
或 Environment
调用,使用以下替代方案
Contao | 请求 |
---|---|
\Input::get($strKey) |
\HeimrichHannot\Request\Request::getGet($strKey) |
\Input::post($strKey) |
\HeimrichHannot\Request\Request::getPost($strKey) |
\Input::postHtml($strKey) |
\HeimrichHannot\Request\Request::getPostHtml($strKey) |
\Input::postRaw($strKey) |
\HeimrichHannot\Request\Request::getPostRaw($strKey) |
\Input::setPost($strKey, $varValue) |
\HeimrichHannot\Request\Request::setPost($strKey, $varValue) |
\Input::setGet($strKey, $varValue) |
\HeimrichHannot\Request\Request::setGet($strKey, $varValue) |
isset($_GET[$strKey]) |
\HeimrichHannot\Request\Request::hasGet($strKey) |
isset($_POST[$strKey]) |
\HeimrichHannot\Request\Request::hasPost($strKey) |
\Environment::get('isAjaxRequest') |
\HeimrichHannot\Request\Request::getInstance()->isXmlHttpRequest() |
插入标签
为了方便,我们提供了一些请求方法参数的插入标签。
**警告:如果您在 SQL 查询上下文中使用插入标签,请确保通过例如 prepare('field=?'')->execute('{{request_get::auto_item}}'')
使用转义来避免插入标签值**
插入标签 | 描述 |
---|---|
{{request_get::*}} |
此标签将被查询参数的 XSS 受保护值替换(将 * 替换为查询参数的名称,例如 auto_item ) |
{{request_post::*}} |
此标签将被 POST 参数的 XSS 受保护值替换(将 * 替换为 POST 参数的名称,例如 FORM_SUBMIT ) |