This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "quickfw".
The branch, subroute has been created
at ddc51b78706a466a33e92c911020a03f3444a15e (commit)
- Log -----------------------------------------------------------------
commit ddc51b78706a466a33e92c911020a03f3444a15e
Author: Ivan Borzenkov <iva...@li...>
Date: Fri Feb 4 17:52:52 2011 +0300
Затирались бэкреврайты при втором вызове урла
diff --git a/QFW/QuickFW/Router.php b/QFW/QuickFW/Router.php
index fbba6cc..2e75205 100644
--- a/QFW/QuickFW/Router.php
+++ b/QFW/QuickFW/Router.php
@@ -422,6 +422,8 @@ class QuickFW_Router
$this->backrewrite = $backrewrite;
if (!$this->sub)
$this->backrewriteUrl = $backrewriteUrl;
+ else
+ $this->backrewriteUrl = null;
}
if (empty($this->$type))
return $uri;
commit 844e5d9135d0e5baad2fd2ff667c003b2f3805f5
Author: Ivan Borzenkov <iva...@li...>
Date: Thu Feb 3 14:48:55 2011 +0300
Саброутинг - корректные реврайты в урлах
diff --git a/QFW/QuickFW/Url.php b/QFW/QuickFW/Url.php
index f401ec2..a73611b 100644
--- a/QFW/QuickFW/Url.php
+++ b/QFW/QuickFW/Url.php
@@ -168,6 +168,20 @@ class Url
return $this->u;
}
+ /**
+ * урл для саброута
+ *
+ * @internal
+ * @return string урл
+ */
+ public function getBase()
+ {
+ return static::$config['router']->backrewriteUrl(
+ static::$config['base'].static::$config['router']->backrewrite($this->u).
+ QuickFW_Router::PATH_SEPARATOR
+ );
+ }
+
}
?>
diff --git a/QFW/sub.php b/QFW/sub.php
index 111089f..a584062 100644
--- a/QFW/sub.php
+++ b/QFW/sub.php
@@ -33,10 +33,9 @@ class Url extends \Url { protected static $config;}
function run($args, $count)
{
$base = join(\QuickFW_Router::PATH_SEPARATOR, \array_slice($args, 0, $count));
- $base = \Url::base(\Url::A($base)->intern());
$uri = join(\QuickFW_Router::PATH_SEPARATOR, \array_slice($args, $count));
QFW::Init();
- Url::Init($base.\QuickFW_Router::PATH_SEPARATOR);
+ Url::Init(\Url::A($base)->getBase());
$TS = new \TemplaterState(QFW::$view);
return QFW::$router->subroute($uri, \QFW::$router->type);
}
commit 3b280697d53c0e941d0e4c1fc023ff60b94b4825
Author: Ivan Borzenkov <iva...@li...>
Date: Thu Feb 3 13:37:49 2011 +0300
Разбор части урла на встроенных функциях без цикла
diff --git a/QFW/sub.php b/QFW/sub.php
index ab2a8ae..111089f 100644
--- a/QFW/sub.php
+++ b/QFW/sub.php
@@ -32,10 +32,9 @@ class Url extends \Url { protected static $config;}
*/
function run($args, $count)
{
- $base = \Url::base(\Url::A('')->intern());
- while($count--)
- $base.= \QuickFW_Router::PATH_SEPARATOR.array_shift($args);
- $uri = join(\QuickFW_Router::PATH_SEPARATOR, $args);
+ $base = join(\QuickFW_Router::PATH_SEPARATOR, \array_slice($args, 0, $count));
+ $base = \Url::base(\Url::A($base)->intern());
+ $uri = join(\QuickFW_Router::PATH_SEPARATOR, \array_slice($args, $count));
QFW::Init();
Url::Init($base.\QuickFW_Router::PATH_SEPARATOR);
$TS = new \TemplaterState(QFW::$view);
commit c8ca0b1275839a5868a1670479e48a9ceb399dd0
Author: Ivan Borzenkov <iva...@li...>
Date: Tue Feb 1 16:12:47 2011 +0300
Автолоад - загрузка классов контроллеров из неймспейсов
diff --git a/QFW/QuickFW/Autoload.php b/QFW/QuickFW/Autoload.php
index 9ede401..f9b5704 100644
--- a/QFW/QuickFW/Autoload.php
+++ b/QFW/QuickFW/Autoload.php
@@ -35,13 +35,15 @@ class Autoload
//пространство имен
if ($pos = mb_strpos($class, '\\'))
{
- $file =
- strtolower(mb_substr($class, 0, $pos)).
- '/'.QuickFW_Router::CONTROLLERS_DIR.'/'.
- ucfirst(mb_substr($class, $pos+1));
+ $ns = strtolower(mb_substr($class, 0, $pos));
+ $class = ucfirst(mb_substr($class, $pos+1));
+ $Q = $ns.'\QFW';
+ //Проверка на саброутинг
+ $dir = !class_exists($Q) ? $ns : QFW::$router->cModule.'/'.$ns.'/'.$Q::$router->cModule;
}
else
- $file = QFW::$router->cModule.'/'.QuickFW_Router::CONTROLLERS_DIR.'/'.$class;
+ $dir = QFW::$router->cModule;
+ $file = $dir.'/'.QuickFW_Router::CONTROLLERS_DIR.'/'.$class;
require APPPATH.'/'.$file.'.php';
return true;
}
commit 50750d384def8db6b9d5b703d5cbd15b278fa03f
Author: Ivan Borzenkov <iva...@li...>
Date: Tue Feb 1 10:56:23 2011 +0300
Вызов блока из саброута
diff --git a/QFW/Templater/Templater.php b/QFW/Templater/Templater.php
index 1ff31ce..f5e6059 100644
--- a/QFW/Templater/Templater.php
+++ b/QFW/Templater/Templater.php
@@ -136,6 +136,22 @@ abstract class Templater
}
/**
+ * Вызывает выполнение блока и возвращает результат
+ *
+ * @param string $ns неймспейс из которого вызвать (должен быть инициализирован)
+ * @param string $block имя блока (MCA)
+ * @return string результат работы блока
+ */
+ public function localBlock($ns, $block)
+ {
+ //TODO: убрать ненужную переменную после перехода на php 5.3
+ $args = func_get_args();
+ array_shift($args);
+ $c = $ns.'\QFW';
+ return call_user_func_array(array($c::$router, 'blockRoute'), $args);
+ }
+
+ /**
* Синоним fetch
*/
public function render($tmpl, $vars=array())
commit 21a82c9f77672df4c1b869977faa25742c40150e
Author: Ivan Borzenkov <iva...@li...>
Date: Mon Jan 31 20:25:18 2011 +0300
Исправлена ошибка - не изменяем baseurl в конфиге
diff --git a/QFW/QuickFW/Url.php b/QFW/QuickFW/Url.php
index 771c7c2..f401ec2 100644
--- a/QFW/QuickFW/Url.php
+++ b/QFW/QuickFW/Url.php
@@ -81,12 +81,12 @@ class Url
/**
* Инициализация класса из конфига
*/
- public static function Init()
+ public static function Init($base='')
{
+ $base = $base ? $base : QFW::$config['redirection']['baseUrl'];
$c = str_replace(__CLASS__, '', get_called_class()).'QFW';
static::$config = $c::$config['redirection'];
- static::$config['base'] = static::$config['baseUrl'].
- (static::$config['useIndex'] ? 'index.php/' : '');
+ static::$config['base'] = $base.(static::$config['useIndex'] ? 'index.php/' : '');
static::$config['ext'] = static::$config['defExt'] ? static::$config['defExt'] :
(QuickFW_Router::PATH_SEPARATOR == '/' ? '/' : '');
static::$config['router'] = $c::$router;
diff --git a/QFW/sub.php b/QFW/sub.php
index 5aea2db..ab2a8ae 100644
--- a/QFW/sub.php
+++ b/QFW/sub.php
@@ -37,8 +37,7 @@ function run($args, $count)
$base.= \QuickFW_Router::PATH_SEPARATOR.array_shift($args);
$uri = join(\QuickFW_Router::PATH_SEPARATOR, $args);
QFW::Init();
- QFW::$config['redirection']['baseUrl'] = $base.\QuickFW_Router::PATH_SEPARATOR;
- Url::Init();
+ Url::Init($base.\QuickFW_Router::PATH_SEPARATOR);
$TS = new \TemplaterState(QFW::$view);
return QFW::$router->subroute($uri, \QFW::$router->type);
}
commit 8781ae85d90778b82e454c0cabe2a18c08f6bc0b
Author: Ivan Borzenkov <iva...@li...>
Date: Mon Jan 31 19:12:05 2011 +0300
Дока по саброутингу
diff --git a/doc/asciidoc/mvc.txt b/doc/asciidoc/mvc.txt
index 5190b8a..9ff285d 100644
--- a/doc/asciidoc/mvc.txt
+++ b/doc/asciidoc/mvc.txt
@@ -133,3 +133,29 @@ class CronContriller
=====================================================================
+Саброутинг
+~~~~~~~~~~
+
+Можно сделать "подприложение" и вызывать его из экшена, при этом заново произойдет разбор указанной часто uri
+Для этого нужно в папке модуля создать произвольную папку и в нее скопировать файл +QFW/sub.php+ после чего помянять в нем имя неймспейса на новый.
+
+[source,php]
+---------------------------------------------
+//...
+class UserContriller
+{
+ //...
+ indexCli($id)
+ {
+ QFW::$view->assign('user', User::get($id));
+ include dirname(dirname(__FILE__)).'/user/sub.php';
+ return user\run(func_get_args(), 1);
+ }
+ //...
+}
+---------------------------------------------
+
+После чего вызвать функцию +run+ из неймспейса передав ей результат +func_get_args()+ и количество параметров, которые были использованы.
+Внутри папки точно так-же создаются модули с контроллерами и экшанами, модели и шаблонизатор общие.
+
+Работает только в PHP 5.3
\ No newline at end of file
commit 45e8b4959e5609038d6c532f3ddf67754a25e52b
Author: Ivan Borzenkov <iva...@li...>
Date: Mon Jan 31 19:06:04 2011 +0300
Для суброутинга сделаны урлы
diff --git a/QFW/QuickFW/Router.php b/QFW/QuickFW/Router.php
index 6f3b46a..fbba6cc 100644
--- a/QFW/QuickFW/Router.php
+++ b/QFW/QuickFW/Router.php
@@ -416,10 +416,12 @@ class QuickFW_Router
if ($this->$type === false)
{
$rewrite = $backrewrite = $backrewriteUrl = array();
- require_once APPPATH . '/rewrite.php';
+ if (!$this->sub || is_file($this->baseDir . '/rewrite.php'))
+ require_once $this->baseDir . '/rewrite.php';
$this->rewrite = $rewrite;
$this->backrewrite = $backrewrite;
- $this->backrewriteUrl = $backrewriteUrl;
+ if (!$this->sub)
+ $this->backrewriteUrl = $backrewriteUrl;
}
if (empty($this->$type))
return $uri;
diff --git a/QFW/QuickFW/Url.php b/QFW/QuickFW/Url.php
index a1fa0fd..771c7c2 100644
--- a/QFW/QuickFW/Url.php
+++ b/QFW/QuickFW/Url.php
@@ -41,7 +41,7 @@ class Url
*/
public static function M($CA='', $get='', $anchor='')
{
- return new static($CA, $get, $anchor, QFW::$router->cModule.
+ return new static($CA, $get, $anchor, static::$config['router']->cModule.
QuickFW_Router::PATH_SEPARATOR);
}
@@ -55,9 +55,9 @@ class Url
*/
public static function C($action='', $get='', $anchor='')
{
- return new static($action, $get, $anchor, QFW::$router->cModule.
+ return new static($action, $get, $anchor, static::$config['router']->cModule.
QuickFW_Router::PATH_SEPARATOR.
- QFW::$router->cController.
+ static::$config['router']->cController.
QuickFW_Router::PATH_SEPARATOR);
}
@@ -71,11 +71,11 @@ class Url
*/
public static function A($params='', $get='', $anchor='')
{
- return new static($params, $get, $anchor, QFW::$router->cModule.
+ return new static($params, $get, $anchor, static::$config['router']->cModule.
QuickFW_Router::PATH_SEPARATOR.
- QFW::$router->cController.
+ static::$config['router']->cController.
QuickFW_Router::PATH_SEPARATOR.
- QFW::$router->cAction.QuickFW_Router::PATH_SEPARATOR);
+ static::$config['router']->cAction.QuickFW_Router::PATH_SEPARATOR);
}
/**
@@ -83,11 +83,13 @@ class Url
*/
public static function Init()
{
- static::$config = QFW::$config['redirection'];
+ $c = str_replace(__CLASS__, '', get_called_class()).'QFW';
+ static::$config = $c::$config['redirection'];
static::$config['base'] = static::$config['baseUrl'].
(static::$config['useIndex'] ? 'index.php/' : '');
static::$config['ext'] = static::$config['defExt'] ? static::$config['defExt'] :
(QuickFW_Router::PATH_SEPARATOR == '/' ? '/' : '');
+ static::$config['router'] = $c::$router;
}
/** @var array QFW::$config['redirection'] */
@@ -119,7 +121,7 @@ class Url
$this->get = $get;
$this->anchor = ltrim($anchor, '#');
if (static::$config['delDef'])
- $this->u = QFW::$router->delDef($this->u);
+ $this->u = static::$config['router']->delDef($this->u);
}
/** @var string внутреннее представление адреса */
@@ -148,8 +150,8 @@ class Url
*/
public function get()
{
- return QFW::$router->backrewriteUrl(
- static::$config['base'].QFW::$router->backrewrite($this->u).
+ return static::$config['router']->backrewriteUrl(
+ static::$config['base'].static::$config['router']->backrewrite($this->u).
($this->u!=='' ? static::$config['ext'] : '').
($this->get ? '?' . $this->get : '').
($this->anchor ? '#' . $this->anchor : ''));
diff --git a/QFW/basesub.php b/QFW/basesub.php
deleted file mode 100644
index 9bc2c90..0000000
--- a/QFW/basesub.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-
-namespace baseSub;
-
-class QFW extends \QFW
-{
- /** @var QuickFW_Router Роутер */
- static public $router;
-
- private function __construct() {}
-
- /**
- * Инициализация основных объектов QFW
- *
- */
- static public function Init()
- {
- //подключаем модули и библиотеки
- self::modules();
-
- static::$router = new \QuickFW_Router(dirname(__FILE__), __NAMESPACE__);
- }
-
- /**
- * Инициализирует необязательные модули
- * <br>в зависимости от настроек конфигов
- */
- static public function modules()
- {
- //TODO настройка автолоада
- }
-
-}
-
-class Url extends \Url
-{
- public static function Init($base)
- {
- static::$config = QFW::$config['redirection'];
- static::$config['delDef'] = QFW::$config['redirection']['delDef'];
- static::$config['baseUrl'] = static::$config['base'] = $base;
- static::$config['ext'] = (\QuickFW_Router::PATH_SEPARATOR == '/' ? '/' : '');
- }
-
- /** @var array QFW::$config['redirection'] */
- protected static $config;
-
-}
-
-?>
diff --git a/application/default/test/sub.php b/QFW/sub.php
similarity index 84%
copy from application/default/test/sub.php
copy to QFW/sub.php
index a876c8d..5aea2db 100644
--- a/application/default/test/sub.php
+++ b/QFW/sub.php
@@ -2,9 +2,7 @@
namespace test;
-require_once QFWPATH.'/basesub.php';
-
-class QFW extends \baseSub\QFW
+class QFW extends \QFW
{
/** @var QuickFW_Router Роутер */
static public $router;
@@ -23,7 +21,7 @@ class QFW extends \baseSub\QFW
}
-class Url extends \baseSub\Url {}
+class Url extends \Url { protected static $config;}
/**
* Вызывает саброутинг
@@ -39,7 +37,8 @@ function run($args, $count)
$base.= \QuickFW_Router::PATH_SEPARATOR.array_shift($args);
$uri = join(\QuickFW_Router::PATH_SEPARATOR, $args);
QFW::Init();
- Url::Init($base.\QuickFW_Router::PATH_SEPARATOR);
+ QFW::$config['redirection']['baseUrl'] = $base.\QuickFW_Router::PATH_SEPARATOR;
+ Url::Init();
$TS = new \TemplaterState(QFW::$view);
return QFW::$router->subroute($uri, \QFW::$router->type);
}
diff --git a/application/default/controllers/IndexController.php b/application/default/controllers/IndexController.php
index b6f5fff..1c93ec0 100644
--- a/application/default/controllers/IndexController.php
+++ b/application/default/controllers/IndexController.php
@@ -15,8 +15,6 @@ class IndexController extends QuickFW_Auth
return '';
QFW::$view->assign('out', $p1);
include dirname(dirname(__FILE__)).'/test/sub.php';
- $a = func_get_args();
- array_shift($a);
return test\run(func_get_args(), 1);
}
diff --git a/application/default/test/sub.php b/application/default/test/sub.php
index a876c8d..5aea2db 100644
--- a/application/default/test/sub.php
+++ b/application/default/test/sub.php
@@ -2,9 +2,7 @@
namespace test;
-require_once QFWPATH.'/basesub.php';
-
-class QFW extends \baseSub\QFW
+class QFW extends \QFW
{
/** @var QuickFW_Router Роутер */
static public $router;
@@ -23,7 +21,7 @@ class QFW extends \baseSub\QFW
}
-class Url extends \baseSub\Url {}
+class Url extends \Url { protected static $config;}
/**
* Вызывает саброутинг
@@ -39,7 +37,8 @@ function run($args, $count)
$base.= \QuickFW_Router::PATH_SEPARATOR.array_shift($args);
$uri = join(\QuickFW_Router::PATH_SEPARATOR, $args);
QFW::Init();
- Url::Init($base.\QuickFW_Router::PATH_SEPARATOR);
+ QFW::$config['redirection']['baseUrl'] = $base.\QuickFW_Router::PATH_SEPARATOR;
+ Url::Init();
$TS = new \TemplaterState(QFW::$view);
return QFW::$router->subroute($uri, \QFW::$router->type);
}
commit 0e4f07232acdf83e257a8a0127cfff4380a1292b
Author: Ivan Borzenkov <iva...@li...>
Date: Mon Jan 31 18:06:43 2011 +0300
Доработан вызов саброутинга
diff --git a/QFW/basesub.php b/QFW/basesub.php
index 06ffadb..9bc2c90 100644
--- a/QFW/basesub.php
+++ b/QFW/basesub.php
@@ -47,12 +47,4 @@ class Url extends \Url
}
-function run($base, $uri)
-{
- QFW::Init();
- Url::Init($base.'');
- $TS = new \TemplaterState(QFW::$view);
- return QFW::$router->subroute($uri, \QFW::$router->type);
-}
-
?>
diff --git a/application/default/controllers/IndexController.php b/application/default/controllers/IndexController.php
index da49da8..b6f5fff 100644
--- a/application/default/controllers/IndexController.php
+++ b/application/default/controllers/IndexController.php
@@ -17,8 +17,7 @@ class IndexController extends QuickFW_Auth
include dirname(dirname(__FILE__)).'/test/sub.php';
$a = func_get_args();
array_shift($a);
- $data = test\run(Url::A($p1), join('/',$a));
- return $data;
+ return test\run(func_get_args(), 1);
}
public function indexAction()
diff --git a/application/default/test/sub.php b/application/default/test/sub.php
index ddb7ef7..a876c8d 100644
--- a/application/default/test/sub.php
+++ b/application/default/test/sub.php
@@ -25,10 +25,21 @@ class QFW extends \baseSub\QFW
class Url extends \baseSub\Url {}
-function run($base, $uri)
+/**
+ * Вызывает саброутинг
+ *
+ * @param array $args результат func_get_args()
+ * @param integer $count сколько использовано в экшене
+ * @return string результат
+ */
+function run($args, $count)
{
+ $base = \Url::base(\Url::A('')->intern());
+ while($count--)
+ $base.= \QuickFW_Router::PATH_SEPARATOR.array_shift($args);
+ $uri = join(\QuickFW_Router::PATH_SEPARATOR, $args);
QFW::Init();
- Url::Init($base.'');
+ Url::Init($base.\QuickFW_Router::PATH_SEPARATOR);
$TS = new \TemplaterState(QFW::$view);
return QFW::$router->subroute($uri, \QFW::$router->type);
}
commit 0f487adea48a7d7b74c3efdc0b27c765520d678b
Author: Ivan Borzenkov <iva...@li...>
Date: Mon Jan 31 17:44:23 2011 +0300
Доработки саброутинга - вынесен в базовый класс
diff --git a/QFW/Init.php b/QFW/Init.php
index 7b2023d..0bad1ba 100644
--- a/QFW/Init.php
+++ b/QFW/Init.php
@@ -78,7 +78,7 @@ class QFW
self::modules();
require_once QFWPATH.'/QuickFW/Router.php';
- self::$router = new QuickFW_Router(APPPATH);
+ static::$router = new QuickFW_Router(APPPATH);
//хелпер для урлов (зависит от QuickFW_Router)
require_once QFWPATH.'/QuickFW/Url.php';
diff --git a/QFW/QuickFW/Router.php b/QFW/QuickFW/Router.php
index cba5420..6f3b46a 100644
--- a/QFW/QuickFW/Router.php
+++ b/QFW/QuickFW/Router.php
@@ -88,7 +88,14 @@ class QuickFW_Router
$this->defA = QFW::$config['default']['action'];
}
- public function r($requestUri = null, $type='Action')
+ /**
+ * Вызов Uri для исполнения в саброутинге
+ *
+ * @param string $requestUri запрашиваемый Uri
+ * @param string $type тип Uri (Action|Cli|...)
+ * @return stinrg результат
+ */
+ public function subroute($requestUri = null, $type='Action')
{
$requestUri = $this->rewrite($requestUri);
$data = explode(self::PATH_SEPARATOR, $requestUri);
@@ -122,7 +129,6 @@ class QuickFW_Router
QFW::$view->setScriptPath($this->baseDir.'/'.$MCA['Module'].'/templates');
return $result;
-
}
/**
diff --git a/QFW/basesub.php b/QFW/basesub.php
new file mode 100644
index 0000000..06ffadb
--- /dev/null
+++ b/QFW/basesub.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace baseSub;
+
+class QFW extends \QFW
+{
+ /** @var QuickFW_Router Роутер */
+ static public $router;
+
+ private function __construct() {}
+
+ /**
+ * Инициализация основных объектов QFW
+ *
+ */
+ static public function Init()
+ {
+ //подключаем модули и библиотеки
+ self::modules();
+
+ static::$router = new \QuickFW_Router(dirname(__FILE__), __NAMESPACE__);
+ }
+
+ /**
+ * Инициализирует необязательные модули
+ * <br>в зависимости от настроек конфигов
+ */
+ static public function modules()
+ {
+ //TODO настройка автолоада
+ }
+
+}
+
+class Url extends \Url
+{
+ public static function Init($base)
+ {
+ static::$config = QFW::$config['redirection'];
+ static::$config['delDef'] = QFW::$config['redirection']['delDef'];
+ static::$config['baseUrl'] = static::$config['base'] = $base;
+ static::$config['ext'] = (\QuickFW_Router::PATH_SEPARATOR == '/' ? '/' : '');
+ }
+
+ /** @var array QFW::$config['redirection'] */
+ protected static $config;
+
+}
+
+function run($base, $uri)
+{
+ QFW::Init();
+ Url::Init($base.'');
+ $TS = new \TemplaterState(QFW::$view);
+ return QFW::$router->subroute($uri, \QFW::$router->type);
+}
+
+?>
diff --git a/application/default/controllers/IndexController.php b/application/default/controllers/IndexController.php
index 6538206..da49da8 100644
--- a/application/default/controllers/IndexController.php
+++ b/application/default/controllers/IndexController.php
@@ -13,12 +13,11 @@ class IndexController extends QuickFW_Auth
{
if (!$p1)
return '';
+ QFW::$view->assign('out', $p1);
include dirname(dirname(__FILE__)).'/test/sub.php';
$a = func_get_args();
array_shift($a);
- echo "<br><br>".Url::A($p1)."<br><br>";
- $data = 'a'.test\run::run(Url::A($p1), join('/',$a)).'a';
- echo "<br><br>".Url::A($p1)."<br><br>";
+ $data = test\run(Url::A($p1), join('/',$a));
return $data;
}
diff --git a/application/default/test/default/controllers/IndexController.php b/application/default/test/default/controllers/IndexController.php
index 3b3a081..a6c27d0 100644
--- a/application/default/test/default/controllers/IndexController.php
+++ b/application/default/test/default/controllers/IndexController.php
@@ -11,6 +11,7 @@ class IndexController extends \QuickFW_Auth
public function indexAction()
{
+ QFW::$view->assign('in', 'in');
return QFW::$view->fetch('index.php');
}
diff --git a/application/default/test/default/templates/index.php b/application/default/test/default/templates/index.php
index 2cc11c0..5c26a0b 100644
--- a/application/default/test/default/templates/index.php
+++ b/application/default/test/default/templates/index.php
@@ -2,3 +2,4 @@
<?php echo Url::A('a'); ?><br>
<?php echo test\Url::A('a'); ?><br>
<?php echo test\Url::C('a'); ?><br>
+<?php echo $out.' '.$in ?>
diff --git a/application/default/test/sub.php b/application/default/test/sub.php
index bb12007..ddb7ef7 100644
--- a/application/default/test/sub.php
+++ b/application/default/test/sub.php
@@ -2,110 +2,35 @@
namespace test;
-class QFW
-{
- /** @var array Глобальный массив данных */
- static public $globalData = array();
+require_once QFWPATH.'/basesub.php';
+class QFW extends \baseSub\QFW
+{
/** @var QuickFW_Router Роутер */
static public $router;
- /** @var array Конфигурация */
- static public $config;
-
- /** @var Templater_PlainView Шаблонизатор */
- static public $view;
-
- /** @var array Подключенные глобальные библиотеки */
- static public $libs = array();
-
- /** @var DbSimple_Database|false Подключение к базе данных */
- static public $db = false;
-
- /** @var mixed|false Данные о пользователе */
- static public $userdata = false;
-
- /** @var JsHttpRequest|jQuery|false JsHttpRequest или jQuery, если был выполнени Ajax запрос */
- static public $ajax = false;
-
- private function __construct() {}
-
- /**
- * Инициализация конфига
- *
- * <br>возвращает конфигурацию, специфичную для текущего хоста
- *
- * @return array конфигурация на этом хосте
- */
- static public function config()
- {
- require QFWPATH.'/config.php';
- require APPPATH.'/default.php';
-
- if (!isset($_SERVER['HTTP_HOST']))
- die('$_SERVER[\'HTTP_HOST\'] NOT SET');
- $file = APPPATH.'/'.$_SERVER['HTTP_HOST'].'.php';
- if (is_file($file))
- require ($file);
- return $config;
- }
-
/**
* Инициализация основных объектов QFW
*
*/
static public function Init()
{
- self::$config = \QFW::$config;
-
- self::$db = \QFW::$db;
-
- self::$view = \QFW::$view;
-
//подключаем модули и библиотеки
self::modules();
- require_once QFWPATH.'/QuickFW/Router.php';
- self::$router = new \QuickFW_Router(dirname(__FILE__), __NAMESPACE__);
- }
-
- /**
- * Инициализирует необязательные модули
- * <br>в зависимости от настроек конфигов
- */
- static public function modules()
- {
- //TODO настройка автолоада
+ static::$router = new \QuickFW_Router(dirname(__FILE__), __NAMESPACE__);
}
}
-class Url extends \Url
-{
- public static function Init($base)
- {
- static::$config = QFW::$config['redirection'];
- static::$config['delDef'] = QFW::$config['redirection']['delDef'];
- static::$config['baseUrl'] = static::$config['base'] = $base;
- static::$config['ext'] = (\QuickFW_Router::PATH_SEPARATOR == '/' ? '/' : '');
- }
-
- /** @var array QFW::$config['redirection'] */
- protected static $config;
-
-}
+class Url extends \baseSub\Url {}
-class run
+function run($base, $uri)
{
- static public function run($base, $uri)
- {
- Url::Init($base.'');
- $TS = new \TemplaterState(QFW::$view);
- $data = QFW::$router->r($uri);
- return $data;
- }
+ QFW::Init();
+ Url::Init($base.'');
+ $TS = new \TemplaterState(QFW::$view);
+ return QFW::$router->subroute($uri, \QFW::$router->type);
}
-QFW::Init();
-
?>
commit 22050b0340cc4b514164dc12ae9b0bbbc5b3967a
Author: Ivan Borzenkov <iva...@li...>
Date: Mon Jan 31 17:05:10 2011 +0300
Пока LSB из php5.3
diff --git a/QFW/QuickFW/Url.php b/QFW/QuickFW/Url.php
index a346f19..a1fa0fd 100644
--- a/QFW/QuickFW/Url.php
+++ b/QFW/QuickFW/Url.php
@@ -15,7 +15,7 @@ class Url
*/
public static function base($url='')
{
- return new self('').$url;
+ return new static('').$url;
}
/**
@@ -28,7 +28,7 @@ class Url
*/
public static function site($url='', $get='', $anchor='')
{
- return new self($url, $get, $anchor);
+ return new static($url, $get, $anchor);
}
/**
@@ -41,7 +41,7 @@ class Url
*/
public static function M($CA='', $get='', $anchor='')
{
- return new self($CA, $get, $anchor, QFW::$router->cModule.
+ return new static($CA, $get, $anchor, QFW::$router->cModule.
QuickFW_Router::PATH_SEPARATOR);
}
@@ -55,7 +55,7 @@ class Url
*/
public static function C($action='', $get='', $anchor='')
{
- return new self($action, $get, $anchor, QFW::$router->cModule.
+ return new static($action, $get, $anchor, QFW::$router->cModule.
QuickFW_Router::PATH_SEPARATOR.
QFW::$router->cController.
QuickFW_Router::PATH_SEPARATOR);
@@ -71,7 +71,7 @@ class Url
*/
public static function A($params='', $get='', $anchor='')
{
- return new self($params, $get, $anchor, QFW::$router->cModule.
+ return new static($params, $get, $anchor, QFW::$router->cModule.
QuickFW_Router::PATH_SEPARATOR.
QFW::$router->cController.
QuickFW_Router::PATH_SEPARATOR.
@@ -83,15 +83,15 @@ class Url
*/
public static function Init()
{
- self::$config = QFW::$config['redirection'];
- self::$config['base'] = self::$config['baseUrl'].
- (self::$config['useIndex'] ? 'index.php/' : '');
- self::$config['ext'] = self::$config['defExt'] ? self::$config['defExt'] :
+ static::$config = QFW::$config['redirection'];
+ static::$config['base'] = static::$config['baseUrl'].
+ (static::$config['useIndex'] ? 'index.php/' : '');
+ static::$config['ext'] = static::$config['defExt'] ? static::$config['defExt'] :
(QuickFW_Router::PATH_SEPARATOR == '/' ? '/' : '');
}
/** @var array QFW::$config['redirection'] */
- private static $config;
+ protected static $config;
/**
* Конструктор класса запроса
@@ -101,7 +101,7 @@ class Url
* @param string $anchor якорь
* @param string $begin базовый урл от текущего
*/
- private function __construct($url, $get='', $anchor='', $begin='')
+ protected function __construct($url, $get='', $anchor='', $begin='')
{
if (is_array($get) && count($get))
$get = http_build_query($get);
@@ -118,7 +118,7 @@ class Url
$this->u = trim($begin.$url, QuickFW_Router::PATH_SEPARATOR);
$this->get = $get;
$this->anchor = ltrim($anchor, '#');
- if (self::$config['delDef'])
+ if (static::$config['delDef'])
$this->u = QFW::$router->delDef($this->u);
}
@@ -149,8 +149,8 @@ class Url
public function get()
{
return QFW::$router->backrewriteUrl(
- self::$config['base'].QFW::$router->backrewrite($this->u).
- ($this->u!=='' ? self::$config['ext'] : '').
+ static::$config['base'].QFW::$router->backrewrite($this->u).
+ ($this->u!=='' ? static::$config['ext'] : '').
($this->get ? '?' . $this->get : '').
($this->anchor ? '#' . $this->anchor : ''));
}
diff --git a/application/default/controllers/IndexController.php b/application/default/controllers/IndexController.php
index 0fe5236..6538206 100644
--- a/application/default/controllers/IndexController.php
+++ b/application/default/controllers/IndexController.php
@@ -16,7 +16,10 @@ class IndexController extends QuickFW_Auth
include dirname(dirname(__FILE__)).'/test/sub.php';
$a = func_get_args();
array_shift($a);
- return 'a'.test\run::run(join('/',$a)).'a';
+ echo "<br><br>".Url::A($p1)."<br><br>";
+ $data = 'a'.test\run::run(Url::A($p1), join('/',$a)).'a';
+ echo "<br><br>".Url::A($p1)."<br><br>";
+ return $data;
}
public function indexAction()
diff --git a/application/default/test/default/controllers/IndexController.php b/application/default/test/default/controllers/IndexController.php
index 9864438..3b3a081 100644
--- a/application/default/test/default/controllers/IndexController.php
+++ b/application/default/test/default/controllers/IndexController.php
@@ -11,7 +11,7 @@ class IndexController extends \QuickFW_Auth
public function indexAction()
{
- return 'zzz';
+ return QFW::$view->fetch('index.php');
}
}
diff --git a/application/default/test/default/templates/index.php b/application/default/test/default/templates/index.php
index 9ab50b9..2cc11c0 100644
--- a/application/default/test/default/templates/index.php
+++ b/application/default/test/default/templates/index.php
@@ -1,10 +1,4 @@
-<h2>Добро пожаловать</h2>
-
-<ul>
- <li><a href="<?php echo Url::M('doc') ?>">Документация</a>
- <p><small>Для генерации нужен установленный a2x, xetex и вообще только unix - с виндой трахайтесь как хотите</small></p>
- </li>
- <li><a href="<?php echo Url::C('dinmenu') ?>">Динамическое меню</a>
- <p><small>Пример вложенного динамического меню с помощью хелпера на CSS3</small></p>
- </li>
-</ul>
+Проверка работы саброутинга<br>
+<?php echo Url::A('a'); ?><br>
+<?php echo test\Url::A('a'); ?><br>
+<?php echo test\Url::C('a'); ?><br>
diff --git a/application/default/test/default/templates/main.php b/application/default/test/default/templates/main.php
deleted file mode 100644
index 1e4fc8e..0000000
--- a/application/default/test/default/templates/main.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="utf-8">
- <title><?php echo isset($title)?'QFW::'.$title:'QFW' ?></title>
-</head>
-<body>
-<h1>QFW - <small>оно таки у вас завелось</small></h1>
-<?php echo $content; ?>
-</body>
-</html>
diff --git a/application/default/test/sub.php b/application/default/test/sub.php
index b7f6b66..bb12007 100644
--- a/application/default/test/sub.php
+++ b/application/default/test/sub.php
@@ -60,19 +60,13 @@ class QFW
self::$db = \QFW::$db;
- //Подключаем шаблонизатор
- $templ = ucfirst(self::$config['templater']['name']);
- $class = '\Templater_'.$templ;
- require_once QFWPATH.'/Templater/'.$templ.'.php';
- self::$view = new $class(dirname(__FILE__), '');
+ self::$view = \QFW::$view;
//подключаем модули и библиотеки
self::modules();
require_once QFWPATH.'/QuickFW/Router.php';
self::$router = new \QuickFW_Router(dirname(__FILE__), __NAMESPACE__);
-
- Url::Init();
}
/**
@@ -88,14 +82,27 @@ class QFW
class Url extends \Url
{
+ public static function Init($base)
+ {
+ static::$config = QFW::$config['redirection'];
+ static::$config['delDef'] = QFW::$config['redirection']['delDef'];
+ static::$config['baseUrl'] = static::$config['base'] = $base;
+ static::$config['ext'] = (\QuickFW_Router::PATH_SEPARATOR == '/' ? '/' : '');
+ }
+
+ /** @var array QFW::$config['redirection'] */
+ protected static $config;
}
class run
{
- static public function run($uri)
+ static public function run($base, $uri)
{
- return QFW::$router->r($uri);
+ Url::Init($base.'');
+ $TS = new \TemplaterState(QFW::$view);
+ $data = QFW::$router->r($uri);
+ return $data;
}
}
commit b218d313da1a51454d63cae0d48ed6b2c8961cb5
Author: Ivan Borzenkov <iva...@li...>
Date: Mon Jan 31 15:26:04 2011 +0300
Пока очень тестовый саброутинг
diff --git a/QFW/QuickFW/Router.php b/QFW/QuickFW/Router.php
index 4ad2f98..cba5420 100644
--- a/QFW/QuickFW/Router.php
+++ b/QFW/QuickFW/Router.php
@@ -24,6 +24,9 @@ class QuickFW_Router
protected $classes=array();
protected $baseDir;
+
+ /** @var string Неймспейс для подроутинга */
+ protected $sub;
protected $defM,$defC,$defA;
@@ -73,17 +76,55 @@ class QuickFW_Router
/** @var string Uri который был вызван для исполнения после фильтрации переменных и реврайта */
public $RequestUri;
- public function __construct($baseDir)
+ public function __construct($baseDir, $sub='')
{
$this->baseDir = rtrim($baseDir, '/\\');
$this->module = '';
$this->controller = '';
$this->action = '';
+ $this->sub = $sub?($sub.'\\'):'';
$this->defM = QFW::$config['default']['module'];
$this->defC = QFW::$config['default']['controller'];
$this->defA = QFW::$config['default']['action'];
}
+ public function r($requestUri = null, $type='Action')
+ {
+ $requestUri = $this->rewrite($requestUri);
+ $data = explode(self::PATH_SEPARATOR, $requestUri);
+ //обнуляем если нас вызвали повторно
+ $this->module = '';
+ $this->controller = '';
+ $this->action = '';
+
+ $MCA = $this->loadMCA($data, $type);
+ if (isset($MCA['Error']))
+ {
+ if (QFW::$config['QFW']['release'])
+ $this->show404();
+ else
+ die("Был выполнен запрос \t\t".$requestUri."\nадрес был разобран в\t\t ".
+ $MCA['Path']."\n".
+ $MCA['Error']);
+ }
+ $params = $this->parseParams($data);
+
+ $this->curModule = $this->cModule = $this->module = $MCA['Module'];
+ $this->curController = $this->cController = $this->controller = $MCA['Controller'];
+ $this->cAction = $this->action = $MCA['Action'];
+ $this->CurPath = $this->UriPath = $MCA['Path'];
+ $this->Uri = $MCA['Path'] . self::PATH_SEPARATOR . join(self::PATH_SEPARATOR, $data);
+ $this->RequestUri = $requestUri;
+ $this->ParentPath = null;
+
+ $result = call_user_func_array(array($MCA['Class'], $MCA['Action'].$MCA['Type']), $params);
+
+ QFW::$view->setScriptPath($this->baseDir.'/'.$MCA['Module'].'/templates');
+
+ return $result;
+
+ }
+
/**
* Вызов Uri для исполнения
*
@@ -424,7 +465,7 @@ SREG;
if (!empty(QFW::$config['cache']['MCA']))
{
$Cache = Cache::get('MCA');
- $key = 'MCA_'.crc32(serialize($data)).$type.
+ $key = 'MCA_'.$this->sub.crc32(serialize($data)).$type.
($type=='Block' ? $this->curModule : $this->defM);
$cached = $Cache->load($key);
if ($cached)
@@ -498,18 +539,19 @@ SREG;
if (!isset($this->classes[$class_key]))
{
require_once($fullname);
- if (!class_exists($class))
+ if (!class_exists($this->sub.$class))
{
//Смотрим, а не в неймспейсе ли он случайно
- if (class_exists($MCA['Module'].'\\'.$class))
- $class = $MCA['Module'].'\\'.$class;
+ if (class_exists($MCA['Module'].'\\'.$this->sub.$class))
+ $class = $MCA['Module'].'\\'.$this->sub.$class;
else
{
- $MCA['Error']="не найден класс \t\t\t".$class."\nКласс не найден, мать его за ногу";
+ $MCA['Error']="не найден класс \t\t\t".$this->sub.$class."\nКласс не найден, мать его за ногу";
$MCA['Path']=$MCA['Module'].'/'.$MCA['Controller'].'/...';
return $MCA;
}
}
+ $class = $this->sub.$class;
$vars = get_class_vars($class);
$acts = get_class_methods($class);
diff --git a/application/default/controllers/IndexController.php b/application/default/controllers/IndexController.php
index fb994fa..0fe5236 100644
--- a/application/default/controllers/IndexController.php
+++ b/application/default/controllers/IndexController.php
@@ -9,6 +9,16 @@ class IndexController extends QuickFW_Auth
//echo QFW::$router->module.'.'.QFW::$router->controller.'.'.QFW::$router->action."<br>\n";
}
+ public function tttAction($p1='')
+ {
+ if (!$p1)
+ return '';
+ include dirname(dirname(__FILE__)).'/test/sub.php';
+ $a = func_get_args();
+ array_shift($a);
+ return 'a'.test\run::run(join('/',$a)).'a';
+ }
+
public function indexAction()
{
QFW::$view->assign('title', 'Основная страница');
diff --git a/application/default/test/default/controllers/IndexController.php b/application/default/test/default/controllers/IndexController.php
new file mode 100644
index 0000000..9864438
--- /dev/null
+++ b/application/default/test/default/controllers/IndexController.php
@@ -0,0 +1,19 @@
+<?php
+namespace test;
+
+require_once(QFWPATH.'/QuickFW/Auth.php');
+
+class IndexController extends \QuickFW_Auth
+{
+ public function __construct()
+ {
+ }
+
+ public function indexAction()
+ {
+ return 'zzz';
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/application/default/test/default/templates/index.php b/application/default/test/default/templates/index.php
new file mode 100644
index 0000000..9ab50b9
--- /dev/null
+++ b/application/default/test/default/templates/index.php
@@ -0,0 +1,10 @@
+<h2>Добро пожаловать</h2>
+
+<ul>
+ <li><a href="<?php echo Url::M('doc') ?>">Документация</a>
+ <p><small>Для генерации нужен установленный a2x, xetex и вообще только unix - с виндой трахайтесь как хотите</small></p>
+ </li>
+ <li><a href="<?php echo Url::C('dinmenu') ?>">Динамическое меню</a>
+ <p><small>Пример вложенного динамического меню с помощью хелпера на CSS3</small></p>
+ </li>
+</ul>
diff --git a/application/default/test/default/templates/main.php b/application/default/test/default/templates/main.php
new file mode 100644
index 0000000..1e4fc8e
--- /dev/null
+++ b/application/default/test/default/templates/main.php
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title><?php echo isset($title)?'QFW::'.$title:'QFW' ?></title>
+</head>
+<body>
+<h1>QFW - <small>оно таки у вас завелось</small></h1>
+<?php echo $content; ?>
+</body>
+</html>
diff --git a/application/default/test/sub.php b/application/default/test/sub.php
new file mode 100644
index 0000000..b7f6b66
--- /dev/null
+++ b/application/default/test/sub.php
@@ -0,0 +1,104 @@
+<?php
+
+namespace test;
+
+class QFW
+{
+ /** @var array Глобальный массив данных */
+ static public $globalData = array();
+
+ /** @var QuickFW_Router Роутер */
+ static public $router;
+
+ /** @var array Конфигурация */
+ static public $config;
+
+ /** @var Templater_PlainView Шаблонизатор */
+ static public $view;
+
+ /** @var array Подключенные глобальные библиотеки */
+ static public $libs = array();
+
+ /** @var DbSimple_Database|false Подключение к базе данных */
+ static public $db = false;
+
+ /** @var mixed|false Данные о пользователе */
+ static public $userdata = false;
+
+ /** @var JsHttpRequest|jQuery|false JsHttpRequest или jQuery, если был выполнени Ajax запрос */
+ static public $ajax = false;
+
+ private function __construct() {}
+
+ /**
+ * Инициализация конфига
+ *
+ * <br>возвращает конфигурацию, специфичную для текущего хоста
+ *
+ * @return array конфигурация на этом хосте
+ */
+ static public function config()
+ {
+ require QFWPATH.'/config.php';
+ require APPPATH.'/default.php';
+
+ if (!isset($_SERVER['HTTP_HOST']))
+ die('$_SERVER[\'HTTP_HOST\'] NOT SET');
+ $file = APPPATH.'/'.$_SERVER['HTTP_HOST'].'.php';
+ if (is_file($file))
+ require ($file);
+ return $config;
+ }
+
+ /**
+ * Инициализация основных объектов QFW
+ *
+ */
+ static public function Init()
+ {
+ self::$config = \QFW::$config;
+
+ self::$db = \QFW::$db;
+
+ //Подключаем шаблонизатор
+ $templ = ucfirst(self::$config['templater']['name']);
+ $class = '\Templater_'.$templ;
+ require_once QFWPATH.'/Templater/'.$templ.'.php';
+ self::$view = new $class(dirname(__FILE__), '');
+
+ //подключаем модули и библиотеки
+ self::modules();
+
+ require_once QFWPATH.'/QuickFW/Router.php';
+ self::$router = new \QuickFW_Router(dirname(__FILE__), __NAMESPACE__);
+
+ Url::Init();
+ }
+
+ /**
+ * Инициализирует необязательные модули
+ * <br>в зависимости от настроек конфигов
+ */
+ static public function modules()
+ {
+ //TODO настройка автолоада
+ }
+
+}
+
+class Url extends \Url
+{
+
+}
+
+class run
+{
+ static public function run($uri)
+ {
+ return QFW::$router->r($uri);
+ }
+}
+
+QFW::Init();
+
+?>
-----------------------------------------------------------------------
hooks/post-receive
--
quickfw
|