Commit 69f61f83 by seldaek

* Added $this->viewParam support to ZendFramework adapter through a…

* Added $this->viewParam support to ZendFramework adapter through a Dwoo_Adapters_ZendFramework_Dwoo class that extends Dwoo, you should use this if you called setEngine() on the ZF view * Fixed some whitespace issues git-svn-id: http://svn.dwoo.org/trunk@341 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent aa5c9622
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
+ Improved parsing of array() to support real php array syntax as well + Improved parsing of array() to support real php array syntax as well
as variables as array keys, thanks to acecream for the help as variables as array keys, thanks to acecream for the help
+ Improved parsing of named parameters that can now be quoted + Improved parsing of named parameters that can now be quoted
* Added $this->viewParam support to ZendFramework adapter through a
Dwoo_Adapters_ZendFramework_Dwoo class that extends Dwoo, you should use
this if you called setEngine() on the ZF view
* Fixed parsing of quoted keywords in if statements, like 'not' was * Fixed parsing of quoted keywords in if statements, like 'not' was
parsed as ! because using {if not $foo} is valid, but it was impossible parsed as ! because using {if not $foo} is valid, but it was impossible
to use them even as string. to use them even as string.
......
<?php
/**
* Dwoo base class for ZendFramework
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the
* use of this software.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Marc Hodgins <mjh@hodginsmedia.com>
* @copyright Copyright (c) 2010, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.2.0
* @date 2010-02-28
* @package Dwoo
*/
class Dwoo_Adapters_ZendFramework_Dwoo extends Dwoo
{
/**
* Redirects all unknown properties to plugin proxy
* to support $this->viewVariable from within templates
*
* @param string $name Property name
* @return mixed
*/
public function __get($name)
{
if (isset($this->getPluginProxy()->view->$name)) {
return $this->getPluginProxy()->view->$name;
}
$trace = debug_backtrace();
trigger_error('Undefined property via __get(): ' . $name .
' in ' . $trace[0]['file'] .
' on line ' . $trace[0]['line'], E_USER_NOTICE);
return null;
}
}
\ No newline at end of file
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
// Usage example : // Usage example :
// ------------------------ // ------------------------
// Note that you might need to manually include 'lib/Dwoo.php', // Note that you might need to manually include 'lib/Dwoo.php',
// 'lib/Dwoo/Adapters/ZendFramework/View.php' and // 'lib/Dwoo/Adapters/ZendFramework/View.php',
// 'lib/Dwoo/Adapters/ZendFramework/Dwoo.php', and
// 'lib/Dwoo/Adapters/ZendFramework/PluginProxy.php' for this to // 'lib/Dwoo/Adapters/ZendFramework/PluginProxy.php' for this to
// work as expected, depending on your ZF setup // work as expected, depending on your ZF setup
// //
...@@ -15,6 +16,7 @@ $view = new Dwoo_Adapters_ZendFramework_View(array( ...@@ -15,6 +16,7 @@ $view = new Dwoo_Adapters_ZendFramework_View(array(
)); ));
// This allows you to use ZF's helpers as if they were Dwoo plugins (i.e. {doctype} will call the doctype helper) // This allows you to use ZF's helpers as if they were Dwoo plugins (i.e. {doctype} will call the doctype helper)
// This also allows you to use $this->variable to access view variables from within templates
$view->setPluginProxy(new Dwoo_Adapters_ZendFramework_PluginProxy(new Zend_View())); $view->setPluginProxy(new Dwoo_Adapters_ZendFramework_PluginProxy(new Zend_View()));
......
...@@ -33,14 +33,14 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -33,14 +33,14 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
* @var Dwoo_Compiler * @var Dwoo_Compiler
*/ */
protected $_compiler = null; protected $_compiler = null;
/** /**
* Changing Filter's scope to play nicely * Changing Filter's scope to play nicely
* *
* @var array * @var array
*/ */
protected $_filter = array(); protected $_filter = array();
/** /**
* @var string * @var string
...@@ -66,7 +66,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -66,7 +66,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
*/ */
public function __construct($opt = array()) public function __construct($opt = array())
{ {
if (is_array($opt)) { if (is_array($opt)) {
$this->setOptions($opt); $this->setOptions($opt);
} elseif ($opt instanceof Zend_Config) { } elseif ($opt instanceof Zend_Config) {
...@@ -81,7 +81,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -81,7 +81,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
* - engine = engine class name|engine object|array of options for engine * - engine = engine class name|engine object|array of options for engine
* - dataProvider = data provider class name|data provider object|array of options for data provider * - dataProvider = data provider class name|data provider object|array of options for data provider
* - compiler = compiler class name|compiler object|array of options for compiler * - compiler = compiler class name|compiler object|array of options for compiler
* - templateFile = * - templateFile =
* *
* Array of options: * Array of options:
* - type class name or object for engine, dataProvider or compiler * - type class name or object for engine, dataProvider or compiler
...@@ -92,22 +92,11 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -92,22 +92,11 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
*/ */
public function setOptions(array $opt = array()) public function setOptions(array $opt = array())
{ {
// BC checks // Making sure that everything is loaded.
// TODO remove in 1.1
if (isset($opt['compileDir']) || isset($opt['compile_dir'])) {
trigger_error('Dwoo ZF Adapter: the compile dir should be set in the $options[\'engine\'][\'compileDir\'] value the adapter settings', E_USER_WARNING);
}
if (isset($opt['cacheDir']) || isset($opt['cache_dir'])) {
trigger_error('Dwoo ZF Adapter: the cache dir should be set in the $options[\'engine\'][\'cacheDir\'] value the adapter settings', E_USER_WARNING);
}
// end BC
// Making sure that everything is loaded.
$classes = array('engine', 'dataProvider', 'compiler'); $classes = array('engine', 'dataProvider', 'compiler');
// Setting options to Dwoo objects... // Setting options to Dwoo objects...
foreach ($opt as $type => $settings) { foreach ($opt as $type => $settings) {
if (!method_exists($this, 'set' . $type)) { if (!method_exists($this, 'set' . $type)) {
throw new Dwoo_Exception("Unknown type $type"); throw new Dwoo_Exception("Unknown type $type");
} }
...@@ -119,11 +108,11 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -119,11 +108,11 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
if (array_key_exists('type', $settings)) { if (array_key_exists('type', $settings)) {
call_user_func(array($this, 'set' . $type), $settings['type']); call_user_func(array($this, 'set' . $type), $settings['type']);
} }
if (in_array($type, $classes)) { if (in_array($type, $classes)) {
// Call get so that the class is initialized // Call get so that the class is initialized
$rel = call_user_func(array($this, 'get' . $type)); $rel = call_user_func(array($this, 'get' . $type));
// Call set*() methods so that all the settings are set. // Call set*() methods so that all the settings are set.
foreach ($settings as $method => $value) { foreach ($settings as $method => $value) {
if (method_exists($rel, 'set' . $method)) { if (method_exists($rel, 'set' . $method)) {
...@@ -138,12 +127,12 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -138,12 +127,12 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
} }
} }
/** /**
* Set object state from Zend_Config object * Set object state from Zend_Config object
* *
* @param Zend_Config $config * @param Zend_Config $config
* @return Dwoo_Adapters_ZendFramework_View * @return Dwoo_Adapters_ZendFramework_View
*/ */
public function setConfig(Zend_Config $config) public function setConfig(Zend_Config $config)
{ {
return $this->setOptions($config->toArray()); return $this->setOptions($config->toArray());
...@@ -158,7 +147,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -158,7 +147,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
* @see Dwoo::setPluginProxy(); * @see Dwoo::setPluginProxy();
*/ */
protected function preRender() protected function preRender()
{ {
$this->getEngine()->setPluginProxy($this->getPluginProxy()); $this->getEngine()->setPluginProxy($this->getPluginProxy());
} }
...@@ -170,12 +159,12 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -170,12 +159,12 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
* @param string $name the variable name * @param string $name the variable name
* @param string $value the value to assign to it * @param string $value the value to assign to it
*/ */
public function __set($name, $value) public function __set($name, $value)
{ {
$this->getDataProvider()->__set($name, $value); $this->getDataProvider()->__set($name, $value);
} }
/** /**
* Sraper for Dwoo_Data::__get() allows to read variables using the object * Sraper for Dwoo_Data::__get() allows to read variables using the object
* syntax * syntax
* *
...@@ -183,22 +172,22 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -183,22 +172,22 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
* @param string $name the variable name * @param string $name the variable name
* @return mixed * @return mixed
*/ */
public function __get($name) public function __get($name)
{ {
return $this->getDataProvider()->__get($name); return $this->getDataProvider()->__get($name);
} }
/** /**
* Wraper for Dwoo_Data::__isset() * Wraper for Dwoo_Data::__isset()
* supports calls to isset($dwooData->var) * supports calls to isset($dwooData->var)
* *
* @see Dwoo_Data::__isset() * @see Dwoo_Data::__isset()
* @param string $name the variable name * @param string $name the variable name
*/ */
public function __isset($name) public function __isset($name)
{ {
return $this->getDataProvider()->__isset($name); return $this->getDataProvider()->__isset($name);
} }
/** /**
* Wraper for Dwoo_Data::_unset() * Wraper for Dwoo_Data::_unset()
...@@ -211,7 +200,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -211,7 +200,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
{ {
$this->getDataProvider()->__unset($name); $this->getDataProvider()->__unset($name);
} }
/** /**
* Catches clone request and clones data provider * Catches clone request and clones data provider
*/ */
...@@ -273,7 +262,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -273,7 +262,7 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
public function getEngine() public function getEngine()
{ {
if (null === $this->_engine) { if (null === $this->_engine) {
$this->_engine = new Dwoo(); $this->_engine = new Dwoo_Adapters_ZendFramework_Dwoo();
} }
return $this->_engine; return $this->_engine;
...@@ -339,25 +328,25 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -339,25 +328,25 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
* @return Dwoo_Data * @return Dwoo_Data
*/ */
public function getCompiler() public function getCompiler()
{ {
if (null === $this->_compiler) { if (null === $this->_compiler) {
$this->_compiler = Dwoo_Compiler::compilerFactory(); $this->_compiler = Dwoo_Compiler::compilerFactory();
} }
return $this->_compiler; return $this->_compiler;
} }
/** /**
* Initializes Dwoo_ITemplate type of class and sets properties from _templateFileSettings * Initializes Dwoo_ITemplate type of class and sets properties from _templateFileSettings
* *
* @param string Template location * @param string Template location
* @return Dwoo_ITemplate * @return Dwoo_ITemplate
*/ */
public function getTemplateFile($template) { public function getTemplateFile($template) {
$templateFileClass = $this->_templateFileClass; $templateFileClass = $this->_templateFileClass;
$dwooTemplateFile = new $templateFileClass($template); $dwooTemplateFile = new $templateFileClass($template);
if (!($dwooTemplateFile instanceof Dwoo_ITemplate)) { if (!($dwooTemplateFile instanceof Dwoo_ITemplate)) {
throw new Dwoo_Exception("Custom templateFile class must be a subclass of Dwoo_ITemplate"); throw new Dwoo_Exception("Custom templateFile class must be a subclass of Dwoo_ITemplate");
} }
...@@ -367,13 +356,13 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -367,13 +356,13 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
call_user_func(array($dwooTemplateFile, 'set' . $method), $value); call_user_func(array($dwooTemplateFile, 'set' . $method), $value);
} }
} }
return $dwooTemplateFile; return $dwooTemplateFile;
} }
/** /**
* Dwoo_ITemplate type of class * Dwoo_ITemplate type of class
* *
* @param string Name of the class * @param string Name of the class
* @return void * @return void
*/ */
...@@ -394,12 +383,12 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract ...@@ -394,12 +383,12 @@ class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
$this->getDataProvider()->assign($name, $val); $this->getDataProvider()->assign($name, $val);
return $this; return $this;
} }
/** /**
* Return list of all assigned variables * Return list of all assigned variables
* *
* @return array * @return array
*/ */
public function getVars() public function getVars()
{ {
return $this->_dataProvider->getData(); return $this->_dataProvider->getData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment