Make *Processor handles Symfony requests

This commit is contained in:
Dmitriy Simushev 2014-08-27 13:22:43 +00:00
parent 8b1b38dddc
commit 730dd2f2df
4 changed files with 26 additions and 5 deletions

View File

@ -40,7 +40,7 @@ class ThreadController extends AbstractController
// TODO: Remove bufferization after *Processor classes will be rewritten
// to play nice with symfony request/response objects
ob_start();
$processor->receiveRequest($request->request->get('data'));
$processor->handleRequest($request);
$content = ob_get_clean();
return $content;

View File

@ -94,7 +94,7 @@ class UsersController extends AbstractController
// TODO: Remove bufferization after *Processor classes will be rewritten
// to play nice with symfony request/response objects
ob_start();
$processor->receiveRequest($request->request->get('data'));
$processor->handleRequest($request);
$content = ob_get_clean();
return $content;

View File

@ -23,6 +23,7 @@ namespace Mibew\RequestProcessor;
use Mibew\Database;
use Mibew\EventDispatcher;
use Mibew\RequestProcessor\Exception\AbstractProcessorException;
use Symfony\Component\HttpFoundation\Request;
/**
* Implements abstract class for request processing
@ -153,12 +154,13 @@ abstract class AbstractProcessor
* On any error function returns only boolean false. To handle error add
* listener to the "<eventPrefix>RequestError" event.
*
* @param string $package Encoded package
* @param Request $request The request to handle.
* @return boolean true if request processed succussfully or false on
* failure
*/
public function receiveRequest($package)
public function handleRequest($request)
{
$package = $this->extractPackage($request);
$dispatcher = EventDispatcher::getInstance();
// Try to handle request
try {
@ -593,4 +595,12 @@ abstract class AbstractProcessor
* @return \Mibew\API\API
*/
abstract protected function getMibewAPIInstance();
/**
* Extrats a package from an request.
*
* @param Request $request The request to extract package from.
* @return string Encoded package.
*/
abstract protected function extractPackage(Request $request);
}

View File

@ -19,8 +19,8 @@
namespace Mibew\RequestProcessor;
// Import namespaces and classes of the core
use Mibew\Database;
use Symfony\Component\HttpFoundation\Request;
/**
* Base class for all request processors that interact with JavaScript
@ -120,4 +120,15 @@ abstract class ClientSideProcessor extends AbstractProcessor
return $result;
}
/**
* Extrats a package from an request.
*
* @param Request $request The request to extract package from.
* @return string Encoded package.
*/
protected function extractPackage(Request $request)
{
return $request->request->get('data');
}
}