[limb-svn] r6349 - in 3.x/trunk/limb/view: src src/toolkit tests/cases
svn at limb-project.com
svn at limb-project.com
Mon Oct 1 17:28:12 MSD 2007
Author: pachanga
Date: 2007-10-01 17:28:12 +0400 (Mon, 01 Oct 2007)
New Revision: 6349
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6349
Added:
3.x/trunk/limb/view/src/lmbDummyView.class.php
3.x/trunk/limb/view/tests/cases/lmbMacroViewTest.class.php
Modified:
3.x/trunk/limb/view/src/lmbBlitzView.class.php
3.x/trunk/limb/view/src/lmbMacroView.class.php
3.x/trunk/limb/view/src/lmbView.class.php
3.x/trunk/limb/view/src/lmbWactView.class.php
3.x/trunk/limb/view/src/toolkit/lmbViewTools.class.php
Log:
-- lmbViewTools now has basic support for finding concrete view implementation for the specific template type
-- base lmbView now "knows" about forms
-- lmbView :: copy($view) added, it simply copies internal attributes from $view
-- lmbDummyView added, it's a default view used in lmbWebAppTools :: getView() instead of lmbWactView
-- other minor improvements
Modified: 3.x/trunk/limb/view/src/lmbBlitzView.class.php
===================================================================
--- 3.x/trunk/limb/view/src/lmbBlitzView.class.php 2007-10-01 13:18:32 UTC (rev 6348)
+++ 3.x/trunk/limb/view/src/lmbBlitzView.class.php 2007-10-01 13:28:12 UTC (rev 6349)
@@ -1,47 +1,65 @@
<?php
-
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
lmb_require('limb/view/src/lmbView.class.php');
+/**
+ * class lmbBlitzView.
+ *
+ * @package view
+ * @version $Id$
+ */
class lmbBlitzView extends lmbView
{
- private $templateInstance;
+ private $templateInstance;
- function __call($methodName, $params)
+ static function locateTemplateByAlias($alias)
+ {
+ return null;
+ }
+
+ function __call($methodName, $params)
+ {
+ $tpl = $this->getTemplateInstance();
+ if(!method_exists($tpl, $methodName))
{
- $tpl = $this->getTemplateInstance();
- if(!method_exists($tpl, $methodName))
- {
- throw new lmbException(
- 'Wrong template method called',
- array(
- 'template class' => get_class($tpl),
- 'method' => $methodName,
- )
- );
- }
- return call_user_method_array($methodName, $tpl, $params);
+ throw new lmbException(
+ 'Wrong template method called',
+ array(
+ 'template class' => get_class($tpl),
+ 'method' => $methodName,
+ )
+ );
}
+ return call_user_method_array($methodName, $tpl, $params);
+ }
- function getTemplateInstance()
+ function getTemplateInstance()
+ {
+ if(!$this->templateInstance)
{
- if(!$this->templateInstance)
- {
- if(!$this->hasTemplate())
- {
- throw new lmbException('template not defined');
- }
- $this->templateInstance = new Blitz($this->getTemplate());
- }
- return $this->templateInstance;
+ if(!$this->hasTemplate())
+ throw new lmbException('template not defined');
+
+ if(!class_exists('Blitz'))
+ throw new lmbException("Blitz extension is not loaded");
+
+ $this->templateInstance = new Blitz($this->getTemplate());
}
-
- function render()
- {
- foreach ($this->getVariables() as $name => $value)
- {
- $this->getTemplateInstance()->set(array($name => $value));
- }
- return $this->getTemplateInstance()->parse();
- }
+ return $this->templateInstance;
+ }
-}
\ No newline at end of file
+ function render()
+ {
+ foreach ($this->getVariables() as $name => $value)
+ $this->getTemplateInstance()->set(array($name => $value));
+
+ return $this->getTemplateInstance()->parse();
+ }
+
+}
Added: 3.x/trunk/limb/view/src/lmbDummyView.class.php
===================================================================
--- 3.x/trunk/limb/view/src/lmbDummyView.class.php (rev 0)
+++ 3.x/trunk/limb/view/src/lmbDummyView.class.php 2007-10-01 13:28:12 UTC (rev 6349)
@@ -0,0 +1,29 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/view/src/lmbView.class.php');
+
+/**
+ * class lmbDummyView.
+ *
+ * @package view
+ * @version $Id$
+ */
+class lmbDummyView extends lmbView
+{
+ static function locateTemplateByAlias($alias)
+ {
+ return $alias;
+ }
+
+ function render()
+ {
+ echo 111;
+ }
+}
+
Modified: 3.x/trunk/limb/view/src/lmbMacroView.class.php
===================================================================
--- 3.x/trunk/limb/view/src/lmbMacroView.class.php 2007-10-01 13:18:32 UTC (rev 6348)
+++ 3.x/trunk/limb/view/src/lmbMacroView.class.php 2007-10-01 13:28:12 UTC (rev 6349)
@@ -6,12 +6,9 @@
* @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
* @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
-lmb_require('limb/view/src/macro/lmbMacroTemplate.class.php');
+lmb_require('limb/macro/src/lmbMacroTemplate.class.php');
lmb_require('limb/view/src/lmbView.class.php');
- at define('LIMB_TEMPLATES_INCLUDE_PATH', 'template;limb/*/template');
- at define('LIMB_MACRO_TAGS_INCLUDE_PATH', 'src/macro;limb/*/src/macro;limb/macro/src/tags');
-
/**
* class lmbMacroView.
*
@@ -21,11 +18,10 @@
class lmbMacroView extends lmbView
{
protected $macro_template;
- protected $cache_dir;
- function setCacheDir($dir)
+ static function locateTemplateByAlias($alias)
{
- $this->cache_dir = $dir;
+ return lmbMacroTemplate :: locateTemplateByAlias($alias, lmbToolkit :: instance()->getMacroConfig());
}
function render()
@@ -56,19 +52,10 @@
if(!$path = $this->getTemplate())
return null;
- $this->macro_template = new lmbMacroTemplate($path, $this->_getMacroConfig());
+ $this->macro_template = new lmbMacroTemplate($path, lmbToolkit :: instance()->getMacroConfig());
return $this->macro_template;
}
- protected function _getMacroConfig()
- {
- return new lmbMacroConfig($this->cache_dir,
- true,
- true,
- explode(';', LIMB_TEMPLATES_INCLUDE_PATH),
- explode(';', LIMB_MACRO_TAGS_INCLUDE_PATH));
- }
-
protected function _fillMacroTemplate($template)
{
foreach($this->getVariables() as $variable_name => $value)
Modified: 3.x/trunk/limb/view/src/lmbView.class.php
===================================================================
--- 3.x/trunk/limb/view/src/lmbView.class.php 2007-10-01 13:18:32 UTC (rev 6348)
+++ 3.x/trunk/limb/view/src/lmbView.class.php 2007-10-01 13:28:12 UTC (rev 6349)
@@ -17,6 +17,8 @@
{
protected $template_name;
protected $variables = array();
+ protected $forms_datasources = array();
+ protected $forms_errors = array();
function __construct($template_name = '')
{
@@ -37,9 +39,18 @@
function reset()
{
+ $this->forms_datasources = array();
+ $this->forms_errors = array();
$this->variables = array();
}
+ function copy($view)
+ {
+ $this->variables = $view->variables;
+ $this->forms_errors = $view->forms_errors;
+ $this->forms_datasources = $view->forms_datasources;
+ }
+
function getTemplate()
{
return $this->template_name;
@@ -65,5 +76,29 @@
{
return $this->variables;
}
+
+ function setFormDatasource($form_name, $datasource)
+ {
+ $this->forms_datasources[$form_name] = $datasource;
+ }
+
+ function getFormDatasource($form_name)
+ {
+ if(isset($this->forms_datasources[$form_name]))
+ return $this->forms_datasources[$form_name];
+ else
+ return null;
+ }
+
+ function setFormErrors($form_name, $error_list)
+ {
+ $this->forms_errors[$form_name] = $error_list;
+ }
+
+ function getForms()
+ {
+ return $this->forms_datasources;
+ }
+
}
Modified: 3.x/trunk/limb/view/src/lmbWactView.class.php
===================================================================
--- 3.x/trunk/limb/view/src/lmbWactView.class.php 2007-10-01 13:18:32 UTC (rev 6348)
+++ 3.x/trunk/limb/view/src/lmbWactView.class.php 2007-10-01 13:28:12 UTC (rev 6349)
@@ -18,10 +18,22 @@
class lmbWactView extends lmbView
{
protected $wact_template;
- protected $forms_datasources = array();
- protected $forms_errors = array();
protected $cache_dir;
+ function __construct($template_name = '')
+ {
+ parent :: __construct($template_name);
+ $this->cache_dir = LIMB_VAR_DIR . '/compiled/';
+ }
+
+ static function locateTemplateByAlias($alias)
+ {
+ $locator = lmbToolkit :: instance()->getWactLocator();
+
+ if($template_path = $locator->locateSourceTemplate($alias))
+ return $template_path;
+ }
+
function setCacheDir($dir)
{
$this->cache_dir = $dir;
@@ -39,8 +51,6 @@
function reset()
{
parent :: reset();
- $this->forms_datasources = array();
- $this->forms_errors = array();
$this->wact_template = null;
}
@@ -49,29 +59,6 @@
return $this->_getWactTemplate();
}
- function setFormDatasource($form_name, $datasource)
- {
- $this->forms_datasources[$form_name] = $datasource;
- }
-
- function getFormDatasource($form_name)
- {
- if(isset($this->forms_datasources[$form_name]))
- return $this->forms_datasources[$form_name];
- else
- return null;
- }
-
- function setFormErrors($form_name, $error_list)
- {
- $this->forms_errors[$form_name] = $error_list;
- }
-
- function getForms()
- {
- return $this->forms_datasources;
- }
-
function findChild($id)
{
if($tpl = $this->_getWactTemplate())
Modified: 3.x/trunk/limb/view/src/toolkit/lmbViewTools.class.php
===================================================================
--- 3.x/trunk/limb/view/src/toolkit/lmbViewTools.class.php 2007-10-01 13:18:32 UTC (rev 6348)
+++ 3.x/trunk/limb/view/src/toolkit/lmbViewTools.class.php 2007-10-01 13:28:12 UTC (rev 6349)
@@ -10,6 +10,7 @@
@define('LIMB_TEMPLATES_INCLUDE_PATH', 'template;limb/*/template');
@define('LIMB_WACT_TAGS_INCLUDE_PATH', 'src/template/tags;limb/*/src/template/tags;limb/wact/src/tags');
+ at define('LIMB_MACRO_TAGS_INCLUDE_PATH', 'src/macro;limb/*/src/macro;limb/macro/src/tags');
/**
* class lmbViewTools.
@@ -19,8 +20,55 @@
*/
class lmbViewTools extends lmbAbstractTools
{
+ protected $view_types = array('.html' => 'lmbWactView',
+ '.phtml' => 'lmbMacroView');
protected $wact_locator;
+ protected $macro_config;
+ function setSupportedViewTypes($types)
+ {
+ $this->view_types = $types;
+ }
+
+ function getSupportedViewTypes()
+ {
+ return $this->view_types;
+ }
+
+ function getSupportedViewExtensions()
+ {
+ return array_keys($this->view_types);
+ }
+
+ function locateTemplateByAlias($alias)
+ {
+ $class = $this->_findViewClassByTemplate($alias);
+ lmb_require("limb/view/src/$class.class.php");
+ return call_user_func(array($class, 'locateTemplateByAlias'), $alias);
+ }
+
+ function createViewByTemplate($template_name)
+ {
+ $class = $this->_findViewClassByTemplate($template_name);
+ lmb_require("limb/view/src/$class.class.php");
+ $view = new $class($template_name);
+ return $view;
+ }
+
+ protected function _findViewClassByTemplate($template_name)
+ {
+ $pos = strrpos($template_name, '.');
+ if($pos === false)
+ throw new lmbException("Could not determine template type for file '$template_name'");
+
+ $ext = substr($template_name, $pos);
+
+ if(!isset($this->view_types[$ext]))
+ throw new lmbException("Template extension '$ext' is not supported");
+
+ return $this->view_types[$ext];
+ }
+
function getWactLocator()
{
if(is_object($this->wact_locator))
@@ -38,5 +86,26 @@
{
$this->wact_locator = $wact_locator;
}
+
+ function getMacroConfig()
+ {
+ if(is_object($this->macro_config))
+ return $this->macro_config;
+
+ lmb_require('limb/macro/src/lmbMacroConfig.class.php');
+
+ $this->macro_config = new lmbMacroConfig(LIMB_VAR_DIR . '/compiled/',
+ true,
+ true,
+ explode(';', LIMB_MACRO_TAGS_INCLUDE_PATH),
+ explode(';', LIMB_TEMPLATES_INCLUDE_PATH));
+
+ return $this->macro_config;
+ }
+
+ function setMacroConfig($config)
+ {
+ $this->macro_config = $config;
+ }
}
Added: 3.x/trunk/limb/view/tests/cases/lmbMacroViewTest.class.php
===================================================================
--- 3.x/trunk/limb/view/tests/cases/lmbMacroViewTest.class.php (rev 0)
+++ 3.x/trunk/limb/view/tests/cases/lmbMacroViewTest.class.php 2007-10-01 13:28:12 UTC (rev 6349)
@@ -0,0 +1,47 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/view/src/lmbMacroView.class.php');
+lmb_require('limb/fs/src/lmbFs.class.php');
+
+class lmbMacroViewTest extends UnitTestCase
+{
+ function setUp()
+ {
+ lmbFs :: rm(LIMB_VAR_DIR . '/tpl/');
+ lmbFs :: mkdir(LIMB_VAR_DIR . '/tpl/');
+ }
+
+ function testRenderSimpleVars()
+ {
+ $tpl = $this->_createTemplate('{{$#hello}}{{$#again}}', 'test.phtml');
+ $view = $this->_createView($tpl);
+
+ $view->set('hello', 'Hello message!');
+ $view->set('again', 'Hello again!');
+
+ $view->render();
+
+ $this->assertEqual($view->render(), 'Hello message!Hello again!');
+ }
+
+ protected function _createView($file)
+ {
+ $view = new lmbMacroView($file);
+ return $view;
+ }
+
+ protected function _createTemplate($code, $name)
+ {
+ $file = LIMB_VAR_DIR . '/tpl/' . $name;
+ file_put_contents($file, $code);
+ return $file;
+ }
+}
+
+
More information about the limb-svn
mailing list