本文整理汇总了PHP中CakeResponse类的典型用法代码示例。如果您正苦于以下问题:PHP CakeResponse类的具体用法?PHP CakeResponse怎么用?PHP CakeResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CakeResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: _deliver
protected function _deliver(CakeResponse $response, Asset $asset)
{
ob_start();
$compressionEnabled = Configure::read('Asset.compress') && $response->compress();
if ($response->type($asset->extension()) == $asset->extension()) {
$contentType = 'application/octet-stream';
$agent = env('HTTP_USER_AGENT');
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
$contentType = 'application/octetstream';
}
$response->type($contentType);
}
if (!$compressionEnabled) {
$response->header('Content-Length', $asset->size());
}
$response->cache(filemtime($asset->file));
$response->send();
ob_clean();
echo $asset->content();
if ($compressionEnabled) {
ob_end_flush();
}
}
开发者ID:rodrigorm,项目名称:asset-plugin,代码行数:23,代码来源:AssetsDispatcher.php
示例17: testLocation
/**
* Test the location method.
*
* @return void
*/
public function testLocation()
{
$response = new CakeResponse();
$this->assertNull($response->location(), 'No header should be set.');
$this->assertNull($response->location('http://example.org'), 'Setting a location should return null');
$this->assertEquals('http://example.org', $response->location(), 'Reading a location should return the value.');
}
开发者ID:pushpendraraj,项目名称:tigzie,代码行数:12,代码来源:CakeResponseTest.php
示例18: dispatch
/**
* Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set
* to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
*
* Actions in CakePHP can be any public method on a controller, that is not declared in Controller. If you
* want controller methods to be public and in-accessible by URL, then prefix them with a `_`.
* For example `public function _loadPosts() { }` would not be accessible via URL. Private and protected methods
* are also not accessible via URL.
*
* If no controller of given name can be found, invoke() will throw an exception.
* If the controller is found, and the action is not found an exception will be thrown.
*
* @param CakeRequest $request Request object to dispatch.
* @param CakeResponse $response Response object to put the results of the dispatch into.
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
* @return string|void if `$request['return']` is set then it returns response body, null otherwise
* @throws MissingControllerException When the controller is missing.
*/
public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array())
{
$beforeEvent = new CakeEvent('Dispatcher.beforeDispatch', $this, compact('request', 'response', 'additionalParams'));
$this->getEventManager()->dispatch($beforeEvent);
$request = $beforeEvent->data['request'];
if ($beforeEvent->result instanceof CakeResponse) {
if (isset($request->params['return'])) {
return $response->body();
}
$response->send();
return;
}
$controller = $this->_getController($request, $response);
if (!$controller instanceof Controller) {
throw new MissingControllerException(array('class' => Inflector::camelize($request->params['controller']) . 'Controller', 'plugin' => empty($request->params['plugin']) ? null : Inflector::camelize($request->params['plugin'])));
}
$response = $this->_invoke($controller, $request, $response);
if (isset($request->params['return'])) {
return $response->body();
}
$afterEvent = new CakeEvent('Dispatcher.afterDispatch', $this, compact('request', 'response'));
$this->getEventManager()->dispatch($afterEvent);
$afterEvent->data['response']->send();
}
开发者ID:carriercomm,项目名称:professional-inventory-and-billing-system,代码行数:42,代码来源:Dispatcher.php
示例19: testWithoutSubdir
/**
* AjaxViewTest::testWithoutSubdir()
*
* @return void
*/
public function testWithoutSubdir()
{
$Request = new CakeRequest();
$Response = new CakeResponse();
$Controller = new Controller($Request, $Response);
$View = new AjaxView($Controller);
$View->viewPath = 'Items';
$View->subDir = false;
$result = $View->render('index');
$this->assertSame('application/json', $Response->type());
$expected = array('error' => null, 'content' => 'My Index Test ctp');
$expected = json_encode($expected);
$this->assertTextEquals($expected, $result);
}
开发者ID:Jony01,项目名称:LLD,代码行数:19,代码来源:AjaxViewTest.php
示例20: testCookieSettings
/**
* Test cookie setting
*
* @return void
*/
public function testCookieSettings()
{
$response = new CakeResponse();
$cookie = array('name' => 'CakeTestCookie[Testing]');
$response->cookie($cookie);
$expected = array('name' => 'CakeTestCookie[Testing]', 'value' => '', 'expire' => 0, 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false);
$result = $response->cookie('CakeTestCookie[Testing]');
$this->assertEquals($expected, $result);
$cookie = array('name' => 'CakeTestCookie[Testing2]', 'value' => '[a,b,c]', 'expire' => 1000, 'path' => '/test', 'secure' => true);
$response->cookie($cookie);
$expected = array('CakeTestCookie[Testing]' => array('name' => 'CakeTestCookie[Testing]', 'value' => '', 'expire' => 0, 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false), 'CakeTestCookie[Testing2]' => array('name' => 'CakeTestCookie[Testing2]', 'value' => '[a,b,c]', 'expire' => 1000, 'path' => '/test', 'domain' => '', 'secure' => true, 'httpOnly' => false));
$result = $response->cookie();
$this->assertEquals($expected, $result);
$cookie = $expected['CakeTestCookie[Testing]'];
$cookie['value'] = 'test';
$response->cookie($cookie);
$expected = array('CakeTestCookie[Testing]' => array('name' => 'CakeTestCookie[Testing]', 'value' => 'test', 'expire' => 0, 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false), 'CakeTestCookie[Testing2]' => array('name' => 'CakeTestCookie[Testing2]', 'value' => '[a,b,c]', 'expire' => 1000, 'path' => '/test', 'domain' => '', 'secure' => true, 'httpOnly' => false));
$result = $response->cookie();
$this->assertEquals($expected, $result);
}
开发者ID:aichelman,项目名称:StudyUp,代码行数:25,代码来源:CakeResponseTest.php
注:本文中的CakeResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论