Browse Source

Changed existing code to match the changes regarding response

tags/2.0.0-beta
Carsten Brandt 12 years ago
parent
commit
71782b344e
  1. 4
      apps/advanced/backend/controllers/SiteController.php
  2. 6
      apps/advanced/frontend/controllers/SiteController.php
  3. 6
      apps/basic/controllers/SiteController.php
  4. 2
      framework/yii/base/Controller.php
  5. 10
      framework/yii/base/ErrorHandler.php
  6. 2
      framework/yii/web/CaptchaAction.php
  7. 9
      framework/yii/web/HttpCache.php
  8. 2
      framework/yii/web/Request.php
  9. 9
      framework/yii/web/User.php
  10. 2
      framework/yii/web/VerbFilter.php
  11. 3
      tests/unit/framework/helpers/HtmlTest.php

4
apps/advanced/backend/controllers/SiteController.php

@ -17,7 +17,7 @@ class SiteController extends Controller
{
$model = new LoginForm();
if ($this->populate($_POST, $model) && $model->login()) {
return Yii::$app->response->redirect(array('site/index'));
return $this->response->redirect(array('site/index'));
} else {
return $this->render('login', array(
'model' => $model,
@ -28,6 +28,6 @@ class SiteController extends Controller
public function actionLogout()
{
Yii::$app->user->logout();
return Yii::$app->response->redirect(array('site/index'));
return $this->response->redirect(array('site/index'));
}
}

6
apps/advanced/frontend/controllers/SiteController.php

@ -27,7 +27,7 @@ class SiteController extends Controller
{
$model = new LoginForm();
if ($this->populate($_POST, $model) && $model->login()) {
return Yii::$app->response->redirect(array('site/index'));
return $this->response->redirect(array('site/index'));
} else {
return $this->render('login', array(
'model' => $model,
@ -38,7 +38,7 @@ class SiteController extends Controller
public function actionLogout()
{
Yii::$app->user->logout();
return Yii::$app->response->redirect(array('site/index'));
return $this->response->redirect(array('site/index'));
}
public function actionContact()
@ -46,7 +46,7 @@ class SiteController extends Controller
$model = new ContactForm;
if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return Yii::$app->response->refresh();
return $this->response->refresh();
} else {
return $this->render('contact', array(
'model' => $model,

6
apps/basic/controllers/SiteController.php

@ -27,7 +27,7 @@ class SiteController extends Controller
{
$model = new LoginForm();
if ($this->populate($_POST, $model) && $model->login()) {
return Yii::$app->response->redirect(array('site/index'));
return $this->response->redirect(array('site/index'));
} else {
return $this->render('login', array(
'model' => $model,
@ -38,7 +38,7 @@ class SiteController extends Controller
public function actionLogout()
{
Yii::$app->user->logout();
return Yii::$app->response->redirect(array('site/index'));
return $this->response->redirect(array('site/index'));
}
public function actionContact()
@ -46,7 +46,7 @@ class SiteController extends Controller
$model = new ContactForm;
if ($this->populate($_POST, $model) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return Yii::$app->response->refresh();
return $this->response->refresh();
} else {
return $this->render('contact', array(
'model' => $model,

2
framework/yii/base/Controller.php

@ -15,7 +15,7 @@ use Yii;
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Controller extends Component
abstract class Controller extends Component
{
/**
* @event ActionEvent an event raised right before executing a controller action.

10
framework/yii/base/ErrorHandler.php

@ -9,6 +9,7 @@ namespace yii\base;
use Yii;
use yii\web\HttpException;
use yii\web\Response;
/**
* ErrorHandler handles uncaught PHP errors and exceptions.
@ -89,8 +90,13 @@ class ErrorHandler extends Component
$useErrorView = !YII_DEBUG || $exception instanceof UserException;
$response = Yii::$app->getResponse();
$response->getHeaders()->removeAll();
if (Yii::$app->controller !== null) {
$response = Yii::$app->controller->getResponse();
$response->getHeaders()->removeAll();
}
if (empty($response)) {
$response = new Response();
}
if ($useErrorView && $this->errorAction !== null) {
$result = Yii::$app->runAction($this->errorAction);

2
framework/yii/web/CaptchaAction.php

@ -325,7 +325,7 @@ class CaptchaAction extends Action
*/
protected function setHttpHeaders()
{
Yii::$app->getResponse()->getHeaders()
$this->getResponse()->getHeaders()
->set('Pragma', 'public')
->set('Expires', '0')
->set('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')

9
framework/yii/web/HttpCache.php

@ -74,8 +74,8 @@ class HttpCache extends ActionFilter
$etag = $this->generateEtag($seed);
}
$this->sendCacheControlHeader();
$response = Yii::$app->getResponse();
$response = $action->getResponse();
$this->sendCacheControlHeader($response);
if ($etag !== null) {
$response->getHeaders()->set('Etag', $etag);
}
@ -109,12 +109,13 @@ class HttpCache extends ActionFilter
/**
* Sends the cache control header to the client
* @param Response $response
* @see cacheControl
*/
protected function sendCacheControlHeader()
protected function sendCacheControlHeader($response)
{
session_cache_limiter('public');
$headers = Yii::$app->getResponse()->getHeaders();
$headers = $response->getHeaders();
$headers->set('Pragma');
if ($this->cacheControlHeader !== null) {
$headers->set('Cache-Control', $this->cacheControlHeader);

2
framework/yii/web/Request.php

@ -788,7 +788,7 @@ class Request extends \yii\base\Request
$this->_csrfCookie = $this->getCookies()->get($this->csrfTokenName);
if ($this->_csrfCookie === null) {
$this->_csrfCookie = $this->createCsrfCookie();
Yii::$app->getResponse()->getCookies()->add($this->_csrfCookie);
Yii::$app->controller->getResponse()->getCookies()->add($this->_csrfCookie);
}
}

9
framework/yii/web/User.php

@ -283,8 +283,7 @@ class User extends Component
$this->setReturnUrl($request->getUrl());
}
if ($this->loginUrl !== null) {
$response = Yii::$app->getResponse();
$response->redirect($this->loginUrl)->send();
Yii::$app->controller->getResponse()->redirect($this->loginUrl)->send();
exit();
} else {
throw new HttpException(403, Yii::t('yii', 'Login Required'));
@ -372,7 +371,7 @@ class User extends Component
$cookie = new Cookie($this->identityCookie);
$cookie->value = $value;
$cookie->expire = time() + (int)$data[2];
Yii::$app->getResponse()->getCookies()->add($cookie);
Yii::$app->controller->getResponse()->getCookies()->add($cookie);
}
}
}
@ -395,7 +394,7 @@ class User extends Component
$duration,
));
$cookie->expire = time() + $duration;
Yii::$app->getResponse()->getCookies()->add($cookie);
Yii::$app->controller->getResponse()->getCookies()->add($cookie);
}
/**
@ -429,7 +428,7 @@ class User extends Component
$this->sendIdentityCookie($identity, $duration);
}
} elseif ($this->enableAutoLogin) {
Yii::$app->getResponse()->getCookies()->remove(new Cookie($this->identityCookie));
Yii::$app->controller->getResponse()->getCookies()->remove(new Cookie($this->identityCookie));
}
}

2
framework/yii/web/VerbFilter.php

@ -80,7 +80,7 @@ class VerbFilter extends Behavior
if (!in_array($verb, $allowed)) {
$event->isValid = false;
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7
Yii::$app->getResponse()->getHeaders()->set('Allow', implode(', ', $allowed));
$event->action->getResponse()->getHeaders()->set('Allow', implode(', ', $allowed));
throw new HttpException(405, 'Method Not Allowed. This url can only handle the following request methods: ' . implode(', ', $allowed));
}
}

3
tests/unit/framework/helpers/HtmlTest.php

@ -17,9 +17,6 @@ class HtmlTest extends TestCase
'class' => 'yii\web\Request',
'url' => '/test',
),
'response' => array(
'class' => 'yii\web\Response',
),
),
));
}

Loading…
Cancel
Save