Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed Oct 5, 2009
1 parent 87af17f commit a8ecabf
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
43 changes: 43 additions & 0 deletions library/PlanetPEAR.php
Expand Up @@ -5,6 +5,11 @@ class PlanetPEAR
protected $queryRestriction; // no idea
protected $tally = 10; // blog entries per page

/**
* Request data.
*/
protected $controller, $action, $from, $query;

/**
* @param MDB2_Common $db Optional MDB2 object.
*
Expand Down Expand Up @@ -76,6 +81,24 @@ public function getBlogs($section = 'default', $forceAll = false)
return $res;
}

public function getCacheName()
{
if ($this->isQuery()) {
return 'search' . $query;
}
return sprintf(
'%s-%s-%s',
$this->controller,
$this->action,
$this->from
);
}

public function getController()
{
return $this->controller;
}

/**
* Fetch and return a list of all feeds
*
Expand Down Expand Up @@ -219,6 +242,8 @@ public function getNavigation($startKey)
return $navigation;
}



public function isQuery()
{
if (!empty($this->query)) {
Expand All @@ -227,6 +252,24 @@ public function isQuery()
return false;
}

public function setAction($action)
{
$this->action = strtolower($action);
return $this;
}

public function setController($controller)
{
$this->controller = ucfirst(strtolower($controller));
return $this;
}

public function setFrom($from)
{
$this->from = $from;
return $this;
}

public function setQuery($query)
{
$this->query = trim($query);
Expand Down
27 changes: 22 additions & 5 deletions public/router.php
Expand Up @@ -26,19 +26,36 @@
$query = (string) @$_GET['search'];
if (!empty($query)) {
$match['action'] = 'page';
} else {
$query = null;
}

if (!isset($match['from'])) {
$from = 0;
} else {
$from = (int) $match['from'];
}

$planet = new PlanetPEAR;
$planet->setController($match['controller']);
$planet->setAction($match['action']);
$planet->setFrom($from);
$planet->setQuery($query);

$controller = 'PlanetPEAR_Controller_' . ucfirst(strtolower($match['controller']));

$controller = 'PlanetPEAR_Controller_' . $planet->getController();
$controllerObj = new $controller($planet);

if (!isset($match['from'])) {
$from = 0;
$cacheName = $planet->getCacheName();

if ($query !== null) {
$cacheName = 'search' . $query;
} else {
$from = (int) $match['from'];
$cacheName = sprintf(
'%s-%s-%s',
strtolower($match['controller']),
strtolower($match['action']),
$from
);
}

try {
Expand Down

0 comments on commit a8ecabf

Please sign in to comment.