public function testBrowse() { $deal = new Deal(); $storage = new Mongo($deal->settings()); $list = $storage->browse(); $this->assertCount(0, $list); $storage->create('foo', 'bar'); $list = $storage->browse(); $this->assertCount(1, $list); $this->assertCount(2, $list[0]); $this->assertEquals('foo', $list[0]['key']); $this->assertEquals('bar', $list[0]['secret']); }
public function delete($id) { try { $record = $this->model->getOne($id); if (empty($record)) { $status = 400; $this->badRequest('Id ' . $id . ' does not exist', $status); } else { $delete = $this->model->removeRecord($id); try { // The Deal instance already has all our settings. So, let's use // that instance to get them and inform the queue about them, // Then he use it to create connections/channels to the queue. He can // also pass along that config to workers who can then create their // own db connections which are needed for models, etc. $queue = new Queue($this->app->settings()); $queue->push(get_class($this->model), $id, 'delete', [], [], $record); } catch (ValidationException $e) { $status = 400; $this->badRequest($e->getMessage(), $status); } } } catch (ValidationException $e) { $status = 400; $this->badRequest($e->getMessage(), $status); } catch (InvalidException $e) { $status = 405; $this->badRequest($e->getMessage(), $status); } // since this is an immediate delete and we return information, 200 is correct response return compact('delete'); }
public static function getHandler() { return function () { $app = Deal::getInstance(); $app->halt(404, 'Endpoint not found.'); }; }
public function call() { // Run inner middleware and application $this->next->call(); // Get reference to application $app = Deal::getInstance(); // set the content type $app->response()->header('Content-type', 'application/json'); $res = $app->response(); $body = $res->body(); // serialized? if (preg_match('/^([adObis]):/', $body)) { $body = unserialize($body); } if (is_scalar($body)) { $body = array('response' => $body); } $encode = json_encode($body, JSON_UNESCAPED_SLASHES); $app->response()->body($encode); }
public function testGetDefaultSettings() { $settings = Deal::getDefaultSettings(); $this->assertEquals('\\Deal\\Middleware\\Output\\Json', $settings['api.classes.output']); $this->assertEquals('\\Deal\\Middleware\\Auth', $settings['api.classes.auth']); $this->assertEquals('\\Deal\\Middleware\\Auth\\Storage\\None', $settings['api.classes.auth.storage']); $this->assertEquals('\\Deal\\Middleware\\Auth\\None', $settings['api.classes.auth.adapter']); $this->assertEquals(array('\\App\\Controller'), $settings['app.controllers.paths']); $this->assertEquals(array('\\App\\Model'), $settings['app.models.paths']); }
public static function getHandler() { return function (\Exception $e) { Deal::getInstance()->halt(500, $e->getMessage() . ' - ' . $e->getTraceAsString()); }; }
public function loadCustomRoutes() { $this->get('/', Deal::getAuthMiddleware($this), function () { Deal::getInstance()->halt('200', 'ok'); }); }