First public release of MyAAC

This commit is contained in:
slawkens1
2017-05-01 20:02:45 +02:00
parent 31172b4883
commit b5362d0654
2016 changed files with 114481 additions and 0 deletions

View File

@@ -0,0 +1,196 @@
<?php
/**
* Dwoo adapter for Agavi
*
* Install instructions :
* - download dwoo from dwoo.org and unzip it somewhere in your agavi app
* - add a renderer to your output_types.xml as such :
* <renderer name="dwoo" class="DwooRenderer">
* <parameter name="assigns">
* <parameter name="routing">ro</parameter>
* <parameter name="request">rq</parameter>
* <parameter name="controller">ct</parameter>
* <parameter name="user">us</parameter>
* <parameter name="translation_manager">tm</parameter>
* <parameter name="request_data">rd</parameter>
* </parameter>
* <parameter name="extract_vars">true</parameter>
* <parameter name="plugin_dir">%core.lib_dir%/dwoo_plugins</parameter>
* </renderer>
*
* - add dwoo's directory to your include path or include dwooAutoload.php yourself
* either through agavi's autoload.xml (with name="Dwoo") or through your index.php
*
* Notes:
* - you can copy the /Dwoo/Adapters/Agavi/dwoo_plugins directory to your agavi app's
* lib directory, or change the plugin_dir parameter in the output_types.xml file.
* these plugins are agavi-specific helpers that shortens the syntax to call common
* agavi helpers (i18n, routing, ..)
*
* 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>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2009-07-18
* @package Dwoo
*/
class DwooRenderer extends AgaviRenderer implements AgaviIReusableRenderer
{
/**
* @constant string The directory inside the cache dir where templates will
* be stored in compiled form.
*/
const COMPILE_DIR = 'templates';
/**
* @constant string The subdirectory inside the compile dir where templates
* will be stored in compiled form.
*/
const COMPILE_SUBDIR = 'dwoo';
/**
* @constant string The directory inside the cache dir where cached content
* will be stored.
*/
const CACHE_DIR = 'dwoo';
/**
* @var Dwoo Dwoo template engine.
*/
protected $dwoo = null;
/**
* @var string A string with the default template file extension,
* including the dot.
*/
protected $defaultExtension = '.html';
/**
* stores the (optional) plugin directory to add to the Dwoo_Loader
*/
protected $plugin_dir = null;
/**
* Pre-serialization callback.
*
* Excludes the Dwoo instance to prevent excessive serialization load.
*/
public function __sleep()
{
$keys = parent::__sleep();
unset($keys[array_search('dwoo', $keys)]);
return $keys;
}
/**
* Initialize this Renderer.
*
* @param AgaviContext The current application context.
* @param array An associative array of initialization parameters.
*/
public function initialize(AgaviContext $context, array $parameters = array())
{
parent::initialize($context, $parameters);
$this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir);
}
/**
* provides a custom compiler to the dwoo renderer with optional settings
* you can set in the agavi output_types.xml config file
*
* @return Dwoo_Compiler
*/
public function compilerFactory()
{
if (class_exists('Dwoo_Compiler', false) === false) {
include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
}
$compiler = Dwoo_Compiler::compilerFactory();
$compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false));
return $compiler;
}
/**
* Grab a cleaned up dwoo instance.
*
* @return Dwoo A Dwoo instance.
*/
protected function getEngine()
{
if($this->dwoo) {
return $this->dwoo;
}
if(!class_exists('Dwoo')) {
if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) {
// file was dropped with the entire dwoo package
require dirname(__FILE__).'/../../../dwooAutoload.php';
} else {
// assume the dwoo package is in the include path
require 'dwooAutoload.php';
}
}
$parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
$compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
AgaviToolkit::mkdir($compileDir, $parentMode, true);
$cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
AgaviToolkit::mkdir($cacheDir, $parentMode, true);
$this->dwoo = new Dwoo($compileDir, $cacheDir);
if (!empty($this->plugin_dir)) {
$this->dwoo->getLoader()->addDirectory($this->plugin_dir);
}
$this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
return $this->dwoo;
}
/**
* Render the presentation and return the result.
*
* @param AgaviTemplateLayer The template layer to render.
* @param array The template variables.
* @param array The slots.
* @param array Associative array of additional assigns.
*
* @return string A rendered result.
*/
public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array())
{
$engine = $this->getEngine();
$data = array();
if($this->extractVars) {
$data = $attributes;
} else {
$data[$this->varName] = &$attributes;
}
$data[$this->slotsVarName] =& $slots;
foreach($this->assigns as $key => $getter) {
$data[$key] = $this->context->$getter();
}
foreach($moreAssigns as $key => &$value) {
if(isset($this->moreAssignNames[$key])) {
$key = $this->moreAssignNames[$key];
}
$data[$key] =& $value;
}
return $engine->get($layer->getResourceStreamIdentifier(), $data);
}
}

View File

@@ -0,0 +1,27 @@
// ------------------------
// Install notes :
// ------------------------
- drop dwoo's directory in app/lib/renderer (create if needed)
- add a renderer to app/config/output_types.xml as such :
<renderer name="dwoo" class="DwooRenderer">
<parameter name="assigns">
<parameter name="routing">ro</parameter>
<parameter name="request">rq</parameter>
<parameter name="controller">ct</parameter>
<parameter name="user">us</parameter>
<parameter name="translation_manager">tm</parameter>
<parameter name="request_data">rd</parameter>
</parameter>
<parameter name="extract_vars">true</parameter>
<parameter name="plugin_dir">%core.lib_dir%/dwoo_plugins</parameter>
</renderer>
- add the renderer to app/config/autoload.xml as such :
<autoload name="DwooRenderer">%core.lib_dir%/renderer/dwoo/Dwoo/Adapter/Agavi/DwooRenderer.php</autoload>
- you can copy the /Dwoo/Adapters/Agavi/dwoo_plugins directory to your agavi app's
lib directory, or change the plugin_dir parameter in the output_types.xml file.
these plugins are agavi-specific helpers that shortens the syntax to call common
agavi helpers (i18n, routing, ..)

View File

@@ -0,0 +1,32 @@
<?php
/**
* <strong>Agavi specific plugin</strong>
*
* uses AgaviTranslationManager to localize a string
*
* <pre>
* * string : the string to localize
* </pre>
*
* Examples:
* <code>
* {t "Hello"}
* {t $header}
* </code>
*
* 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>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.0.0
* @date 2008-10-23
* @package Dwoo
*/
function Dwoo_Plugin_t_compile(Dwoo_Compiler $compiler, $string)
{
return '$this->data[\'tm\']->_('.$string.')';
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* <strong>Agavi specific plugin</strong>
*
* uses AgaviRouting to create an url
*
* <pre>
* * route : the route name, optional (by default the current url is returned)
* * params : an array with variables to build the route, optional
* * options : an array of options to pass to the routing object, optional
* * rest : for convenience, you can just pass named parameters that will be used as
* the params array, but you must not provide the params array in this case
* </pre>
*
* Examples:
* <code>
* {a url("route.name" array(param="Value", param2=$otherVal))}Here is a link{/a}
* <form action="{url}"> {* without any parameter it just returns the current url *}
* </code>
*
* 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>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.0.0
* @date 2008-10-23
* @package Dwoo
*/
function Dwoo_Plugin_url_compile(Dwoo_Compiler $compiler, $route = null, $params = null, $options = null, array $rest = array())
{
if ($params == 'null') {
if (count($rest)) {
$params = array();
foreach ($rest as $k=>$v) {
if (is_numeric($k)) {
$params[] = $k.'=>'.$v;
} else {
$params[] = '"'.$k.'"=>'.$v;
}
}
$params = 'array('.implode(', ', $params).')';
} else {
$params = 'array()';
}
}
if ($options == 'null') {
$options = 'array()';
}
return '$this->data[\'ro\']->gen('.$route.', '.$params.', '.$options.')';
}

View File

@@ -0,0 +1,33 @@
// CakePHP Dwoo bridge - v0.2
// ------------------------
// Installation :
// ------------------------
// 1. Download and install the dwoo library, preferably on the
// 'vendors' directory of CakePHP. However you can place it
// anywhere you want; if you do, make sure to change the App::import
// line in dwoo.php to include the dwoo library properly.
//
// 2. Place this file in the app/views directory, or on cake/libs/view.
//
// 3. Create the app/tmp/dwoo/cache and app/tmp/dwoo/compile directories
// and make sure they are writable.
// ------------------------
// Usage example :
// ------------------------
// In your controller class you need to change the view property to
// use Dwoo at some point in the execution using :
$this->view = 'Dwoo';
// Or you can also override the view property in your AppController class as such :
class AppController extends Controller {
public $view = 'Dwoo';
}
// If you want another template extension (default is .tpl) you must
// edit the dwoo.php file at line 44 and change it to :
$this->ext = ".html";
//{include $templatedir."index.tpl"}

View File

@@ -0,0 +1,143 @@
<?php
App::import('vendor', 'dwoo', array("file" => 'dwoo/dwooAutoload.php'));
/**
* Dwoo adapter for CakePHP
*
* Based on SmartyView by Mark John S. Buenconsejo <mjwork@simpleteq.com>
*
* 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.
*
* This file is released under the LGPL
* "GNU Lesser General Public License"
* More information can be found here:
* {@link http://www.gnu.org/copyleft/lesser.html}
*
* @author Mark John S. Buenconsejo <mjwork@simpleteq.com>
* @author Giangi <giangi@qwerg.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2009-07-18
* @package Dwoo
*/
class DwooView extends View
{
protected $_sv_template_dir;
protected $_sv_layout_dir;
protected $_sv_compile_dir;
protected $_sv_cache_dir;
protected $_sv_compile_id;
protected $_dwoo;
public $sv_processedTpl;
public function __construct(&$controller)
{
parent::__construct($controller);
$this->ext = '.tpl';
$this->_sv_template_dir = array
(
VIEWS . $this->viewPath . DS . $this->subDir,
VIEWS . $this->viewPath,
VIEWS
);
$this->_sv_layout_dir = array
(
LAYOUTS . $this->subDir,
VIEWS
);
$this->_sv_compile_dir = TMP . 'dwoo' . DS . 'compile';
$this->_sv_cache_dir = TMP . 'dwoo' . DS . 'cache';
$this->_dwoo = new Dwoo($this->_sv_compile_dir, $this->_sv_cache_dir);
$this->_sv_compile_id = $controller->name;
$this->_dwoo->sv_this = $this;
$this->_dwoo->setSecurityPolicy();
return;
}
/**
* changes the template directory
*/
public function setTemplateDir($path = VIEW) {
$old = $this->_sv_template_dir;
$this->_sv_template_dir = $path;
return $old;
}
public function getTemplateDir() {
return $this->_sv_template_dir ;
}
public function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true)
{
// let's determine if this is a layout call or a template call
// and change the template dir accordingly
$layout = false;
if(isset($___data_for_view['content_for_layout'])) {
$this->_sv_template_dir = $this->_sv_layout_dir;
$layout = true;
}
$tpl = new Dwoo_Template_File($___viewFn);
$data = $___data_for_view;
$data['view'] = $this;
if ($this->helpers != false && $loadHelpers === true) {
$loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach (array_keys($loadedHelpers) as $helper) {
$camelBackedHelper = strtolower(substr($helper, 0, 1)) . substr($helper, 1);
${$camelBackedHelper} = $loadedHelpers[$helper];
if (is_array(${$camelBackedHelper}->helpers) && !empty(${$camelBackedHelper}->helpers)) {
$subHelpers = ${$camelBackedHelper}->helpers;
foreach ($subHelpers as $subHelper) {
${$camelBackedHelper}->{$subHelper} = $loadedHelpers[$subHelper];
}
}
if(isset($this->passedArgs)) {
${$camelBackedHelper}->passedArgs = $this->passedArgs;
}
$this->loaded[$camelBackedHelper] = ${$camelBackedHelper};
$data[$camelBackedHelper] = ${$camelBackedHelper};
}
}
if ($this->helpers != false && $loadHelpers === true) {
foreach ($loadedHelpers as $helper) {
if (is_object($helper)) {
if (is_subclass_of($helper, 'Helper') || is_subclass_of($helper, 'helper')) {
$helper->beforeRender();
}
}
}
}
return $this->_dwoo->get($tpl, $data);
}
public function get(){
return $this->_dwoo;
}
}

View File

@@ -0,0 +1,36 @@
CodeIgniter/Dwoo adapater
-------------------------
Integration of Dwoo into Codeigniter (1.7.0 >)
Links:
Dwoo - http://dwoo.org
CodeIgniter - http://codeigniter.com
Installation:
1) Extract package into your application directory (i.e. $webroot/application or
$webroot/system/application)
2) Change the parameters in config/dwootemplate.php
3) Create the compile and cache directory you set in your config file in step 2
and give it the correct rights (chmod 777 when on *nix)
4) Extract/copy the Dwoo package into application/libraries/dwoo
5) Browse to : http://[yoururl]/dwoowelcome
Version info
1.0.2 [11-03-2009] Fixed a problem with $data attribute (which Dwoo also used)
1.0.1 [12-11-2008] Removed some & in the dwootemplate
Changed licencse
Changed 'output' in 'get' in the dwootemplate (line 122)
1.0.0 [11-11-2008] Initial release
Questions/Remarks?
mail to: stefan.verstege@newmedia.nl
IM me on GTALK: verstege@gmail.com
Contact me on the Dwoo forums: stefanv
---------[ copyright notice ]-----------------------------------------------------------------------
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.
License http://dwoo.org/LICENSE Modified BSD License

View File

@@ -0,0 +1,12 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
// The name of the directory where templates are located.
$config['template_dir'] = dirname(FCPATH) . '/../application/views/';
// The directory where compiled templates are located
$config['compileDir'] = dirname(FCPATH) . '/../compile/';
//This tells Dwoo whether or not to cache the output of the templates to the $cache_dir.
$config['caching'] = 0;
$config['cacheDir'] = dirname(FCPATH) . '/../cache/';
$config['cacheTime'] = 0;

View File

@@ -0,0 +1,16 @@
<?php
class Dwoowelcome extends Controller {
function __construct()
{
parent::Controller();
}
function index()
{
$this->load->library('Dwootemplate');
$this->dwootemplate->assign('itshowlate', date('H:i:s'));
$this->dwootemplate->display('dwoowelcome.tpl');
}
}

View File

@@ -0,0 +1,172 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require "dwoo/dwooAutoload.php";
/**
* Creates an template interface from Codeigniter to DWOO.
*
* 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 Stefan Verstege <stefan.verstege@newmedia.nl>
* @copyright Copyright (c) 2008, Stefan Verstege
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://www.newmedia.nl/
* @version 1.1.0
* @date 2009-07-18
* @package Dwoo
*
* @uses the dwoo package from http://dwoo.org
*/
class Dwootemplate extends Dwoo {
protected $dwoo_data = array();
/**
* Constructor for the DwooTemplate engine
*
*/
public function __construct() {
// Call parents constructor
parent::__construct();
// Set the config settings
$this->initialize();
// Assign some defaults to dwoo
$CI = get_instance();
$this->dwoo_data = new Dwoo_Data();
$this->dwoo_data->js_files = array();
$this->dwoo_data->css_files = array();
$this->dwoo_data->CI = $CI;
$this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily
$this->dwoo_data->uniqid = uniqid();
$this->dwoo_data->timestamp = mktime();
log_message('debug', "Dwoo Template Class Initialized");
}
/**
* Assign data to dwoo data object
*
* @param string $key
* @param mixed $value
*/
public function assign($key, $value) {
$this->dwoo_data->$key = $value;
}
/**
* Add Javascript files to template
*
* @param string $js
*/
public function add_js($js) {
$current = $this->dwoo_data->js_files;
$current[] = $js;
$this->dwoo_data->js_files = $current;
}
/**
* Add Css stylesheets to template
*
* @param string $css
*/
public function add_css($css) {
$current = $this->dwoo_data->css_files;
$current[] = $css;
$this->dwoo_data->css_files = $current;
}
/**
* Display or return the compiled template
* Since we assign the results to the standard CI output module
* you can also use the helper from CI in your templates!!
*
* @param string $sTemplate
* @param boolean $return
* @return mixed
*/
public function display($sTemplate, $return = FALSE) {
// Start benchmark
$CI = get_instance();
$CI->benchmark->mark('dwoo_parse_start');
// Check if file exists
if ( !file_exists($this->template_dir . $sTemplate ) ) {
$message = sprintf('Template file \'%s\' not found.', $sTemplate);
show_error($message);
log_message('error', $message);
}
// Create new template
$tpl = new Dwoo_Template_File($this->template_dir . $sTemplate);
// render the template
$template = $this->get($tpl, $this->dwoo_data);
// Finish benchmark
$CI->benchmark->mark('dwoo_parse_end');
// Return results or not ?
if ($return == FALSE) {
$CI->output->final_output = $template;
} else {
return $template;
}
}
/**
* Toggle Codeigniter profiler on/off
*
*/
public function enable_profiler($toggle = TRUE) {
$CI = get_instance();
$CI->output->enable_profiler($toggle);
}
/**
* Set http header
*
* @example $this->output->set_header("HTTP/1.1 200 OK");
* @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
* @param string $header
*/
public function set_header($header) {
$CI = get_instance();
$CI->output->set_header($header);
}
/**
* Set status header
*
* @example $this->output->set_status_header('401');
* @example // Sets the header as: Unauthorized
* @param string $header
*/
public function set_status_header($header) {
$CI = get_instance();
$CI->output->set_status_header($header);
}
/**
* Assign the dwootemplate config items to the instance
*
*/
private function initialize() {
$CI = get_instance();
$CI->config->load('dwootemplate', TRUE);
$config = $CI->config->item('dwootemplate');
foreach ($config as $key => $val) {
$this->$key = $val;
}
}
}

View File

@@ -0,0 +1,31 @@
{extends "page.tpl"}
{block "title"}
Welcome to Dwoo-ed CodeIgniter
{/block}
{block "content"}
<h1>Welcome to Dwoo-ed CodeIgniter!</h1>
<p>The page you are looking at is being generated dynamically by <b>CodeIgniter</b> in combination with the 'Smarty-killer' <b>Dwoo</b> template engine.
The page is rendered at {$itshowlate} by the Dwoo_compiler.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/dwoowelcome.tpl</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/dwoowelcome.php</code>
<p>The library for Dwoo integration can be found at:</p>
<code>application/libraries/Dwootemplate.php</code>
<p>If you are exploring Dwoo for the very first time, you should start by reading the {anchor uri='http://dwoo.org/' title='Dwoo website'}.</p>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the {anchor uri='http://codeigniter.com/user_guide/' title='User Guide'}.</p>
<pre>
<b>Usage</b>:
$this->load->library('Dwootemplate');
$this->dwootemplate->assign('test', 'test');
$this->dwootemplate->display('dwoowelcome.tpl');
</pre>
{/block}

View File

@@ -0,0 +1,57 @@
<html>
<head>
<title>{block "title"}Here come the title{/block}</title>
<style type="text/css">
body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 16px;
font-weight: bold;
margin: 24px 0 2px 0;
padding: 5px 0 6px 0;
}
code {
font-family: Monaco, Verdana, Sans-serif;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
pre {
font-family: Monaco, Verdana, Sans-serif;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #B9BAA4;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
</style>
</head>
<body>
{block "content"}Here comes the content{/block}
</body>
</html>

View File

@@ -0,0 +1,96 @@
<?php
/**
* PluginProxy class for Zend View
*
* 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 Denis Arh <denis@arh.cc>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Denis Arh, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.0.0
* @date 2008-10-23
* @package Dwoo
*/
class Dwoo_Adapters_ZendFramework_PluginProxy implements Dwoo_IPluginProxy
{
/**
* reference to the zend view owning this proxy
*
* @var Zend_View_Interface
*/
public $view;
/**
* Dwoo_Adapters_ZendFramework_PluginProxy's constructor.
*
* @param Zend_View_Interface $view
*/
public function __construct(Zend_View_Interface $view) {
$this->view = $view;
}
/**
* Called from Dwoo_Compiler to check if the requested plugin is available
*
* @param string $name
* @return bool
*/
public function handles($name) {
try {
$this->view->getHelper($name);
} catch (Zend_Loader_PluginLoader_Exception $e) {
return false;
}
return true;
}
/**
* returns the code (as a string) to call the plugin
* (this will be executed at runtime inside the Dwoo class)
*
* @param string $name the plugin name
* @param array $params a parameter array, array key "*" is the rest array
* @return string
*/
public function getCode($name, $params) {
return '$this->getPluginProxy()->view->'. $name .'('.Dwoo_Compiler::implode_r($params).')';
}
/**
* returns a callback to the plugin, this is used with the reflection API to
* find out about the plugin's parameter names etc.
*
* should you need a rest array (i.e. for ZendFramework helpers) without the
* possibility to edit the plugin's code, you can provide a callback to some
* other function with the correct parameter signature, i.e. :
* <code>
* return array($this, "callbackHelper");
* // and callbackHelper would be as such:
* public function callbackHelper(array $rest=array()){}
* </code>
*
* @param string $name the plugin name
* @return callback
*/
public function getCallback($name) {
return array($this->view->getHelper($name), $name);
}
/**
* returns some code that will check if the plugin is loaded and if not load it
* this is optional, if your plugins are autoloaded or whatever, just return an
* empty string
*
* @param string $name the plugin name
* @return string
*/
public function getLoader($name) {
return '';
}
}

View File

@@ -0,0 +1,32 @@
// ------------------------
// Usage example :
// ------------------------
// Note that you might need to manually include 'lib/Dwoo.php',
// 'lib/Dwoo/Adapters/ZendFramework/View.php' and
// 'lib/Dwoo/Adapters/ZendFramework/PluginProxy.php' for this to
// work as expected, depending on your ZF setup
//
// If anyone writes a more advanced how-to please let me know
// ------------------------
$view = new Dwoo_Adapters_ZendFramework_View(array(
'compileDir' => 'path/to/compile_dir' // set to null or remove this line to use defaults
'cacheDir' => 'path/to/cache_dir' // set to null or remove this line to use defaults
));
// This allows you to use ZF's helpers as if they were Dwoo plugins (i.e. {doctype} will call the doctype helper)
$view->setPluginProxy(new Dwoo_Adapters_ZendFramework_PluginProxy(new Zend_View()));
// 1. example - used with the Zend Controller
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
// 2. example - used manually
$view->assign('foo', 'bar');
$view->display('foobar.phtml');

View File

@@ -0,0 +1,512 @@
<?php
/**
* Dwoo adapter 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 Denis Arh <denis@arh.cc>
* @author Stephan Wentz <stephan@wentz.it>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2009-07-18
* @package Dwoo
*/
class Dwoo_Adapters_ZendFramework_View extends Zend_View_Abstract
{
/**
* @var Dwoo
*/
protected $_engine = null;
/**
* @var Dwoo_Data
*/
protected $_dataProvider = null;
/**
* @var Dwoo_Compiler
*/
protected $_compiler = null;
/**
* Changing Filter's scope to play nicely
*
* @var array
*/
protected $_filter = array();
/**
* @var string
*/
protected $_templateFileClass = 'Dwoo_Template_File';
/**
* @var array
*/
protected $_templateFileSettings = array();
/**
* @var Dwoo_IPluginProxy
*/
protected $_pluginProxy = null;
/**
* Constructor method.
* See setOptions for $opt details
*
* @see setOptions
* @param array|Zend_Config List of options or Zend_Config instance
*/
public function __construct($opt = array())
{
if (is_array($opt)) {
$this->setOptions($opt);
} elseif ($opt instanceof Zend_Config) {
$this->setConfig($opt);
}
$this->init();
}
/**
* Set object state from options array
* - 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
* - compiler = compiler class name|compiler object|array of options for compiler
* - templateFile =
*
* Array of options:
* - type class name or object for engine, dataProvider or compiler
* - any set* method (compileDir for setCompileDir ...)
*
* @param array $options
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setOptions(array $opt = array())
{
// BC checks
// 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');
// Setting options to Dwoo objects...
foreach ($opt as $type => $settings) {
if (!method_exists($this, 'set' . $type)) {
throw new Dwoo_Exception("Unknown type $type");
}
if (is_string($settings) || is_object($settings)) {
call_user_func(array($this, 'set' . $type), $settings);
} elseif (is_array($settings)) {
// Set requested class
if (array_key_exists('type', $settings)) {
call_user_func(array($this, 'set' . $type), $settings['type']);
}
if (in_array($type, $classes)) {
// Call get so that the class is initialized
$rel = call_user_func(array($this, 'get' . $type));
// Call set*() methods so that all the settings are set.
foreach ($settings as $method => $value) {
if (method_exists($rel, 'set' . $method)) {
call_user_func(array($rel, 'set' . $method), $value);
}
}
} elseif ('templateFile' == $type) {
// Remember the settings for the templateFile
$this->_templateFileSettings = $settings;
}
}
}
}
/**
* Set object state from Zend_Config object
*
* @param Zend_Config $config
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setConfig(Zend_Config $config)
{
return $this->setOptions($config->toArray());
}
/**
* Called before template rendering
*
* Binds plugin proxy to the Dwoo.
*
* @see Dwoo_Adapters_ZendFramework_View::getPluginProxy();
* @see Dwoo::setPluginProxy();
*/
protected function preRender()
{
$this->getEngine()->setPluginProxy($this->getPluginProxy());
}
/**
* Wraper for Dwoo_Data::__set()
* allows to assign variables using the object syntax
*
* @see Dwoo_Data::__set()
* @param string $name the variable name
* @param string $value the value to assign to it
*/
public function __set($name, $value)
{
$this->getDataProvider()->__set($name, $value);
}
/**
* Sraper for Dwoo_Data::__get() allows to read variables using the object
* syntax
*
* @see Dwoo_Data::__get()
* @param string $name the variable name
* @return mixed
*/
public function __get($name)
{
return $this->getDataProvider()->__get($name);
}
/**
* Wraper for Dwoo_Data::__isset()
* supports calls to isset($dwooData->var)
*
* @see Dwoo_Data::__isset()
* @param string $name the variable name
*/
public function __isset($name)
{
return $this->getDataProvider()->__isset($name);
}
/**
* Wraper for Dwoo_Data::_unset()
* supports unsetting variables using the object syntax
*
* @see Dwoo_Data::__unset()
* @param string $name the variable name
*/
public function __unset($name)
{
$this->getDataProvider()->__unset($name);
}
/**
* Catches clone request and clones data provider
*/
public function __clone() {
$this->setDataProvider(clone $this->getDataProvider());
}
/**
* Returns plugin proxy interface
*
* @return Dwoo_IPluginProxy
*/
public function getPluginProxy()
{
if (!$this->_pluginProxy) {
$this->_pluginProxy = new Dwoo_Adapters_ZendFramework_PluginProxy($this);
}
return $this->_pluginProxy;
}
/**
* Sets plugin proxy
*
* @param Dwoo_IPluginProxy
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setPluginProxy(Dwoo_IPluginProxy $pluginProxy)
{
$this->_pluginProxy = $pluginProxy;
return $this;
}
/**
* Sets template engine
*
* @param string|Dwoo Object or name of the class
*/
public function setEngine($engine)
{
// if param given as an object
if ($engine instanceof Dwoo) {
$this->_engine = $engine;
}
//
elseif (is_subclass_of($engine, 'Dwoo') || 'Dwoo' === $engine) {
$this->_engine = new $engine();
}
else {
throw new Dwoo_Exception("Custom engine must be a subclass of Dwoo");
}
}
/**
* Return the Dwoo template engine object
*
* @return Dwoo
*/
public function getEngine()
{
if (null === $this->_engine) {
$this->_engine = new Dwoo();
}
return $this->_engine;
}
/**
* Sets Dwoo data object
*
* @param string|Dwoo_Data Object or name of the class
*/
public function setDataProvider($data)
{
if ($data instanceof Dwoo_IDataProvider) {
$this->_dataProvider = $data;
}
elseif (is_subclass_of($data, 'Dwoo_Data') || 'Dwoo_Data' == $data) {
$this->_dataProvider = new $data();
}
else {
throw new Dwoo_Exception("Custom data provider must be a subclass of Dwoo_Data or instance of Dwoo_IDataProvider");
}
}
/**
* Return the Dwoo data object
*
* @return Dwoo_Data
*/
public function getDataProvider()
{
if (null === $this->_dataProvider) {
$this->_dataProvider = new Dwoo_Data;
}
return $this->_dataProvider;
}
/**
* Sets Dwoo compiler
*
* @param string|Dwoo_Compiler Object or name of the class
*/
public function setCompiler($compiler)
{
// if param given as an object
if ($compiler instanceof Dwoo_ICompiler) {
$this->_compiler = $compiler;
}
// if param given as a string
elseif (is_subclass_of($compiler, 'Dwoo_Compiler') || 'Dwoo_Compiler' == $compiler) {
$this->_compiler = new $compiler;
}
else {
throw new Dwoo_Exception("Custom compiler must be a subclass of Dwoo_Compiler or instance of Dwoo_ICompiler");
}
}
/**
* Return the Dwoo compiler object
*
* @return Dwoo_Data
*/
public function getCompiler()
{
if (null === $this->_compiler) {
$this->_compiler = Dwoo_Compiler::compilerFactory();
}
return $this->_compiler;
}
/**
* Initializes Dwoo_ITemplate type of class and sets properties from _templateFileSettings
*
* @param string Template location
* @return Dwoo_ITemplate
*/
public function getTemplateFile($template) {
$templateFileClass = $this->_templateFileClass;
$dwooTemplateFile = new $templateFileClass($template);
if (!($dwooTemplateFile instanceof Dwoo_ITemplate)) {
throw new Dwoo_Exception("Custom templateFile class must be a subclass of Dwoo_ITemplate");
}
foreach ($this->_templateFileSettings as $method => $value) {
if (method_exists($dwooTemplateFile, 'set' . $method)) {
call_user_func(array($dwooTemplateFile, 'set' . $method), $value);
}
}
return $dwooTemplateFile;
}
/**
* Dwoo_ITemplate type of class
*
* @param string Name of the class
* @return void
*/
public function setTemplateFile($tempateFileClass) {
$this->_templateFileClass = $tempateFileClass;
}
/**
* Passes data to Dwoo_Data object
*
* @see Dwoo_Data::assign()
* @param array|string $name
* @param mixed $val
* @return Dwoo_Adapters_ZendFramework_View
*/
public function assign($name, $val = null)
{
$this->getDataProvider()->assign($name, $val);
return $this;
}
/**
* Return list of all assigned variables
*
* @return array
*/
public function getVars()
{
return $this->_dataProvider->getData();
}
/**
* Clear all assigned variables
*
* Clears all variables assigned to Zend_View either via {@link assign()} or
* property overloading ({@link __get()}/{@link __set()}).
*
* @return void
* @return Dwoo_Adapters_ZendFramework_View
*/
public function clearVars()
{
$this->getDataProvider()->clear();
return $this;
}
/**
* Wraper for parent's render method so preRender method
* can be called (that will bind the plugin proxy to the
* engine.
*
* @see Zend_View_Abstract::render
* @return string The script output.
*/
public function render($name)
{
$this->preRender();
return parent::render($name);
}
/**
* Processes a view script and outputs it. Output is then
* passed through filters.
*
* @param string $name The script script name to process.
* @return string The script output.
*/
public function _run()
{
echo $this->_engine->get(
$this->getTemplateFile(func_get_arg(0)),
$this->getDataProvider(),
$this->getCompiler()
);
}
/**
* Add plugin path
*
* @param string $dir Directory
* @return Dwoo_Adapters_ZendFramework_View
*/
public function addPluginDir($dir)
{
$this->getEngine()->getLoader()->addDirectory($dir);
return $this;
}
/**
* Set compile path
*
* @param string $dir Directory
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setCompileDir($dir)
{
$this->getEngine()->setCompileDir($dir);
return $this;
}
/**
* Set cache path
*
* @param string $dir Directory
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setCacheDir($dir)
{
$this->getEngine()->setCacheDir($dir);
return $this;
}
/**
* Set cache lifetime
*
* @param string $seconds Lifetime in seconds
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setCacheLifetime($seconds)
{
$this->getEngine()->setCacheTime($seconds);
return $this;
}
/**
* Set charset
*
* @param string $charset
* @return Dwoo_Adapters_ZendFramework_View
*/
public function setCharset($charset)
{
$this->_engine->setCharset($charset);
return $this;
}
}