143 lines
3.8 KiB
PHP
143 lines
3.8 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 25/giu/2015
|
|
*/
|
|
|
|
/**
|
|
* Request example:
|
|
* {
|
|
* version: ${protocol_version},
|
|
* account: ${acc_id},
|
|
* user: ${user_id},
|
|
* time: ${timestamp_microseconds},
|
|
* msg_id: ${request_id},
|
|
* digest: ${digest},
|
|
* details: ${request}
|
|
* }
|
|
* @author Riccardo Di Dato
|
|
*
|
|
*/
|
|
class RAPI_Request extends RAPI_Message{
|
|
/*
|
|
* Attributi, setters e getters
|
|
*/
|
|
/**
|
|
* Account utilizzato per la richiesta
|
|
* @var string
|
|
*/
|
|
private $account;
|
|
public function getAccount(){
|
|
return $this->account;
|
|
}
|
|
|
|
/**
|
|
* Utente dell'account
|
|
* @var string
|
|
*/
|
|
private $user;
|
|
public function getUser(){
|
|
return $this->user;
|
|
}
|
|
|
|
/**
|
|
* Identificativo della richiesta (NULL in lettura)
|
|
* @var string
|
|
*/
|
|
private $operationId;
|
|
public function getOperationId(){
|
|
return $this->operationId;
|
|
}
|
|
|
|
/*
|
|
* Metodi propri della classe
|
|
*/
|
|
/**
|
|
* @param string $account Il token dell'account che fa la richiesta
|
|
* @param string $user L'identificativo dell'utente (collegato all'account) che fa la richiesta
|
|
* @param string $operationId Identificativo univoco del messaggio. UTILIZZARE SOLO IN SCRITTURA, IN LETTURA UTILIZZARE null
|
|
* @param string $protocolVersion La versione del protocollo RAPI
|
|
* @param RAPI_RequestDetails $details Il contenuto della richiesta
|
|
* @param int $time Timestamp in microsecondi
|
|
* @param string $digest Digest per valutare l'autenticità del messaggio
|
|
*/
|
|
public function __construct($account, $user, $operationId, $protocolVersion, RAPI_RequestDetails $details, $time = null, $digest = null){
|
|
parent::__construct($protocolVersion, $details, $time, $digest);
|
|
$this->account = $account;
|
|
$this->user = $user;
|
|
$this->operationId = $operationId;
|
|
}
|
|
|
|
/**
|
|
* Metodo di utility che richiama il metodo omonimo del request details.
|
|
* Se una delle request è un checksumFake confronta solo i due checksum.
|
|
* @param RAPI_Request $req
|
|
* @return boolean
|
|
*/
|
|
public function isEqual(RAPI_Request $req){
|
|
return strcmp($this->getProtocolVersion(),$req->getProtocolVersion())==0 &&
|
|
strcmp($this->account,$req->account)==0 &&
|
|
strcmp($this->user,$req->user)==0 &&
|
|
strcmp($this->operationId,$req->operationId)==0 &&
|
|
$this->getDetails()->isEqual($req->getDetails());
|
|
}
|
|
|
|
/**
|
|
* Metodo di utility che richiama il metodo omonimo del request details.
|
|
* @return bool
|
|
*/
|
|
public function isChecksumFake(){
|
|
return $this->getDetails()->isChecksumFake();
|
|
}
|
|
|
|
/**
|
|
* Genera la versione checksumFake della rapi request.
|
|
* @return RAPI_Request
|
|
*/
|
|
public function generateChecksumFake(){
|
|
$rval = new RAPI_Request($this->account, $this->user, $this->getOperationId(), $this->getProtocolVersion(), $this->getDetails()->generateChecksumFake(), $this->getTime(), $this->getDigest());
|
|
return $rval;
|
|
}
|
|
|
|
/*
|
|
* Abstract Implementations
|
|
*/
|
|
/**
|
|
* @see RAPI_Message::generateEncryptionObject()
|
|
*/
|
|
protected function generateEncryptionObject(){
|
|
$rval = $this->generateEncryptionBaseObject();
|
|
$rval->account = $this->account;
|
|
$rval->user = $this->user;
|
|
$rval->operationId = $this->operationId;
|
|
|
|
return $rval;
|
|
}
|
|
|
|
/**
|
|
* @see RAPI_Message::isValidObjectForCreation()
|
|
*/
|
|
protected static function isValidObjectForCreation($obj){
|
|
return self::isValidObjectForCreationBase($obj) &&
|
|
property_exists($obj, "account") &&
|
|
property_exists($obj, "user") &&
|
|
property_exists($obj, "operationId");
|
|
}
|
|
|
|
/**
|
|
* @see RAPI_Message::createFromObject()
|
|
*/
|
|
public static function createFromObject($obj){
|
|
if (self::isValidObjectForCreation($obj)){
|
|
$details = RAPI_RequestDetailsFactory::generateFromEncryptionObject($obj->details);
|
|
return new RAPI_Request($obj->account, $obj->user, $obj->operationId, $obj->version, $details, $obj->time, $obj->digest);
|
|
}
|
|
else {
|
|
throw new RAPI_Exception("Invalid request format");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
?>
|