$nick_max_chars) { return 'Your nickname is too long.'; } $text_max_chars = 4096; if (strlen($text) > $text_max_chars) { return 'Your message is too long. ' . strlen($text) . ' out of ' . $text_max_chars . ' characters.'; } if (empty(trim($text, ' '))) { return 'Message body cannot be empty.'; } return false; })(); if (!$errmsg) { if (count(WillyChat::$messages) > 10) { array_pop(WillyChat::$messages); } array_unshift(WillyChat::$messages, [ 'nick' => $nick, 'date' => time(), 'text' => $text ]); file_put_contents(WillyChat::$data_path, json_encode( WillyChat::$messages ) ); } $just_sent_message = true; } view('pages/willychat/index', [ 'nick' => $nick, 'just_sent_message' => $just_sent_message, 'errmsg' => $errmsg ]); }); Route::get('/willychat/messages', function() { view('pages/willychat/messages', [ 'messages' => WillyChat::$messages ]); }); Route::get('/willychat/sync', function() { json_response( hash('crc32', serialize(WillyChat::$messages)) ); });