/** * 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; }
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; }
/** * 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(); }
/** * 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(); }
/** * 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; }
/** * 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()); }
/** * 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; }
/** * 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); }
/** * 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()); }
/** * 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); }
public function __construct(array $options = array()) { parent::__construct($options); # additional status codes $this->_statusCodes[418] = 'MPApiException'; $this->_statusCodes[422] = 'MPValidationException'; }
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 } }
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(); }
/** * * @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; }
/** * Maps a content type alias back to its mime-type(s) * * @param string|array $alias String alias to convert back into a content type. Or an array of aliases to map. * @return string Null on an undefined alias. String value of the mapped alias type. If an * alias maps to more than one content type, the first one will be returned. */ public function mapAlias($alias) { if (is_array($alias)) { return array_map(array($this, 'mapAlias'), $alias); } $type = $this->response->getMimeType($alias); if ($type) { if (is_array($type)) { return $type[0]; } return $type; } return null; }
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; }
/** * Returns an audio/video element * * ### Usage * * Using an audio file: * * `echo $this->Html->media('audio.mp3', array('fullBase' => true));` * * Outputs: * * `<video src="http://www.somehost.com/files/audio.mp3">Fallback text</video>` * * Using a video file: * * `echo $this->Html->media('video.mp4', array('text' => 'Fallback text'));` * * Outputs: * * `<video src="/files/video.mp4">Fallback text</video>` * * Using multiple video files: * * ``` * echo $this->Html->media( * array('video.mp4', array('src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'")), * array('tag' => 'video', 'autoplay') * ); * ``` * * Outputs: * * ``` * <video autoplay="autoplay"> * <source src="/files/video.mp4" type="video/mp4"/> * <source src="/files/video.ogv" type="video/ogv; codecs='theora, vorbis'"/> * </video> * ``` * * ### Options * * - `tag` Type of media element to generate, either "audio" or "video". * If tag is not provided it's guessed based on file's mime type. * - `text` Text to include inside the audio/video tag * - `pathPrefix` Path prefix to use for relative URLs, defaults to 'files/' * - `fullBase` If provided the src attribute will get a full address including domain name * * @param string|array $path Path to the video file, relative to the webroot/{$options['pathPrefix']} directory. * Or an array where each item itself can be a path string or an associate array containing keys `src` and `type` * @param array $options Array of HTML attributes, and special options above. * @return string Generated media element */ public function media($path, $options = array()) { $options += array('tag' => null, 'pathPrefix' => 'files/', 'text' => ''); if (!empty($options['tag'])) { $tag = $options['tag']; } else { $tag = null; } if (is_array($path)) { $sourceTags = ''; foreach ($path as &$source) { if (is_string($source)) { $source = array('src' => $source); } if (!isset($source['type'])) { $ext = pathinfo($source['src'], PATHINFO_EXTENSION); $source['type'] = $this->response->getMimeType($ext); } $source['src'] = $this->assetUrl($source['src'], $options); $sourceTags .= $this->useTag('tagselfclosing', 'source', $source); } unset($source); $options['text'] = $sourceTags . $options['text']; unset($options['fullBase']); } else { if (empty($path) && !empty($options['src'])) { $path = $options['src']; } $options['src'] = $this->assetUrl($path, $options); } if ($tag === null) { if (is_array($path)) { $mimeType = $path[0]['type']; } else { $mimeType = $this->response->getMimeType(pathinfo($path, PATHINFO_EXTENSION)); } if (preg_match('#^video/#', $mimeType)) { $tag = 'video'; } else { $tag = 'audio'; } } if (isset($options['poster'])) { $options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => Configure::read('App.imageBaseUrl')) + $options); } $text = $options['text']; $options = array_diff_key($options, array('tag' => null, 'fullBase' => null, 'pathPrefix' => null, 'text' => null)); return $this->tag($tag, $text, $options); }
/** * test beforeRender() method * * @test */ public function beforeRender() { $this->generateComponent(['mocks' => ['Api' => ['isApiRequest', 'failure', 'setResponse', '_getDbLog', 'getResponse']], 'componentOptions' => ['logDb' => true]]); $this->Api->expects($this->once())->method('failure'); $this->Api->expects($this->once())->method('isApiRequest')->will($this->returnValue(true)); $this->Api->expects($this->once())->method('_getDbLog')->will($this->returnValue('testDbLog')); $this->Api->expects($this->once())->method('setResponse')->with('dbLog', 'testDbLog'); $this->Api->expects($this->once())->method('getResponse')->will($this->returnValue(['code' => 401])); $this->Api->beforeRender($this->controller); $this->assertSame(401, $this->response->statusCode()); $this->assertArrayHasKey('response', $this->controller->viewVars); $this->assertSame(['code' => 401], $this->controller->viewVars['response']); $this->assertArrayHasKey('_serialize', $this->controller->viewVars); $this->assertSame('response', $this->controller->viewVars['_serialize']); $this->assertSame('Json', $this->controller->viewClass); }
/** * 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); }
/** * Sends an asset file to the client * * @param string $assetFile Path to the asset file in the file system * @param string $ext The extension of the file to determine its mime type * @return void */ protected function _deliverAsset($assetFile, $ext) { ob_start(); $compressionEnabled = Configure::read('Asset.compress') && $this->response->compress(); if ($this->response->type($ext) == $ext) { $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'; } $this->response->type($contentType); } $this->response->cache(filemtime($assetFile)); $this->response->send(); ob_clean(); if ($ext === 'css' || $ext === 'js') { include $assetFile; } else { readfile($assetFile); } if ($compressionEnabled) { ob_end_flush(); } }
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(); } }
/** * Sets a cookie expire time to remove cookie value * * @param string $name Name of cookie * @return void */ protected function _delete($name) { $this->_response->cookie(array('name' => $this->name . $name, 'value' => '', 'expire' => time() - 42000, 'path' => $this->path, 'domain' => $this->domain, 'secure' => $this->secure, 'httpOnly' => $this->httpOnly)); }
/** * 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.'); }
/** * 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(); }
/** * 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); }
/** * 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); }
/** * Tests the mapType method * */ public function testMapType() { $response = new CakeResponse(); $this->assertEquals('wav', $response->mapType('audio/x-wav')); $this->assertEquals('pdf', $response->mapType('application/pdf')); $this->assertEquals('xml', $response->mapType('text/xml')); $this->assertEquals('html', $response->mapType('*/*')); $this->assertEquals('csv', $response->mapType('application/vnd.ms-excel')); $expected = array('json', 'xhtml', 'css'); $result = $response->mapType(array('application/json', 'application/xhtml+xml', 'text/css')); $this->assertEquals($expected, $result); }
/** * Processes the feed and rebuilds an array based on the feeds type (RSS, RDF, Atom). * * @access protected * @param CakeResponse $response * @param array $query * @param string $source * @return boolean */ protected function _process($response, $query, $source) { $feed = TypeConverter::toArray($response->body()); $clean = array(); if (!empty($query['root']) && !empty($feed[$query['feed']['root']])) { $items = $feed[$query['feed']['root']]; } else { // Rss if (isset($feed['channel']) && isset($feed['channel']['item'])) { $items = $feed['channel']['item']; // Rdf } else { if (isset($feed['item'])) { $items = $feed['item']; // Atom } else { if (isset($feed['entry'])) { $items = $feed['entry']; // Xml } else { $items = $feed; } } } } if (empty($items) || !is_array($items)) { return $clean; } // Gather elements $elements = array('title', 'guid' => array('guid', 'id'), 'date' => array('date', 'pubDate', 'published', 'updated'), 'link' => array('link', 'origLink'), 'image' => array('image', 'thumbnail'), 'author' => array('author', 'writer', 'editor', 'user'), 'source' => array('source'), 'description' => array('description', 'desc', 'summary', 'content', 'text')); if (is_array($query['fields'])) { $elements = array_merge_recursive($elements, $query['fields']); } // Loop the feed foreach ($items as $item) { $data = array(); foreach ($elements as $element => $keys) { if (is_numeric($element)) { $element = $keys; $keys = array($keys); } if (isset($keys['attributes'])) { $attributes = $keys['attributes']; unset($keys['attributes']); } else { $attributes = array('value', 'href', 'src', 'name', 'label'); } if (isset($keys['keys'])) { $keys = $keys['keys']; } foreach ($keys as $key) { if (isset($item[$key]) && empty($data[$element])) { $value = $this->_extract($item[$key], $attributes); if (!empty($value)) { $data[$element] = $value; break; } } } } if (empty($data['link'])) { trigger_error(sprintf('Feed %s does not have a valid link element.', $source), E_USER_NOTICE); continue; } if (empty($data['source']) && $source) { $data['source'] = (string) $source; } $sort = null; if (isset($data[$query['feed']['sort']])) { $sort = $data[$query['feed']['sort']]; } if (!$sort) { if ($query['feed']['sort'] == 'date' && isset($data['date'])) { $sort = strtotime($data['date']); } else { $sort = microtime(); } } if (!empty($data)) { $clean[$sort] = $data; } } return $clean; }
/** * Forces the user's browser not to cache the results of the current request. * * @return void * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::disableCache * @deprecated 3.0.0 Will be removed in 3.0. Use CakeResponse::disableCache(). */ public function disableCache() { $this->response->disableCache(); }
/** * Tests the outputCompressed method * */ public function testOutputCompressed() { $response = new CakeResponse(); $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip'; $result = $response->outputCompressed(); $this->assertFalse($result); $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; $result = $response->outputCompressed(); $this->assertFalse($result); if (!extension_loaded("zlib")) { $this->markTestSkipped('Skipping further tests for outputCompressed as zlib extension is not loaded'); } if (php_sapi_name() !== 'cli') { $this->markTestSkipped('Testing outputCompressed method with compression enabled done only in cli'); } if (ini_get("zlib.output_compression") !== '1') { ob_start('ob_gzhandler'); } $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip'; $result = $response->outputCompressed(); $this->assertTrue($result); $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; $result = $response->outputCompressed(); $this->assertFalse($result); if (ini_get("zlib.output_compression") !== '1') { ob_get_clean(); } }