public function render(Request $request, Response $response) { ob_start(); $file = 'templates/' . $this->template . 'Template.php'; include_once $file; $data = ob_get_clean(); $response->write($data); }
/** * Sets common parameters and arguments for all XSLT views and displays this view. * @param Request $request Request * @param Response $response Response */ public function display(Request $request, Response $response) { $this->proc->importStyleSheet($this->template); if ($this->resource != null) { $xml = Serializer::serialize($this->resource); $this->doc->loadXML($xml); } $xml = $this->proc->transformToXML($this->doc); $response->write($xml); }
function execute_request(Request $request, Response $response, $dispatchPath) { $dispatchList = (require $dispatchPath); $result = Dispatcher::dispatch($dispatchList, $request); if ($result[0] === false) { $response->set_status_code(404); $body = ErrorHandler::handleError(404, $request, 'Resource was not found'); $response->write($body); return $response; } else { return \PHPMachine\DecisionCore::handleRequest($result[0], $request, $response); } }
/** * 等待一段时间后跳转到指定url * 运行后仍然正常显示页面 * @param string $url 客户端跳转的URL绝对路径或者控制器路径<br>根目录控制器请开头补“/” * @param integer $time 延时时间 * @param mixed $data 带着数据跳转 */ public static function delay_to($url, $time = 5, $data = null) { $url = yyuc::url($url); if ($time == 0) { //纯JS跳转 Response::write("<script>location.href='" . $url . "';</script>", Mime::$htm); die; } else { $tzpam = ''; if (is_array($data)) { foreach ($data as $k => $v) { $tzpam .= "<input type='hidden' name='" . $k . "' value='" . htmlentities($v) . "'/>"; } } else { $tzpam = "<input type='hidden' name='yyuc_pam' value='1'/>"; } Response::write("<form action='" . $url . "' method='get' id='yyucform'>" . $tzpam . "</form><script>document.getElementById('yyucform').submit();</script>"); die; } }
<?php require_once 'inc/init.php'; $task_id = $_POST['task-status-id']; $date = strtotime($_POST['task-status']); $task = new Task(); $task->load('id = ?', [$task_id]); $task->status = $_POST['task-status']; if ($task->save()) { Response::write('message', 'Task status updated'); } else { Response::write('status', false); Response::write('message', 'Task status failed to update.'); } Response::output();
<?php require_once 'inc/init.php'; $task_id = $_GET['task-id']; $task = new Task(); $task->load('id = ?', [$task_id]); if ($task->delete()) { Response::write('message', 'Task deleted'); } else { Response::write('status', false); Response::write('message', 'Task failed to delete.'); } Response::output();
<?php if ('dbuniquecheck' == Request::get(1)) { $dbdate = Request::json(); $m = new Model($dbdate[1]); $query_arr = array($dbdate[2] => $dbdate[4]); if (trim($dbdate[3]) != '') { $query_arr['id@<>'] = trim($dbdate[3]); } if ($m->has($query_arr)) { Response::write('no'); } else { Response::write('ok'); } } elseif ('getselvt' == Request::get(1)) { $tn = String::decryption(Request::post('tn')); $aw = String::decryption(Request::post('aw')); $m = new Model($tn); $array = $m->field('id,name')->where("pid='" . Request::post('pid') . "'" . $aw)->list_all_array(); Response::json($array); }
<?php require_once 'inc/init.php'; Response::write('message', 'Welcome to ' . Config::read('application')['name']); Response::output();
public function doGet(Request $request, Response $response) { $response->write("AUTRE " . $request->getAttribute('new') . " __ " . $request->getSession()->getAttribute("TEST")); }
ob_start("ob_gzhandler"); } else { ob_start(); } //les managers ne renvoient QUE du json, on met donc le header de la réponse a jour //on inclu l'autoloader include dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoloader.php'; $manager = new Manager(); //on récupère la commande et la parse pour être executée if (isset($_POST['command'])) { $commands = explode(':', $_POST['command']); $managerName = $commands[0]; $managerCommand = $commands[1]; //on supprime la commande de la variable globale, les managers n'ont pas a la connaitre et a l'utiliser unset($_POST['command']); //si on trouve la commande on l'execute if ($manager->match($managerName, $managerCommand)) { $manager->dispatch($_POST); } else { $response = json_encode(['result' => false, 'message' => "commande inexistante"]); $objectResponse = new Response(404); $objectResponse->write($response); $objectResponse->send(); } } else { $response = json_encode(['result' => false, 'message' => "Variable POST command inexistante"]); $objectResponse = new Response(404); $objectResponse->write($response); $objectResponse->send(); } ob_end_clean();
*/ if ($argc > 1) { $test = $argv[1]; require "{$test}.php"; if ($test == 'addressbook.proto') { $fp = fopen('test.book', 'rb'); $m = new tutorial_AddressBook($fp); var_dump($m); fclose($fp); } else { if ($test == 'market.proto') { //$fp = fopen('market2-in-1.dec', 'rb'); $fp = fopen('market2-in-2.dec', 'rb'); //$fp = fopen('temp', 'rb'); $m = new Response($fp); echo $m; //$mem = fopen('php://memory', 'wb'); $mem = fopen('temp', 'wb'); if ($mem === false) { exit('Unable to open output stream'); } $s = fstat($fp); echo 'File size: ' . $s['size'] . "\n"; echo 'Guested size: ' . $m->size() . "\n"; $m->write($mem); echo 'Write size: ' . ftell($mem) . "\n"; fclose($mem); fclose($fp); } } }
/** * Test body and write * * Pre-conditions: * Case A: Response body set to "Foo bar" * Case B: Same response body is changed to "abc123" * Case C: Same response body is appended with "xyz" * * Post-conditions: * Case A: Response body is "Foo bar", and Content-Length = 7 * Case B: Response body is "abc123" and Content-Length = 6 * Case C: Response body is "abc123xyz" and Content-Length = 9 */ public function testBody() { //Case A $r1 = new Response(); $r1->body('Foo bar'); $this->assertEquals($r1->body(), 'Foo bar'); $this->assertEquals($r1->header('Content-Length'), 7); //Case B $r1->body('abc123'); $this->assertEquals($r1->body(), 'abc123'); $this->assertEquals($r1->header('Content-Length'), 6); //Case C $r1->write('xyz'); $this->assertEquals($r1->body(), 'abc123xyz'); $this->assertEquals($r1->header('Content-Length'), 9); }
<?php require_once 'inc/init.php'; $task = new Task(); $tasks = $task->Find('1 = 1'); Response::write('data', $tasks); Response::output();
/** * @param int $status status HTTP de la réponse (404,200,500, etc) * @param $content * @param string $type */ public static function quickResponse($status, $content, $type = 'application/json') { $response = new Response($status, false, $type); $response->write($content); $response->send(); }
public function doPost(Request $pRequest, Response $pResponse) { $pResponse->write('TEST POST' . $pRequest->getParameter("toto")); $pRequest->getSession()->setAttribute("TEST", $pRequest->getParameter("toto")); }
public function testWrite() { $this->object->write('1'); $this->object->write('2'); $this->assertThat($this->object->getContent(), $this->equalTo('12')); }