created mocks for testing
This commit is contained in:
BIN
src/Webservice/.WebService.php.swp
Normal file
BIN
src/Webservice/.WebService.php.swp
Normal file
Binary file not shown.
BIN
src/Webservice/Exception/.UsageException.php.swp
Normal file
BIN
src/Webservice/Exception/.UsageException.php.swp
Normal file
Binary file not shown.
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace BSR\Webservice\Formatter;
|
||||
|
||||
abstract class Formatter {
|
||||
@@ -8,16 +7,27 @@ abstract class Formatter {
|
||||
/**
|
||||
* @param array $formats New available formats, array(mimetype => class)
|
||||
*/
|
||||
protected static function registerFormats(array $formats) {
|
||||
protected static function registerFormats(array $formats)
|
||||
{
|
||||
foreach($formats as $f) {
|
||||
self::$formats[$f] = get_called_class();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See loadFormatters() init()
|
||||
* @return array of registered formats by subclasses on init()
|
||||
*/
|
||||
public static function getRegisterdFormats()
|
||||
{
|
||||
return self::$formats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Formatter The formatter to use for this request
|
||||
*/
|
||||
public static function getFormatter() {
|
||||
public static function getFormatter()
|
||||
{
|
||||
self::loadFormatters();
|
||||
$format = self::getFormatFromHeader();
|
||||
|
||||
@@ -66,7 +76,6 @@ abstract class Formatter {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 'BSR\Webservice\Formatter\Json';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace BSR\Webservice\Formatter;
|
||||
|
||||
use BSR\Utils\Logger\Logger;
|
||||
@@ -132,7 +131,7 @@ class Html extends Formatter {
|
||||
'status' => 'info',
|
||||
);
|
||||
}
|
||||
$info = Logger::data();
|
||||
$info = Logger::getData();
|
||||
$context['time'] = $info['time'];
|
||||
|
||||
$panel = static::template($context, 'panel');
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace BSR\Webservice;
|
||||
|
||||
use BSR\Webservice\Exception\WebException;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace BSR\Webservice;
|
||||
|
||||
use BSR\Webservice\Formatter\Formatter;
|
||||
|
||||
class Renderer {
|
||||
class Renderer
|
||||
{
|
||||
private static $statusMessages = array(
|
||||
200 => 'Ok',
|
||||
400 => 'Bad request',
|
||||
@@ -13,13 +13,19 @@ class Renderer {
|
||||
500 => 'Server Error',
|
||||
);
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
ob_start();
|
||||
}
|
||||
|
||||
public function render($status, $data) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render($status, $data)
|
||||
{
|
||||
header(sprintf('HTTP/1.0 %s %s', $status, self::$statusMessages[$status]));
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
|
||||
ob_clean();
|
||||
flush();
|
||||
|
||||
|
||||
@@ -21,17 +21,19 @@ abstract class WebService
|
||||
/**
|
||||
* Treat the current request and output the result. This is the only
|
||||
* method that should be called on the webservice directly !
|
||||
* @param bool $sendSession needed for testing
|
||||
*/
|
||||
public function run()
|
||||
public function run($sendSession = true)
|
||||
{
|
||||
Logger::start(array('version' => $this->version));
|
||||
|
||||
$renderer = new Renderer();
|
||||
$rendererClass = Configuration::get('renderer.class', __NAMESPACE__ . '\Renderer');
|
||||
$renderer = new $rendererClass;
|
||||
|
||||
$data = array();
|
||||
|
||||
try {
|
||||
$result = $this->call();
|
||||
$result = $this->call($sendSession);
|
||||
$data["result"][$this->func] = $result;
|
||||
|
||||
// Logger::log(print_r($result, true));
|
||||
@@ -61,13 +63,16 @@ abstract class WebService
|
||||
* Determines which method to call based on GET or POST parameters and
|
||||
* call it before returning the result.
|
||||
*
|
||||
* @param bool $sendSession used for testing
|
||||
* @return array
|
||||
* @throws UsageException
|
||||
*/
|
||||
private function call()
|
||||
private function call($sendSession = true)
|
||||
{
|
||||
session_save_path(Configuration::get('session.save_path'));
|
||||
session_start();
|
||||
if ($sendSession) {
|
||||
session_save_path(Configuration::get('session.save_path'));
|
||||
session_start();
|
||||
}
|
||||
|
||||
$params = empty($_GET) ? $_POST : $_GET;
|
||||
if (empty($params)) {
|
||||
|
||||
Reference in New Issue
Block a user