function setUp() { $this->postModule = FunctionalChatPostModule::standard(); $this->settings = new FunctionalChatSettings($this->postModule, __DIR__ . '/test_chat.json', __DIR__ . '/test_chat.lock', 10); $this->params1 = array('room' => 'myplace', 'chatter' => 'Joe', 'message' => 'Test message'); $this->now = $_SERVER['REQUEST_TIME']; $this->post1 = new FunctionalChatPost('Ramona', 'myroom', 'Hello', $this->now); $this->chat = new PhpFunctionalChat(); $request1_e = MyChatRequest::fromParams($this->params1); if ($request1_e->isRight()) { $this->request1 = $request1_e->fromRight(); } }
return Either::left("Missing required parameter \"room\""); } else { return Either::right($params); } } } protected static function fromValidParams(array $params) { return new MyChatRequest($params['user'], $params['room'], $params['message']); } } if (!empty($_POST)) { $_POST['room'] = 'myplace'; $chat = new PhpFunctionalChat(); $settings = new FunctionalChatSettings(FunctionalChatPostModule::standard(), __DIR__ . '/chat.json', __DIR__ . '/tmp/php_chat.lock', 10); $eRequest = MyChatRequest::fromParams($_POST); if ($eRequest->isLeft()) { $eResult = $eRequest; } else { $eResult = $chat->receivePostIO($eRequest->fromRight(), $settings); } if ($eResult->isLeft()) { header('HTTP/1.0 500 Internal Server Error'); echo $eResult->fromLeft(); } else { header('Cache-Control: no-cache, must-revalidate'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); readfile($settings->chat_file); } }