当前位置: 首页>>代码示例>>PHP>>正文


PHP Response类代码示例

本文整理汇总了PHP中Response的典型用法代码示例。如果您正苦于以下问题:PHP Response类的具体用法?PHP Response怎么用?PHP Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get

 function get($request, $user)
 {
     $response = new Response($request);
     $response->code = Response::OK;
     $response->addHeader('content-type', 'text/plain');
     $data = array();
     ouverture();
     // recherche du championnat en cours
     $querySaisonEnCours = "SELECT phpl_gr_championnats.id\r\n\t\t\t\t\t\t\t\tFROM phpl_gr_championnats \r\n\t\t\t\t\t\t\t\tWHERE phpl_gr_championnats.activ_prono = '1' \r\n\t\t\t\t\t\t\t\tORDER by id desc";
     $resultat = mysql_query($querySaisonEnCours) or die("probleme " . mysql_error());
     $row = mysql_fetch_array($resultat);
     $idSaisonEnCours = $row[0];
     // recherche de l'id de la dernière journée
     $queryDerniereJournee = "SELECT max(evolutionGraph.fin)\r\n\t\t\t\t\t\t\t\tFROM phpl_pronos_graph evolutionGraph\r\n\t\t\t\t\t\t\t\tWHERE evolutionGraph.id_gr_champ = '{$idSaisonEnCours}'";
     $resultat = mysql_query($queryDerniereJournee);
     $row = mysql_fetch_array($resultat);
     $idDerniereJournee = $row[0];
     // évolution sur la dernière journée
     $queryEvolution = "SELECT P2.type, P2.classement as place, (P2.points - P1.points) as points, (P1.classement - P2.classement) as evolution\r\n    \t\t\t\t\t\t FROM phpl_membres membre\r\n\t\t\t\t             JOIN phpl_pronos_graph P1 ON P1.id_membre = membre.id_prono\r\n\t\t\t\t             \t\t\t\t\t\t  AND P1.id_gr_champ = '{$idSaisonEnCours}'\r\n\t\t\t\t             \t\t\t\t\t\t  AND P1.type in ('general', 'hourra', 'mixte')\r\n\t\t\t\t\t\t\t   \t\t\t\t\t\t  AND P1.fin = '" . ($idDerniereJournee - 1) . "'\t\t             \t\t\t\t\t\t  \r\n\t\t\t\t             JOIN phpl_pronos_graph P2 ON P2.id_membre = P1.id_membre\r\n\t\t\t\t             \t\t\t\t\t\t  AND P2.id_gr_champ = P1.id_gr_champ\r\n\t\t\t\t             \t\t\t\t\t\t  AND P2.type = P1.type\r\n\t\t\t\t               \t\t\t\t\t\t  AND P2.fin = '{$idDerniereJournee}'\r\n\t\t\t\t             WHERE pseudo = '{$user}'\t\t             \t\t\t\t\t\t  \t             \r\n\t\t\t\t\t\t\t ORDER BY P2.type";
     $resultat = mysql_query($queryEvolution) or die("probleme " . mysql_error());
     while ($row = mysql_fetch_array($resultat)) {
         $typeChamp = $row["type"];
         $numPlace = $row['place'];
         $nbPoints = $row['points'];
         $numEvolution = $row["evolution"];
         array_push($data, array("type" => $typeChamp, "place" => $numPlace, "points" => $nbPoints, "evolution" => $numEvolution));
     }
     // Retour du tableau au format JSON
     $response->body = json_encode(array("profilStat" => $data));
     return $response;
 }
开发者ID:pronoschallenge,项目名称:PronosChallenge,代码行数:31,代码来源:profilStat.php

示例2: testGetReasonPhraseReturnsTheReasonPhrase

 public function testGetReasonPhraseReturnsTheReasonPhrase()
 {
     $response = new Response();
     $this->assertEquals($response->getReasonPhrase(), null);
     $response->addHeader('1.0 200 OK');
     $this->assertEquals($response->getReasonPhrase(), 'OK');
 }
开发者ID:philip,项目名称:Buzz,代码行数:7,代码来源:ResponseTest.php

示例3: set_cache

 /**
  * Override of the set_cache method, works in exactly the same way except
  * the check for the max-age header in the response has been removed so that
  * Codebase API responses will always be cached, this breaks HTTP Cache
  * rules but is the cleanest way of enabling caching for all responses
  * within Kohana.
  *
  * @param	Response	$response
  * @return	boolean
  */
 public function set_cache(Response $response)
 {
     $headers = $response->headers()->getArrayCopy();
     if ($cache_control = Arr::get($headers, 'cache-control')) {
         // Parse the cache control
         $cache_control = HTTP_Header::parse_cache_control($cache_control);
         // If the no-cache or no-store directive is set, return
         if (array_intersect($cache_control, array('no-cache', 'no-store'))) {
             return FALSE;
         }
         // Check for private cache and get out of here if invalid
         if (!$this->_allow_private_cache and in_array('private', $cache_control)) {
             if (!isset($cache_control['s-maxage'])) {
                 return FALSE;
             }
             // If there is a s-maxage directive we can use that
             $cache_control['max-age'] = $cache_control['s-maxage'];
         }
     }
     /**
      * if the max-age cache control header is set to 0 in the response, set
      * it to 1 hour so the reponse will be cacheable
      */
     $cache_control_header = $response->headers('Cache-Control');
     $response->headers('Cache-Control', str_replace('max-age=0', 'max-age=3600', $cache_control_header));
     if ($expires = Arr::get($headers, 'expires') and !isset($cache_control['max-age'])) {
         // Can't cache things that have expired already
         if (strtotime($expires) <= time()) {
             return FALSE;
         }
     }
     return TRUE;
 }
开发者ID:rpa-design,项目名称:codebase,代码行数:43,代码来源:cache.php

示例4: saveuser

 function saveuser()
 {
     $response = new Response();
     try {
         $id = $this->input->post("user-id");
         $email = $this->input->post("email");
         $firstName = $this->input->post("first-name");
         $lastName = $this->input->post("last-name");
         $role = $this->input->post("role");
         $subDivision = $this->input->post("sub-division");
         $user = new User();
         if ($id != null && $id != "") {
             $user = $this->findById("User", $id);
         }
         $user->setEmail($email);
         $user->setUsername($email);
         $user->setPassword("");
         $user->setFirstName($firstName);
         $user->setLastName($lastName);
         $subDivision = $this->findById("Subdivision", $subDivision);
         $user->setSubdivision($subDivision);
         $role = $this->getRoleByName($role);
         $user->setRole($role[0]);
         $token = $this->getRandomCode();
         $user->setToken($token);
         $this->save($user);
         $emailMessage = "Hi " . $user->getName() . ", <br/> Your account has been activate on " . base_url() . ". Please <a href='" . site_url() . "/validate/" . $token . "'>click here </a> to create you password.";
         $this->sendMail($user->getEmail(), "Active you account.", $emailMessage);
     } catch (Exception $e) {
         $response->setStatus(false);
         $response->setErrorMessage($e->getMessage());
     }
     $this->output->set_content_type('application/json')->set_output(json_encode($response));
 }
开发者ID:digvijaymohite,项目名称:e-tender,代码行数:34,代码来源:Users.php

示例5: testIfRedirectReturnsCorrectHttpCodeAndLocationHeader

 /**
  * @test
  * @param $url
  * @param $statusCode
  * @dataProvider redirectDataProvider
  */
 public function testIfRedirectReturnsCorrectHttpCodeAndLocationHeader($url, $statusCode)
 {
     $response = new Response();
     $response->redirect($url, $statusCode);
     $this->assertEquals($url, $response->headers->get('Location'));
     $this->assertEquals($statusCode, $response->getStatusCode());
 }
开发者ID:lcobucci,项目名称:action-mapper,代码行数:13,代码来源:ResponseTest.php

示例6: initcall

function initcall()
{
    if ($_REQUEST["CallStatus"] == "completed") {
        // receives request from Twilio server when a call ends
        // remove call from active calls
        // saves call info in DB as current call
        $callGuid = $_REQUEST["CallGuid"];
        $db = new PDO("sqlite:twilio.db");
        $query = "UPDATE Calls SET Status = 'ended' WHERE CallGuid = '{$callGuid}'";
        $db->exec($query);
    } else {
        // dial all saved numbers for your account
        $numbers = getNumbersToCall();
        // get numbers
        $r = new Response();
        for ($i = 0; $i < count($numbers); $i++) {
            $r->addDial($numbers[$i]);
        }
        $r->Respond();
        // saves call info in DB as current call
        $callGuid = $_REQUEST["CallGuid"];
        $caller = $_REQUEST["Caller"];
        $callLocation = $_REQUEST["CallerCity"] != "" ? $_REQUEST["CallerCity"] : ($_REQUEST["CallerState"] != "" ? $_REQUEST["CallerState"] : ($_REQUEST["CallerZip"] != "" ? $_REQUEST["CallerZip"] : ($_REQUEST["CallerCountry"] != "" ? $_REQUEST["CallerCountry"] : "")));
        $db = new PDO("sqlite:twilio.db");
        $query = "INSERT INTO Calls (CallGuid, Caller, Location, Status) VALUES ('{$callGuid}', '{$caller}', '{$callLocation}', 'active')";
        $db->exec($query);
    }
}
开发者ID:Timothee,项目名称:Notwilfications,代码行数:28,代码来源:index.php

示例7: _send_message

 /**
  * Sends the HTTP message [Request] to a remote server and processes
  * the response.
  *
  * @param   Request   $request  request to send
  * @param   Response  $request  response to send
  * @return  Response
  */
 public function _send_message(Request $request, Response $response)
 {
     // Response headers
     $response_headers = array();
     $options = array();
     // Set the request method
     $options = $this->_set_curl_request_method($request, $options);
     // Set the request body. This is perfectly legal in CURL even
     // if using a request other than POST. PUT does support this method
     // and DOES NOT require writing data to disk before putting it, if
     // reading the PHP docs you may have got that impression. SdF
     // This will also add a Content-Type: application/x-www-form-urlencoded header unless you override it
     if ($body = $request->body()) {
         $options[CURLOPT_POSTFIELDS] = $request->body();
     }
     // Process headers
     if ($headers = $request->headers()) {
         $http_headers = array();
         foreach ($headers as $key => $value) {
             $http_headers[] = $key . ': ' . $value;
         }
         $options[CURLOPT_HTTPHEADER] = $http_headers;
     }
     // Process cookies
     if ($cookies = $request->cookie()) {
         $options[CURLOPT_COOKIE] = http_build_query($cookies, NULL, '; ');
     }
     // Get any exisiting response headers
     $response_header = $response->headers();
     // Implement the standard parsing parameters
     $options[CURLOPT_HEADERFUNCTION] = array($response_header, 'parse_header_string');
     $this->_options[CURLOPT_RETURNTRANSFER] = TRUE;
     $this->_options[CURLOPT_HEADER] = FALSE;
     // Apply any additional options set to
     $options += $this->_options;
     $uri = $request->uri();
     if ($query = $request->query()) {
         $uri .= '?' . http_build_query($query, NULL, '&');
     }
     // Open a new remote connection
     $curl = curl_init($uri);
     // Set connection options
     if (!curl_setopt_array($curl, $options)) {
         throw new Request_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array'));
     }
     // Get the response body
     $body = curl_exec($curl);
     // Get the response information
     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($body === FALSE) {
         $error = curl_error($curl);
     }
     // Close the connection
     curl_close($curl);
     if (isset($error)) {
         throw new Request_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $request->url(), ':code' => $code, ':error' => $error));
     }
     $response->status($code)->body($body);
     return $response;
 }
开发者ID:creat2012,项目名称:hustoj_official,代码行数:68,代码来源:Curl.php

示例8: testShouldReturnFalseWhenCallForEmptyResponseIfIsOk

 public function testShouldReturnFalseWhenCallForEmptyResponseIfIsOk()
 {
     // Set
     $response = new Response();
     // Assert
     $this->assertFalse($response->isOk());
 }
开发者ID:leroy-merlin-br,项目名称:laravel-axado-api,代码行数:7,代码来源:ResponseTest.php

示例9: _main

 /**
  * Get the latest raffle
  * 
  * @param Request
  * @return Response
  * */
 public function _main(Request $request)
 {
     // set Spanish so the date come in Spanish
     setlocale(LC_TIME, "es_ES");
     // get the current raffle
     $raffle = $this->utils->getCurrentRaffle();
     // show message if there is no open raffle
     if (!$raffle) {
         $response = new Response();
         $response->subject = "No hay ninguna Rifa abierta";
         $response->createFromText("Lo sentimos, no hay ninguna Rifa abierta ahora mismo. Pruebe nuevamente en algunos d&iacute;as.");
         return $response;
     }
     // get number of tickets adquired by the user
     $connection = new Connection();
     $userTickets = $connection->deepQuery("SELECT count(*) as tickets FROM ticket WHERE raffle_id is NULL AND email = '{$request->email}'");
     $userTickets = $userTickets[0]->tickets;
     // link to connect cuba logo
     $connectCubaLogo = "{$this->pathToService}/images/connectcuba.jpg";
     // create a json object to send to the template
     $responseContent = array("description" => $raffle->item_desc, "startDate" => $raffle->start_date, "endDate" => $raffle->end_date, "tickets" => $raffle->tickets, "image" => $raffle->image, "userTickets" => $userTickets, "connectCubaLogo" => $connectCubaLogo);
     // create the final user Response
     $response = new Response();
     $response->subject = "La Rifa de Apretaste";
     $response->createFromTemplate("basic.tpl", $responseContent, array($raffle->image, $connectCubaLogo));
     return $response;
 }
开发者ID:Apretaste,项目名称:rifa,代码行数:33,代码来源:service.php

示例10: __invoke

 /**
  * @param Request  $req
  * @param Response $res
  *
  * @return Response
  */
 public function __invoke($req, $res)
 {
     if ($req->isHtml()) {
         $res->render(new View('not_found', ['title' => 'Not Found']));
     }
     return $res->setCode(404);
 }
开发者ID:idealistsoft,项目名称:framework-bootstrap,代码行数:13,代码来源:NotFoundHandler.php

示例11: store

 /**
  * Store the cookies from a response.
  *
  * Store the cookies that haven't expired. If a cookie has been expired
  * and is currently stored, it will be removed.
  *
  * @param \Cake\Http\Client\Response $response The response to read cookies from
  * @param string $url The request URL used for default host/path values.
  * @return void
  */
 public function store(Response $response, $url)
 {
     $host = parse_url($url, PHP_URL_HOST);
     $path = parse_url($url, PHP_URL_PATH);
     $path = $path ?: '/';
     $cookies = $response->cookies();
     foreach ($cookies as $name => $cookie) {
         if (empty($cookie['domain'])) {
             $cookie['domain'] = $host;
         }
         if (empty($cookie['path'])) {
             $cookie['path'] = $path;
         }
         $key = implode(';', [$cookie['name'], $cookie['domain'], $cookie['path']]);
         $expires = isset($cookie['expires']) ? $cookie['expires'] : false;
         $expiresTime = false;
         if ($expires) {
             $expiresTime = strtotime($expires);
         }
         if ($expiresTime && $expiresTime <= time()) {
             unset($this->_cookies[$key]);
             continue;
         }
         $this->_cookies[$key] = $cookie;
     }
 }
开发者ID:nrother,项目名称:cakephp,代码行数:36,代码来源:CookieCollection.php

示例12: post

 function post($request)
 {
     $response = new Response($request);
     if (isset($_POST['tour'])) {
         // Remove those slashes
         if (get_magic_quotes_gpc()) {
             $tour = stripslashes($_POST['tour']);
         } else {
             $tour = $_POST['tour'];
         }
         $tour_obj = json_decode($tour);
         $entitymanager = GeocacheManager::getInstance();
         //~ print_r($tour_obj);
         $data = array();
         $data['name'] = $tour_obj->name;
         $data['webcode'] = isset($tour_obj->webcode) ? $tour_obj->webcode : $this->get_new_webcode();
         $data['geocaches'] = $entitymanager->parseGeocaches($tour_obj->geocaches);
         $data['ownWaypoints'] = $entitymanager->parseOwnWaypoints($tour_obj->costumMarkers);
         $tour = new Tour($data);
         $tour->save();
         $response->code = Response::OK;
         $response->addHeader('Content-type', 'text/plain');
         $response->body = $tour->__toJSON();
     } else {
         $response->code = Response::BADREQUEST;
     }
     return $response;
 }
开发者ID:ThomDietrich,项目名称:gctour,代码行数:28,代码来源:tour_save.php

示例13: respond

 public function respond(Response $response)
 {
     $fullClassName = $this->pageClass->getFullyQualifiedName();
     $page = new $fullClassName();
     $page->renderPage();
     $response->flush();
 }
开发者ID:picon,项目名称:picon-framework,代码行数:7,代码来源:PageRequestTarget.php

示例14: handle

 public static function handle(Exception $e)
 {
     switch (get_class($e)) {
         case 'HTTP_Exception_404':
             $response = new Response();
             $response->status(404);
             $view = new View('errors/error404');
             Controller_Abstract::add_static();
             if (Kohana::$environment == Kohana::DEVELOPMENT) {
                 $view->message = $e->getMessage();
             }
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         case 'HTTP_Exception_410':
             $response = new Response();
             $response->status(410);
             $view = new View('errors/error410');
             Controller_Abstract::add_static();
             echo $response->body($view)->send_headers()->body();
             return TRUE;
             break;
         default:
             header('C-Data: ' . uniqid() . str_replace('=', '', base64_encode($e->getMessage())));
             return Kohana_Exception::handler($e);
             break;
     }
 }
开发者ID:nergal,项目名称:2mio,代码行数:28,代码来源:handler.php

示例15: preview_page

 public function preview_page()
 {
     $page = Page::getByID(intval($_REQUEST['cID'], 10), 'RECENT');
     if (!is_object($page) || $page->isError()) {
         throw new \InvalidArgumentException('Invalid collection ID');
     }
     $permissions = new Permissions($page);
     if ($permissions->canPreviewPageAsUser() && $permissions->canRead() && Config::get('concrete.permissions.model') == 'advanced') {
         /** @var Request $request */
         $request = Request::getInstance();
         $request->setCustomRequestUser(false);
         $request->setCurrentPage($page);
         if ($request->request('customUser')) {
             $user_info = UserInfo::getByUserName($request->request('customUser'));
             if ($user_info && is_object($user_info) && !$user_info->isError()) {
                 $request->setCustomRequestUser($user_info);
             }
         }
         $request->setCustomRequestDateTime(Core::make('helper/form/date_time')->translate('preview_as_user_datetime', $request->request()));
         $controller = $page->getPageController();
         $view = $controller->getViewObject();
         $response = new \Response();
         $response->setContent($view->render());
         $response->send();
     }
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:26,代码来源:preview_as_user.php


注:本文中的Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。