aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain d'Alverny <rda@mageia.org>2012-11-12 11:36:31 +0000
committerRomain d'Alverny <rda@mageia.org>2012-11-12 11:36:31 +0000
commitce07e3d3f4cd90bedd0107d8b4b1bf07d29d0afd (patch)
tree45a342e145c7559d88e3e9eac4405835fdce6364
parent77a3e2e20abdb74dc1e872204edc1e0474bbab44 (diff)
downloadwww-ce07e3d3f4cd90bedd0107d8b4b1bf07d29d0afd.tar
www-ce07e3d3f4cd90bedd0107d8b4b1bf07d29d0afd.tar.gz
www-ce07e3d3f4cd90bedd0107d8b4b1bf07d29d0afd.tar.bz2
www-ce07e3d3f4cd90bedd0107d8b4b1bf07d29d0afd.tar.xz
www-ce07e3d3f4cd90bedd0107d8b4b1bf07d29d0afd.zip
reorg code, license headers
-rw-r--r--app.php19
-rw-r--r--lib/pinq/App.php8
-rw-r--r--lib/pinq/Cache.php55
-rw-r--r--lib/pinq/Controller.php61
4 files changed, 129 insertions, 14 deletions
diff --git a/app.php b/app.php
index 5dc16a38a..86db0b9e4 100644
--- a/app.php
+++ b/app.php
@@ -22,16 +22,19 @@
* option) any later version.
*/
-require 'lib/Pinq/Controller.php';
-require 'lib/Pinq/App.php';
-
-$pc = new Pinq_Controller(__DIR__, $_SERVER);
-$pc->init();
-
$routes = array(
-// 'downloads' => 'MGA_Downloads'
+ //'downloads' => 'MGA_Downloads'
);
-$pc->run($routes);
+require 'lib/Pinq/Controller.php';
+require 'lib/Pinq/App.php';
+require 'lib/Pinq/Cache.php';
+$cache = new Pinq_Memcache_Cache(20);
+Pinq_Controller::run(
+ __DIR__,
+ $routes,
+ $_SERVER,
+ new Pinq_Memcache_Cache(20)
+);
diff --git a/lib/pinq/App.php b/lib/pinq/App.php
index 2f2ebd88a..587b47a86 100644
--- a/lib/pinq/App.php
+++ b/lib/pinq/App.php
@@ -6,11 +6,17 @@
* @category Mageia
* @package Mageia\Web\www\Pinq
* @author rda <rda@mageia.org>
- * @license http://www.gnu.org/licenses/gpl-2.0.html GPL-2+
* @link http://www.mageia.org/
*
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2+
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License aspublished by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
*/
+
/**
*/
abstract class Pinq_App
diff --git a/lib/pinq/Cache.php b/lib/pinq/Cache.php
new file mode 100644
index 000000000..8a5a3d4d1
--- /dev/null
+++ b/lib/pinq/Cache.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ *
+ * PHP version 5.4
+ *
+ * @category Mageia
+ * @package Mageia\Web\www\Pinq
+ * @author rda <rda@mageia.org>
+ * @link http://www.mageia.org/
+ *
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2+
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License aspublished by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+*/
+
+abstract class Pinq_Cache
+{
+ abstract public function __construct();
+
+ /**
+ * @param string $key
+ *
+ * @return mixed
+ */
+ abstract public function get($key);
+
+ /**
+ * @param mixed $value
+ * @param string $key
+ * @param integer $timeout
+ */
+ abstract public function set($value, $key, $timeout = 0);
+}
+
+class Pinq_Memcache_Cache extends Pinq_Cache
+{
+
+ public function __construct($timeout = 0)
+ {
+ $this->timeout = $timeout;
+ }
+
+ public function get($key)
+ {
+
+ }
+
+ public function set($value, $key, $timeout = 0)
+ {
+ $timeout = $timeout > 0 ? $timeout : $this->timeout;
+ }
+} \ No newline at end of file
diff --git a/lib/pinq/Controller.php b/lib/pinq/Controller.php
index 6043cc0e1..8ceb26ade 100644
--- a/lib/pinq/Controller.php
+++ b/lib/pinq/Controller.php
@@ -6,9 +6,14 @@
* @category Mageia
* @package Mageia\Web\www\Pinq
* @author rda <rda@mageia.org>
- * @license http://www.gnu.org/licenses/gpl-2.0.html GPL-2+
* @link http://www.mageia.org/
*
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2+
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License aspublished by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
*/
/**
@@ -28,9 +33,34 @@ class Pinq_Controller
/**
*/
+ public static function run($app_root, $routes, $_server, $cache)
+ {
+ $pc = new self($app_root, $_server);
+ $pc->init();
+
+ if (isset($cache)
+ && $res = $cache->get($pc->get_cache_key())) {
+
+ //
+ } else {
+
+ $res = $pc->_run($routes);
+
+ if (isset($cache)) {
+ $cache->set($res, $pc->cache_key());
+ }
+ }
+
+ $pc->publish($res);
+ unset($pc);
+ }
+
+ /**
+ */
public function init()
{
- $this->uri = $this->_server['REQUEST_URI'];
+ $this->method = $this->_server['REQUEST_METHOD'];
+ $this->uri = $this->_server['REQUEST_URI'];
if (strpos('?', $this->uri) !== false) {
$uri = explode('?', $this->uri);
@@ -40,18 +70,39 @@ class Pinq_Controller
}
/**
+ */
+ public function get_cache_key()
+ {
+ return sha1(implode('#', array($this->method, $this->uri)));
+ }
+
+ /**
+ */
+ public function publish($res)
+ {
+
+ foreach ($res['Headers'] as $h) {
+ header($h);
+ }
+ echo $res['Body'];
+
+ }
+
+ /**
* @param array $routes
*
* @return boolean
*/
- public function run($routes = null)
+ private function _run($routes = null)
{
// static, image files are expected to be served directly by the server.
// detect path language; if not set, redirect to best fallback language (English for now), end
$this->lang = $this->get_request_language($this->uri);
+
if (!$this->lang_is_managed($this->lang)) {
- // TODO
+ // TODO - ignore, with a special code or redirect?
+ $this->lang = 'en';
}
// delegate to declared routes/apps
@@ -144,7 +195,7 @@ class Pinq_Controller
function fallback_to_previous_mode($uri, $lang)
{
$alt_uri = sprintf(
- '/%s/%s',
+ '/%s/%s',
'en',
substr($uri, strlen($lang) + 2)
);