當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CakeResponse類代碼示例

本文整理匯總了PHP中CakeResponse的典型用法代碼示例。如果您正苦於以下問題:PHP CakeResponse類的具體用法?PHP CakeResponse怎麽用?PHP CakeResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CakeResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parse

 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if ($params === false) {
         return false;
     }
     $Domains = new Domains();
     $subdomain = $Domains->getSubdomain();
     $masterDomain = Configure::read('Domain.Master');
     $defaultRoute = Configure::read('Domain.DefaultRoute');
     $Tenant = new Tenant();
     if (!$Tenant->domainExists($subdomain) && $params != $defaultRoute) {
         if (!$this->response) {
             $this->response = new CakeResponse();
         }
         debug($this->response);
         die;
         $status = 307;
         $redirect = $defaultRoute;
         $this->response->header(array('Location' => Router::url($redirect, true)));
         $this->response->statusCode($status);
         $this->response->send();
         $this->_stop();
     }
     return $subdomain;
 }
開發者ID:bmilesp,項目名稱:multi-tenancy,代碼行數:33,代碼來源:DomainRoute.php

示例2: authenticate

 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $provider = new Stevenmaguire\OAuth2\Client\Provider\Bitbucket(array('clientId' => Configure::read('OAuth.bitbucket_consumer_key'), 'clientSecret' => Configure::read('OAuth.bitbucket_consumer_secret'), 'redirectUri' => Configure::read('OAuth.redirect_uri')));
     $session = new CakeSession();
     if (!isset($request->query['code'])) {
         $response->header('Location', $provider->getAuthorizationUrl());
     } else {
         try {
             $token = $provider->getAccessToken('authorization_code', array('code' => $request->query['code']));
         } catch (Exception $e) {
             return false;
         }
         $resourceOwner = $provider->getResourceOwner($token)->toArray();
         App::uses('User', 'Model');
         $User = new User();
         $data = array('User' => array('account_type' => 'bitbucket', 'username' => $resourceOwner['username'], 'display_name' => $resourceOwner['display_name'], 'bitbucket_uuid' => $resourceOwner['uuid'], 'oauth_access_token' => $token->getToken(), 'oauth_refresh_token' => $token->getRefreshToken(), 'oauth_token_expires_in' => $token->getExpires()));
         $existingUser = $User->find('first', array('conditions' => array('User.bitbucket_uuid' => $resourceOwner['uuid'])));
         if (!$existingUser) {
             $User->create();
         } else {
             $data['User']['id'] = $existingUser['User']['id'];
         }
         $User->save($data);
         return $data['User'];
     }
     return false;
 }
開發者ID:Glitchbone,項目名稱:yolped,代碼行數:27,代碼來源:BitbucketAuthenticate.php

示例3: parse

 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     $redirect = $this->defaults;
     if (count($this->defaults) == 1 && !isset($this->defaults['controller'])) {
         $redirect = $this->defaults[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $argOptions['context'] = array('action' => $redirect['action'], 'controller' => $redirect['controller']);
         $args = Router::getArgs($params['_args_'], $argOptions);
         $redirect += $args['pass'];
         $redirect += $args['named'];
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     $this->response->header(array('Location' => Router::url($redirect, true)));
     $this->response->statusCode($status);
     $this->response->send();
 }
開發者ID:no2key,項目名稱:Web-Framework-Benchmark,代碼行數:34,代碼來源:redirect_route.php

示例4: parse

 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     $redirect = $this->redirect;
     if (count($this->redirect) == 1 && !isset($this->redirect['controller'])) {
         $redirect = $this->redirect[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $redirect += array('named' => $params['named'], 'pass' => $params['pass'], 'url' => array());
         $redirect = Router::reverse($redirect);
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     $this->response->header(array('Location' => Router::url($redirect, true)));
     $this->response->statusCode($status);
     $this->response->send();
     $this->_stop();
 }
開發者ID:MrGrigorev,項目名稱:reserva-de-salas,代碼行數:33,代碼來源:RedirectRoute.php

示例5: authenticate

 /**
  * Authenticate user
  *
  * @param CakeRequest $request The request object
  * @param CakeResponse $response response object.
  * @return mixed.  False on login failure.  An array of User data on success.
  */
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $user = $this->getUser($request);
     if (!$user) {
         $response->statusCode(401);
         $response->send();
     }
     return $user;
 }
開發者ID:hardiksondagar,項目名稱:cake-jwt-seed,代碼行數:16,代碼來源:JwtTokenAuthenticate.php

示例6: testReplaceRunId

 /**
  * Test that beforeDispatcher replaces run id
  *
  * @return void
  */
 public function testReplaceRunId()
 {
     $filter = new XHProfDispatcher();
     $response = new CakeResponse();
     $response->body('Run id: %XHProfRunId%.');
     $event = new CakeEvent('DispatcherTest', $this, compact('response'));
     $filter->beforeDispatch($event);
     $this->assertSame($response, $filter->afterDispatch($event));
     $this->assertRegExp('/^Run id: [0-9a-f]{13}\\.$/', $response->body());
 }
開發者ID:renan,項目名稱:cakephp-xhprof,代碼行數:15,代碼來源:XHProfDispacherTest.php

示例7: authenticate

 /**
  * Authenticate a user using basic HTTP auth.  Will use the configured User model and attempt a
  * login using basic HTTP auth.
  *
  * @param CakeRequest $request The request to authenticate with.
  * @param CakeResponse $response The response to add headers to.
  * @return mixed Either false on failure, or an array of user data on success.
  */
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $result = $this->getUser($request);
     if (empty($result)) {
         $response->header($this->loginHeaders());
         $response->statusCode(401);
         $response->send();
         return false;
     }
     return $result;
 }
開發者ID:MrGrigorev,項目名稱:reserva-de-salas,代碼行數:19,代碼來源:BasicAuthenticate.php

示例8: insertFile

 /**
  * https://developers.google.com/drive/v2/reference/files/insert
  **/
 public function insertFile($file, $driveFile, $options = array())
 {
     // setting default options
     $options = array_merge(array('convert' => 'true'), $options);
     // seting path and request
     $path = sprintf('/%s', $driveFile['id']);
     $request = array();
     $request['uri']['query'] = $options;
     $request['body'] = file_get_contents($file['tmp_name']);
     // using CakeReponse to guess mime type
     $ext = array_pop(explode('.', $file['name']));
     $CR = new CakeResponse();
     $request['header']['Content-Type'] = $CR->getMimeType($ext);
     return $this->_request($path, $request);
 }
開發者ID:kaburk,項目名稱:CakePHP-Google,代碼行數:18,代碼來源:GoogleDriveFilesUpload.php

示例9: testRenderWithView

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array('User' => array('username' => 'fake'), 'Item' => array(array('name' => 'item1'), array('name' => 'item2')));
     $Controller->set('user', $data);
     $View = new JsonView($Controller);
     $output = $View->render('index');
     $expected = json_encode(array('user' => 'fake', 'list' => array('item1', 'item2')));
     $this->assertIdentical($expected, $output);
     $this->assertIdentical('application/json', $Response->type());
 }
開發者ID:rufl,項目名稱:ATP,代碼行數:20,代碼來源:JsonViewTest.php

示例10: testRenderWithView

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array(array('User' => array('username' => 'user1')), array('User' => array('username' => 'user2')));
     $Controller->set('users', $data);
     $View = new XmlView($Controller);
     $output = $View->render('index');
     $expected = '<?xml version="1.0" encoding="UTF-8"?><users><user>user1</user><user>user2</user></users>';
     $this->assertIdentical($expected, str_replace(array("\r", "\n"), '', $output));
     $this->assertIdentical('application/xml', $Response->type());
     $this->assertInstanceOf('HelperCollection', $View->Helpers);
 }
開發者ID:MrGrigorev,項目名稱:reserva-de-salas,代碼行數:21,代碼來源:XmlViewTest.php

示例11: _fetch

 protected function _fetch($facebook, $access_oauth_token, CakeResponse $response)
 {
     try {
         // get user infomation from Facebook
         $user_id = $facebook->getUser();
         $me = $facebook->api('/me');
         $user = $this->_Collection->Auth->user();
         $user['Member']["user_id"] = $me['id'];
         $user['Member']["user_name"] = $me['name'];
         $user['Member']["access_oauth_token"] = $access_oauth_token;
         if ($this->_Collection->Auth->login($user)) {
             $loginRedirect = $this->_Collection->Auth->loginRedirect;
             $response->header('Location', $loginRedirect);
             $response->send();
         }
     } catch (OAuthException $E) {
         //you can catch OAuth exception
     }
 }
開發者ID:noahm,項目名稱:cakephp-FacebookAuthenticate,代碼行數:19,代碼來源:FacebookAuthenticate.php

示例12: _deliverMedia

 protected function _deliverMedia(CakeResponse $response, $mediaFile, $mediaInfo)
 {
     $response->sharable(true, 2592000);
     //$response->mustRevalidate(true);
     $response->expires('+30 days');
     $modTime = filemtime($mediaFile);
     $response->modified($modTime);
     $response->etag(md5($mediaFile . $modTime));
     //$response->header("Pragma", "cache");
     $response->type($mediaInfo['ext']);
     $response->file($mediaFile);
     $response->send();
 }
開發者ID:nilBora,項目名稱:konstruktor,代碼行數:13,代碼來源:MediaDispatcher.php

示例13: authenticate

 /**
  *
  * @param CakeRequest $request
  * @param CakeResponse $response
  * @return boolean
  */
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $oauth = ClassRegistry::init('Twim.TwimOauth');
     /* @var $oauth TwimOauth */
     if (!empty($request->data['Twitter']['login'])) {
         // redirect to twitter
         $requestToken = $oauth->getRequestToken();
         $redirectUrl = $this->settings['authenticate'] ? $oauth->getAuthenticateUrl($requestToken) : $oauth->getAuthorizeUrl($requestToken);
         $response->header('Location', $redirectUrl);
     } elseif (isset($request->query['oauth_token']) && isset($request->query['oauth_verifier'])) {
         // get access token
         $verifier = array_intersect_key($request->query, array('oauth_token' => true, 'oauth_verifier' => true));
         $accessToken = $oauth->getAccessToken($verifier);
         if ($this->settings['userModel'] === false) {
             return $accessToken;
         }
         // save user data
         return $this->saveToModel($accessToken);
     }
     return false;
 }
開發者ID:nojimage,項目名稱:cakephp-twim,代碼行數:27,代碼來源:TwitterAuthenticate.php

示例14: _getController

 protected function _getController($exception)
 {
     if (!($request = Router::getRequest(true))) {
         $request = new CakeRequest();
     }
     $response = new CakeResponse();
     if (method_exists($exception, 'responseHeader')) {
         $response->header($exception->responseHeader());
     }
     try {
         $controller = new AppErrorController($request, $response);
         $controller->startupProcess();
     } catch (Exception $e) {
         if (!empty($controller) && $controller->Components->enabled('RequestHandler')) {
             $controller->RequestHandler->startup($controller);
         }
     }
     if (empty($controller)) {
         $controller = new Controller($request, $response);
         $controller->viewPath = 'Errors';
     }
     return $controller;
 }
開發者ID:manzapanza,項目名稱:cakephp-api-utils,代碼行數:23,代碼來源:AppExceptionRenderer.php

示例15: testRenderWithView

 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
     $Request = new CakeRequest();
     $Response = new CakeResponse();
     $Controller = new Controller($Request, $Response);
     $Controller->name = $Controller->viewPath = 'Posts';
     $data = array(array('User' => array('username' => 'user1')), array('User' => array('username' => 'user2')));
     $Controller->set('users', $data);
     $View = new XmlView($Controller);
     $output = $View->render('index');
     $expected = array('users' => array('user' => array('user1', 'user2')));
     $expected = Xml::build($expected)->asXML();
     $this->assertSame($expected, $output);
     $this->assertSame('application/xml', $Response->type());
     $this->assertInstanceOf('HelperCollection', $View->Helpers);
 }
開發者ID:pritten,項目名稱:SmartCitizen.me,代碼行數:22,代碼來源:XmlViewTest.php


注:本文中的CakeResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。