Framework

This commit is contained in:
2018-12-19 21:29:53 +00:00
parent 0976e17030
commit 27944ac132
5 changed files with 54 additions and 6 deletions

19
src/Handlers.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
require 'MessageHandler.php';
class TestHandler implements MessageHandler
{
public function CanHandle($room_id, $msgid, $message): bool
{
// TODO: Implement canHandle() method.
return $msgid == 0;
}
public function Handle($room_id, $msgid, $message): string
{
// TODO: Implement handle() method.
return "uwu";
}
}

7
src/MessageHandler.php Normal file
View File

@@ -0,0 +1,7 @@
<?php
interface MessageHandler
{
public function CanHandle($room_id, $msgid, $message): bool;
public function Handle($room_id, $msgid, $message): string;
}

View File

@@ -10,7 +10,24 @@ define("INTER_ROOM", 111213);
// randomorg($start,$end); // randomorg($start,$end);
function reply_user($room_id, $msgid, $message) : string require 'Handlers.php';
$handlers = array(
new TestHandler()
);
function reply_user($room_id, $msgid, $message)
{ {
return $msgid; // Placeholder Globals
global $userid;
global $room_lang;
global $is_admin;
global $handlers;
foreach ($handlers as $handler) {
if($handler->CanHandle($room_id, $msgid, $message)) {
return $handler->Handle($room_id, $msgid, $message);
}
}
return ;
} }

View File

@@ -12,6 +12,6 @@ do {
$input = fread(STDIN, 80); // Read up to 80 characters or a newline $input = fread(STDIN, 80); // Read up to 80 characters or a newline
$trimmed = trim($input); $trimmed = trim($input);
echo '> ' , reply_user($room_id, $msg_id, $trimmed) , "\n"; echo $msg_id, ' > ' , reply_user($room_id, $msg_id, $trimmed) , "\n";
$msg_id++; $msg_id++;
} while($trimmed !== "exit"); } while($trimmed !== "exit");

View File

@@ -11,11 +11,16 @@ require '../src/entryPoint.php';
class Test extends TestCase class Test extends TestCase
{ {
public function testShouldReturnMessageID(): void public function testShouldNotNULLMessageID0(): void
{ {
$this->assertEquals( $this->assertNotNull(
'0',
reply_user('whatever', 0, 'whatever') reply_user('whatever', 0, 'whatever')
); );
} }
public function testShouldNULLMessageID1(): void
{
$this->assertNull(
reply_user('whatever', 1, 'whatever')
);
}
} }