Merge branch '1-log-get-parameters-for-callbacks' into 'master'
Resolve "Log GET parameters for callbacks." Closes #1 See merge request pnx/httpcb!1
This commit is contained in:
commit
dd71d0b600
7 changed files with 173 additions and 4 deletions
|
|
@ -28,6 +28,7 @@
|
|||
@import "layout/footer";
|
||||
|
||||
// Components
|
||||
@import "components/url";
|
||||
@import "components/icon";
|
||||
@import "components/button";
|
||||
@import "components/badge";
|
||||
|
|
|
|||
|
|
@ -35,13 +35,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
&-index {
|
||||
&-uri {
|
||||
display: inline-block;
|
||||
width: 45%;
|
||||
}
|
||||
|
||||
&-size {
|
||||
display: inline-block;
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
&-type,
|
||||
&-size,
|
||||
&-timestamp {
|
||||
display: inline-block;
|
||||
width: 20%;
|
||||
|
|
|
|||
8
app/assets/less/components/url.less
Normal file
8
app/assets/less/components/url.less
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
.url {
|
||||
|
||||
&-query,
|
||||
&-fragment {
|
||||
color: #9c9c9c;
|
||||
}
|
||||
}
|
||||
|
|
@ -136,6 +136,8 @@ class CallbackController extends ControllerBase
|
|||
$meta = new Model\Data\RequestMeta();
|
||||
$meta->Callback = $callback;
|
||||
$meta->RequestObject = $request;
|
||||
$meta->setUri($this->request->getServer('REQUEST_URI'));
|
||||
|
||||
$result = $meta->save();
|
||||
if ($result == false) {
|
||||
var_dump($meta->getMessages());
|
||||
|
|
|
|||
69
app/library/ViewHelper/UrlStyle.php
Normal file
69
app/library/ViewHelper/UrlStyle.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace ViewHelper;
|
||||
|
||||
/**
|
||||
* Class UrlStyle
|
||||
*
|
||||
* Tags diffrent parts in a url around <span> tags with class names.
|
||||
*
|
||||
* classes/parts are:
|
||||
* scheme
|
||||
* host
|
||||
* port
|
||||
* path
|
||||
* query
|
||||
* fragment
|
||||
*
|
||||
* @package ViewHelper
|
||||
*/
|
||||
class UrlStyle extends AbstractHelper
|
||||
{
|
||||
/**
|
||||
* Prefix (or namespace) for css classes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_classPrefix = 'url-';
|
||||
|
||||
public function urlStyle($url)
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
|
||||
if ($parts === null) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$xhtml = '';
|
||||
|
||||
if (isset($parts['scheme'])) {
|
||||
$xhtml .= $this->_htmlElement('scheme', $parts['scheme'] . '://');
|
||||
}
|
||||
|
||||
if (isset($parts['host'])) {
|
||||
$xhtml .= $this->_htmlElement('host', $parts['host']);
|
||||
}
|
||||
|
||||
if (isset($parts['port'])) {
|
||||
$xhtml .= $this->_htmlElement('port', ':' . $parts['port']);
|
||||
}
|
||||
|
||||
$xhtml .= $this->_htmlElement('path', $parts['path']);
|
||||
|
||||
if (isset($parts['query'])) {
|
||||
$xhtml .= $this->_htmlElement('query', '?' . $parts['query']);
|
||||
}
|
||||
|
||||
if (isset($parts['fragment'])) {
|
||||
$xhtml .= $this->_htmlElement('fragment', '#' . $parts['fragment']);
|
||||
}
|
||||
|
||||
return $xhtml;
|
||||
}
|
||||
|
||||
protected function _htmlElement($class, $content)
|
||||
{
|
||||
$class = $this->_classPrefix . $class;
|
||||
return '<span class="' . $class . '">' . $content . '</span>';
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,20 @@ class RequestMeta extends Model
|
|||
*/
|
||||
protected $callbackid;
|
||||
|
||||
/**
|
||||
* HTTP Request Uri
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $uri;
|
||||
|
||||
/**
|
||||
* Cached query parameters from request uri.
|
||||
*
|
||||
* @var array|null
|
||||
*/
|
||||
protected $_uri_query = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
|
|
@ -65,6 +79,50 @@ class RequestMeta extends Model
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $uri
|
||||
* @return RequestMeta
|
||||
*/
|
||||
public function setUri($uri)
|
||||
{
|
||||
$this->uri = (string) $uri;
|
||||
|
||||
// New uri string, invalidate query.
|
||||
$this->_uri_query = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getUriQuery()
|
||||
{
|
||||
if ($this->_uri_query === null) {
|
||||
|
||||
$query = (string) parse_url($this->getUri(), PHP_URL_QUERY);
|
||||
|
||||
$ret = array();
|
||||
foreach(explode('&', $query) as $v) {
|
||||
@list($k, $v) = explode('=', $v, 2);
|
||||
if (strlen($k) > 0) {
|
||||
$ret[$k] = $v;
|
||||
}
|
||||
}
|
||||
$this->_uri_query = $ret;
|
||||
}
|
||||
|
||||
return $this->_uri_query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to set the value of field Timestamp
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
data-toggle="collapse" data-parent="#request-log"
|
||||
aria-expanded="true" aria-controls="request{{ index }}">
|
||||
|
||||
<span class="request-list-item-header-index">
|
||||
#{{ index + 1 }}
|
||||
<span class="request-list-item-header-uri">
|
||||
{{ icon('android-locate') }} <span class="url">{{ urlStyle(req.getUri()) }}</span>
|
||||
</span>
|
||||
|
||||
<span class="request-list-item-header-timestamp">
|
||||
|
|
@ -36,6 +36,33 @@
|
|||
|
||||
<div class="request-list-item-detail">
|
||||
|
||||
{% if req.getUriQuery()|length > 0 %}
|
||||
|
||||
<button class="request-list-item-detail-button" type="button"
|
||||
data-toggle="collapse" data-target="#query{{ index }}"
|
||||
aria-expanded="false" aria-controls="query{{ index }}">
|
||||
Query
|
||||
</button>
|
||||
|
||||
<div class="collapse in" id="query{{ index }}">
|
||||
<table class="request-list-item-detail-headers">
|
||||
<thead>
|
||||
<th class="request-list-item-detail-headers-key">Key</th>
|
||||
<th class="request-list-item-detail-headers-value">Value</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key, val in req.getUriQuery() %}
|
||||
<tr>
|
||||
<td><strong>{{ key|e }}</strong></td>
|
||||
<td>{{ val|e }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
<button class="request-list-item-detail-button" type="button"
|
||||
data-toggle="collapse" data-target="#headers{{ index }}"
|
||||
aria-expanded="false" aria-controls="headers{{ index }}">
|
||||
|
|
|
|||
Reference in a new issue