Created
October 31, 2011 15:41
-
-
Save FrancisVarga/1327784 to your computer and use it in GitHub Desktop.
foobar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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