From 692c06082d57a92fbe819047291a75dd4179a864 Mon Sep 17 00:00:00 2001 From: Luke Morton Date: Sun, 3 Apr 2011 15:46:22 +0100 Subject: [PATCH] Abstracted logic to own methods --- classes/kohana/controller/publicize.php | 8 ++++++-- classes/kohana/publicize.php | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/classes/kohana/controller/publicize.php b/classes/kohana/controller/publicize.php index 95e028b..666cfb0 100644 --- a/classes/kohana/controller/publicize.php +++ b/classes/kohana/controller/publicize.php @@ -22,15 +22,19 @@ public function action_copy() { $asset = $this->request->param('asset'); - if (Kohana::$environment !== Kohana::DEVELOPMENT) + if (Publicize::should_copy_to_docroot()) { $uri = $this->request->param('uri'); // Copy and redirect Publicize::copy_to_docroot($asset, $uri); - $this->request->redirect($uri); + //$this->request->redirect($uri); } + // Send last modified headers so browsers have a chance + $this->response->headers('Last-Modified', + date(DATE_RFC1123, filemtime($asset))); + // Show live copy $this->response->send_file($asset); } diff --git a/classes/kohana/publicize.php b/classes/kohana/publicize.php index 8147bd4..980fcd6 100644 --- a/classes/kohana/publicize.php +++ b/classes/kohana/publicize.php @@ -16,13 +16,35 @@ class Kohana_Publicize { const PUBLIC_FOLDER = 'public'; /** + * Should we copy to docroot? We should if not in the + * development environment. + * + * @return boolean + */ + public static function should_copy_to_docroot() + { + return Kohana::$environment !== Kohana::DEVELOPMENT; + } + + /** + * Should we set route? We should if not in the + * production environment. + * + * @return boolean + */ + public static function should_set_route() + { + return Kohana::$environment !== Kohana::PRODUCTION; + } + +/** * Sets route if not in production. * * @return void */ public static function set_route() { - if (Kohana::$environment !== Kohana::PRODUCTION) + if (self::should_set_route()) { self::_set_route(); }