Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/models/Data/RequestMeta.php

194 lines
3.6 KiB
PHP

<?php
namespace Model\Data;
use Phalcon\Mvc\Model;
class RequestMeta extends Model
{
/**
*
* @var integer
*/
protected $id;
/**
*
* @var integer
*/
protected $callbackid;
/**
* HTTP Request Uri
*
* @var string
*/
protected $uri;
/**
*
* @var string
*/
protected $timestamp;
/**
* Initialize method for model.
*/
public function initialize()
{
$this->skipAttributes(array('request_object_id'));
$this->setSource('request_meta');
$this->useDynamicUpdate(true);
// Relationships
$this->belongsTo('callbackid', 'Model\Data\Callback', 'id', array('alias' => 'Callback'));
$this->hasOne('id', 'Model\Data\Request', 'id', array('alias' => 'RequestObject'));
}
/**
* Method to set the value of field id
*
* @param integer $id
* @return $this
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Method to set the value of field callbackid
*
* @param integer $callbackid
* @return $this
*/
public function setCallbackid($callbackid)
{
$this->callbackid = $callbackid;
return $this;
}
/**
* @return string
*/
public function getUri()
{
return $this->uri;
}
/**
* @param string $uri
* @return RequestMeta
*/
public function setUri($uri)
{
$this->uri = (string) $uri;
return $this;
}
/**
* Method to set the value of field Timestamp
*
* @param string $Timestamp
* @return $this
*/
public function setTimestamp($timestamp)
{
$this->timestamp = $timestamp;
return $this;
}
/**
* Returns the value of field id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Returns the value of field callbackid
*
* @return integer
*/
public function getCallbackid()
{
return $this->callbackid;
}
public function getSize()
{
$headers = $this->getHeaders();
foreach($headers as $k => $v) {
if ($k == 'Content-Length') {
return $v;
}
}
return 0;
}
public function getType()
{
$headers = $this->getHeaders();
foreach($headers as $k => $v) {
if ($k == 'Content-Type') {
return substr($v, strrpos($v, '/') + 1);
}
}
return 'Unknown';
}
public function getHeaders()
{
return $this->getRequestObject()->getHeaders();
}
public function getBody()
{
return $this->getRequestObject()->getBody();
}
/**
* Returns the value of field Timestamp
*
* @return string
*/
public function getTimestamp()
{
return $this->timestamp;
}
/**
* @param Callback $callback
* @param int $page
* @param int $limit
* @return \Phalcon\Paginator\AdapterInterface
*/
static public function getPaginator(Callback $callback, $page = 1, $limit = 30)
{
$builder = (new self())->getModelsManager()->createBuilder();
$builder->from('Model\Data\RequestMeta')
->where('callbackid = :cid:', array('cid' => $callback->getId()))
->orderBy('timestamp desc');
$paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(array(
'builder' => $builder,
'page' => $page,
'limit' => $limit
));
return $paginator;
}
}