aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pinq
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2012-11-12 11:36:35 +0000
committerRomain d'Alverny <rda@mageia.org>2012-11-12 11:36:35 +0000
commite7994a2e072ed5dbb6844b631028d4e712bfb40a (patch)
treef8e53917a99eb78d3bfe2970d8018756b4be6237 /lib/pinq
parentce07e3d3f4cd90bedd0107d8b4b1bf07d29d0afd (diff)
downloadwww-e7994a2e072ed5dbb6844b631028d4e712bfb40a.tar
www-e7994a2e072ed5dbb6844b631028d4e712bfb40a.tar.gz
www-e7994a2e072ed5dbb6844b631028d4e712bfb40a.tar.bz2
www-e7994a2e072ed5dbb6844b631028d4e712bfb40a.tar.xz
www-e7994a2e072ed5dbb6844b631028d4e712bfb40a.zip
better code structure
Diffstat (limited to 'lib/pinq')
-rw-r--r--lib/pinq/Controller.php58
1 files changed, 40 insertions, 18 deletions
diff --git a/lib/pinq/Controller.php b/lib/pinq/Controller.php
index 8ceb26ade..1c418675e 100644
--- a/lib/pinq/Controller.php
+++ b/lib/pinq/Controller.php
@@ -43,10 +43,9 @@ class Pinq_Controller
//
} else {
-
$res = $pc->_run($routes);
- if (isset($cache)) {
+ if (isset($cache) && $res['cache'] > 0) {
$cache->set($res, $pc->cache_key());
}
}
@@ -81,10 +80,13 @@ class Pinq_Controller
public function publish($res)
{
- foreach ($res['Headers'] as $h) {
+ //$res['statuts']
+ // Content-Length must match buffer + body
+ foreach ($res['headers'] as $h => $v) {
header($h);
}
- echo $res['Body'];
+ echo $res['buffer'];
+ echo $res['body'];
}
@@ -105,14 +107,43 @@ class Pinq_Controller
$this->lang = 'en';
}
- // delegate to declared routes/apps
+ // TODO ob_start, etc.?
+
+ // 1.
+ if ($app = $this->matches_route($this->uri, $routes)) {
+ return $this->delegate_to($app);
+ }
+
+ // 2.
+ // delegate to local script
+ // TODO look at local code at $uri, and decide if we can load it and decorate it.
+
+ // 3.
+ // finally, act as we used to before
+ if ($this->fallback_to_previous_mode($this->uri, $this->lang)) {
+ return true;
+ }
+
+ // 4.
+ // if nothing matched, well...
+ return $this->delegate_to('error', array('code' => '404'));
+ }
+
+ /**
+ * @param string $uri
+ * @param array $routes
+ *
+ * @return string
+ */
+ private function matches_route($uri, $routes)
+ {
$re = '
/
\/(([a-zA-Z\-\_]{2,5})\/)?
(.*)
/x';
- if (preg_match_all($re, $this->uri, $matches)) {
+ if (preg_match_all($re, $uri, $matches)) {
$this->_lang = $matches[2][0];
$this->_path = $matches[3][0];
}
@@ -120,22 +151,13 @@ class Pinq_Controller
if (is_array($routes) && count($routes) > 0) {
foreach ($routes as $r => $app) {
$re = '/' . $r . '/';
- if (preg_match_all($re, $this->uri, $m)) {
- return $this->delegate_to($app);
+ if (preg_match_all($re, $uri, $m)) {
+ return $app;
}
}
}
- // delegate to local script
- // TODO look at local code at $uri, and decide if we can load it and decorate it.
-
- // finally, act as we used to before
- if ($this->fallback_to_previous_mode($this->uri, $this->lang)) {
- return true;
- }
-
- // if nothing matched, well...
- return $this->delegate_to('error', array('code' => '404'));
+ return null;
}
/**