Skip to content

Commit

Permalink
Abstracted logic to own methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorton committed Apr 3, 2011
1 parent 173a2b6 commit 692c060
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 6 additions & 2 deletions classes/kohana/controller/publicize.php
Expand Up @@ -22,15 +22,19 @@ public function action_copy()
{ {
$asset = $this->request->param('asset'); $asset = $this->request->param('asset');


if (Kohana::$environment !== Kohana::DEVELOPMENT) if (Publicize::should_copy_to_docroot())
{ {
$uri = $this->request->param('uri'); $uri = $this->request->param('uri');


// Copy and redirect // Copy and redirect
Publicize::copy_to_docroot($asset, $uri); 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 // Show live copy
$this->response->send_file($asset); $this->response->send_file($asset);
} }
Expand Down
24 changes: 23 additions & 1 deletion classes/kohana/publicize.php
Expand Up @@ -16,13 +16,35 @@ class Kohana_Publicize {
const PUBLIC_FOLDER = 'public'; 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. * Sets route if not in production.
* *
* @return void * @return void
*/ */
public static function set_route() public static function set_route()
{ {
if (Kohana::$environment !== Kohana::PRODUCTION) if (self::should_set_route())
{ {
self::_set_route(); self::_set_route();
} }
Expand Down

0 comments on commit 692c060

Please sign in to comment.