Skip to content

Instantly share code, notes, and snippets.

@FrancisVarga
Created October 31, 2011 15:41
Show Gist options
  • Save FrancisVarga/1327784 to your computer and use it in GitHub Desktop.
Save FrancisVarga/1327784 to your computer and use it in GitHub Desktop.
foobar
<?php
namespace Processus\Abstracts\JsonRpc
{
/**
*
*/
abstract class AbstractJsonRpcServer
{
protected $_config;
protected $_request;
protected $_class;
// #########################################################
/**
* @param $class
* @return AbstractJsonRpcServer
*/
public function setClass($class)
{
$this->_class = $class;
return $this;
}
// #########################################################
public function handle()
{
}
// #########################################################
/**
* @param $request \Processus\Abstracts\JsonRpc\AbstractJsonRpcRequest
* @return AbstractJsonRpcServer
*/
public function setRequest($request)
{
$this->_request = $request;
return $this;
}
// #########################################################
/**
* @return bool
*/
public function hasNamespace()
{
if ($this->getRequest()->getSpecifiedNamespace()) {
return TRUE;
}
return FALSE;
}
// #########################################################
/**
* @return bool
*/
public function isValidMethod()
{
if (!empty($this->_config['validMethods']) &&
in_array($this->_request->getMethod(),
$this->_config['validMethods'])
) {
return TRUE;
}
return FALSE;
}
// #########################################################
/**
* @return bool
*/
public function isValidRequest()
{
if ($this->hasNamespace() && $this->isValidMethod()) {
return TRUE;
}
return FALSE;
}
// #########################################################
/**
* public run method
*/
public function run()
{
// if valid request let it handle via Zend\Json\Server\Server
if ($this->isValidRequest() === TRUE) {
$this->_run();
}
}
// #########################################################
/**
* internal run method
*/
protected function _run()
{
// set class
$this->setClass($this->getRequest()->getSpecifiedServiceClassName());
// Handle the request:
$this->handle();
}
/**
* @return \Core\Abstracts\JsonRpc\AbstractJsonRpcRequest
*/
public function getRequest()
{
return $this->_request;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment