Commit 478bf677 by Seldaek

! Important note : Dwoo.php should not be included directly anymore, please

read the UPGRADE_NOTES file for more infos on the matter, if you don't your Dwoo install will most likely break after the update anyway * Various optimizations git-svn-id: svn://dwoo.org/dwoo/trunk@165 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 396dcf06
[2008-09-] 0.9.4
[2008-09-] 1.0.0beta
! Important note : Dwoo.php should not be included directly anymore, please
read the UPGRADE_NOTES file for more infos on the matter, if you don't
your Dwoo install will most likely break after the update anyway
! BC Break: {include} and {extends} now support the include path properly,
which means that if you include "foo/bar.html" from _any_ template and you
have an include path set on your template object, it will look in all those
......@@ -19,6 +22,7 @@
Dwoo_ITemplate objects or valid filenames are accepted
* Foreach and other similar plugins that support "else" now only count()
their input before processing when an else block follows
* Various optimizations
* Fixed compiler bug that created a parse error when you had comments in an
extended template
* Fixed extends bug when extending files in other directories using relative
......
......@@ -34,7 +34,7 @@ http://www.gnu.org/licenses/lgpl.html
-----------------------------------------------------------------------------
/***************************** Basic Example *******************************/
// Include the main class (it should handle the rest on its own)
include 'path/to/Dwoo.php';
include 'path/to/dwooAutoload.php';
// Create the controller, this is reusable
$dwoo = new Dwoo();
......@@ -59,7 +59,7 @@ $dwoo->get($tpl, $data);
// To loop over multiple articles of a blog for instance, if you have a
// template file representing an article, you could do the following :
include 'path/to/Dwoo.php';
include 'path/to/dwooAutoload.php';
$dwoo = new Dwoo();
$tpl = new Dwoo_Template_File('path/to/article.tpl');
......
-----------------------------------------------------------------------------
-- Upgrading to Dwoo v1.0.0beta
-----------------------------------------------------------------------------
1. Dwoo classes loading
-----------------------
While everything was previously included by Dwoo.php, this version introduces
an autoload function (dwooAutoload) that handles this automatically. This
means your choices are now :
a) change your : include 'path/to/Dwoo.php';
into : include 'path/to/dwooAutoload.php';
this is the recommended setting, especially during development, so that if you
are seeing a Dwoo error and want to report a bug, you get proper line numbers
with the error and not just "error in Dwoo.compiled.php at line 2"
b) use the compiled version of Dwoo, this is "experimental" and seems to provide better
performances mostly under windows, with a linux server it might imrpove performances
slightly if you have an opcode cache (APC, xcache, ..) :
include 'path/to/Dwoo.compiled.php';
c) load Dwoo classes yourself somehow, as part of your autoload function or
whatever suits you best
-----------------------------------------------------------------------------
-- Upgrading to Dwoo v0.9.2
-----------------------------------------------------------------------------
1. Block plugins
-----------------
----------------
This version introduced a backward compatibility break with block plugins, this
was needed to allow compile-time access to the block's (parsed) content, be
......
<?php
define('DWOO_DIRECTORY', dirname(__FILE__).DIRECTORY_SEPARATOR);
set_include_path(get_include_path() . PATH_SEPARATOR . DWOO_DIRECTORY);
include 'Dwoo/IPluginProxy.php';
include 'Dwoo/ILoader.php';
include 'Dwoo/IElseable.php';
include 'Dwoo/Loader.php';
include 'Dwoo/Exception.php';
include 'Dwoo/Security/Policy.php';
include 'Dwoo/Security/Exception.php';
include 'Dwoo/ICompilable.php';
include 'Dwoo/ICompiler.php';
include 'Dwoo/IDataProvider.php';
include 'Dwoo/ITemplate.php';
include 'Dwoo/ICompilable/Block.php';
include 'Dwoo/Plugin.php';
include 'Dwoo/Block/Plugin.php';
include 'Dwoo/Filter.php';
include 'Dwoo/Processor.php';
include 'Dwoo/Template/String.php';
include 'Dwoo/Template/File.php';
include 'Dwoo/Data.php';
define('DWOO_DIRECTORY', dirname(__FILE__) . DIRECTORY_SEPARATOR);
// TODO BC Checks, remove
if (defined('DWOO_CACHE_DIRECTORY'))
throw new Dwoo_Exception('DWOO_CACHE_DIRECTORY is deprecated, you should now set this in Dwoo\'s constructor using new Dwoo([ $compileDir [, $cacheDir ]])');
if (defined('DWOO_COMPILE_DIRECTORY'))
throw new Dwoo_Exception('DWOO_COMPILE_DIRECTORY is deprecated, you should now set this in Dwoo\'s constructor using new Dwoo([ $compileDir [, $cacheDir ]])');
if (defined('DWOO_CHMOD')) {
throw new Dwoo_Exception('DWOO_CHMOD is deprecated, you should now set this on your template object using $tpl->setChmod('.DWOO_CHMOD.');');
}
// end
if (defined('DWOO_CHMOD') === false)
define('DWOO_CHMOD', 0777);
/**
* main dwoo class, allows communication between the compiler, template and data classes
*
......@@ -134,7 +113,7 @@ class Dwoo
/**
* directory where the compiled templates are stored
*
* defaults to DWOO_COMPILEDIR (= DWOO_DIRECTORY/compiled by default)
* defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default)
*
* @var string
*/
......@@ -143,7 +122,7 @@ class Dwoo
/**
* directory where the cached templates are stored
*
* defaults to DWOO_CACHEDIR (= DWOO_DIRECTORY/cache by default)
* defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default)
*
* @var string
*/
......@@ -286,13 +265,13 @@ class Dwoo
public function __construct($compileDir = null, $cacheDir = null)
{
if ($cacheDir === null) {
$this->cacheDir = DWOO_DIRECTORY.'cache'.DIRECTORY_SEPARATOR;
$this->cacheDir = dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
} else {
$this->cacheDir = $cacheDir.DIRECTORY_SEPARATOR;
}
if ($compileDir === null) {
$this->compileDir = DWOO_DIRECTORY.'compiled'.DIRECTORY_SEPARATOR;
$this->compileDir = dirname(__FILE__).DIRECTORY_SEPARATOR.'compiled'.DIRECTORY_SEPARATOR;
} else {
$this->compileDir = $compileDir.DIRECTORY_SEPARATOR;
}
......
<?php
include 'Dwoo/Compilation/Exception.php';
include dirname(__FILE__) . '/Compilation/Exception.php';
/**
* default dwoo compiler class, compiles dwoo templates into php
......
......@@ -45,22 +45,19 @@ class Dwoo_Loader implements Dwoo_ILoader
*/
protected $cacheDir;
/**
* legacy/transitional var for BC with old classpath.cache files, do NOT rely on it
*
* will be deleted sooner or later
*
* TODO remove this and compat code in addDirectory
*/
public static $classpath = array();
protected $corePluginDir;
public function __construct($cacheDir)
{
$this->corePluginDir = DWOO_DIRECTORY . 'plugins';
$this->cacheDir = $cacheDir . DIRECTORY_SEPARATOR;
// include class paths or rebuild paths if the cache file isn't there
if ((file_exists($this->cacheDir.'classpath.cache.php') && include $this->cacheDir.'classpath.cache.php') == false) {
$this->rebuildClassPathCache(DWOO_DIRECTORY.'plugins', $this->cacheDir.'classpath.cache.php');
$foo = @file_get_contents($this->cacheDir.'classpath.cache.php');
if ($foo) {
$this->classPath = unserialize($foo) + $this->classPath;
} else {
$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir.'classpath.cache.php');
}
}
......@@ -91,7 +88,7 @@ class Dwoo_Loader implements Dwoo_ILoader
// save in file if it's the first call (not recursed)
if ($cacheFile!==false) {
if (!file_put_contents($cacheFile, '<?php $this->classPath = '.var_export($this->classPath, true).' + $this->classPath;')) {
if (!file_put_contents($cacheFile, serialize($this->classPath))) {
throw new Dwoo_Exception('Could not write into '.$cacheFile.', either because the folder is not there (create it) or because of the chmod configuration (please ensure this directory is writable by php), alternatively you can change the directory used with $dwoo->setCompileDir() or provide a custom loader object with $dwoo->setLoader()');
}
$this->classPath += $tmp;
......@@ -107,9 +104,9 @@ class Dwoo_Loader implements Dwoo_ILoader
public function loadPlugin($class, $forceRehash = true)
{
// a new class was added or the include failed so we rebuild the cache
if (!isset($this->classPath[$class]) || !include $this->classPath[$class]) {
if (!isset($this->classPath[$class]) || !(include $this->classPath[$class])) {
if ($forceRehash) {
$this->rebuildClassPathCache(DWOO_DIRECTORY . 'plugins', $this->cacheDir . 'classpath.cache.php');
$this->rebuildClassPathCache($this->corePluginDir, $this->cacheDir . 'classpath.cache.php');
foreach ($this->paths as $path=>$file) {
$this->rebuildClassPathCache($path, $file);
}
......@@ -142,17 +139,11 @@ class Dwoo_Loader implements Dwoo_ILoader
if (!$pluginDir) {
throw new Dwoo_Exception('Plugin directory does not exist or can not be read : '.$pluginDirectory);
}
$cacheFile = $this->cacheDir . 'classpath-'.substr(strtr($pluginDir, ':/\\.', '----'), strlen($pluginDir) > 80 ? -80 : 0).'.cache.php';
$cacheFile = $this->cacheDir . 'classpath-'.substr(strtr($pluginDir, '/\\', '--'), strlen($pluginDir) > 80 ? -80 : 0).'.d'.Dwoo::RELEASE_TAG.'.php';
$this->paths[$pluginDir] = $cacheFile;
if (file_exists($cacheFile)) {
include $cacheFile;
// BC code, will be removed
if (!empty(Dwoo_Loader::$classpath)) {
$this->classPath = Dwoo_Loader::$classpath + $this->classPath;
Dwoo_Loader::$classpath = array();
$this->rebuildClassPathCache($pluginDir, $cacheFile);
}
// end
$foo = @file_get_contents($cacheFile);
if ($foo) {
$this->classPath = unserialize($foo) + $this->classPath;
} else {
$this->rebuildClassPathCache($pluginDir, $cacheFile);
}
......
......@@ -129,7 +129,7 @@ class Dwoo_Template_File extends Dwoo_Template_String
if ($compiler === null || $compiler === array('Dwoo_Compiler', 'compilerFactory')) {
if (class_exists('Dwoo_Compiler', false) === false) {
include 'Dwoo/Compiler.php';
include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
}
$compiler = Dwoo_Compiler::compilerFactory();
} else {
......@@ -143,7 +143,9 @@ class Dwoo_Template_File extends Dwoo_Template_String
$compiler->setSecurityPolicy($dwoo->getSecurityPolicy());
$this->makeDirectory(dirname($compiledFile));
file_put_contents($compiledFile, $compiler->compile($dwoo, $this));
chmod($compiledFile, DWOO_CHMOD);
if ($this->chmod !== null) {
chmod($compiledFile, $this->chmod);
}
self::$cache['compiled'][$this->compileId] = true;
}
......
......@@ -81,6 +81,15 @@ class Dwoo_Template_String implements Dwoo_ITemplate
protected $compiler;
/**
* chmod value for all files written (cached or compiled ones)
*
* set to null if you don't want any chmod operation to happen
*
* @var int
*/
protected $chmod = 0777;
/**
* creates a template from a string
*
* @param string $templateString the template to use
......@@ -140,6 +149,30 @@ class Dwoo_Template_String implements Dwoo_ITemplate
}
/**
* returns the chmod value for all files written (cached or compiled ones)
*
* defaults to 0777
*
* @return int|null
*/
public function getChmod()
{
return $this->chmod;
}
/**
* set the chmod value for all files written (cached or compiled ones)
*
* set to null if you don't want to do any chmod() operation
*
* @param int $mask new bitmask to use for all files
*/
public function setChmod($mask = null)
{
$this->chmod = $mask;
}
/**
* returns the template name
*
* @return string
......@@ -277,7 +310,9 @@ class Dwoo_Template_String implements Dwoo_ITemplate
@rename($temp, $cachedFile);
}
chmod($cachedFile, DWOO_CHMOD);
if ($this->chmod !== null) {
chmod($cachedFile, $this->chmod);
}
self::$cache['cached'][$this->cacheId] = true;
......@@ -323,7 +358,7 @@ class Dwoo_Template_String implements Dwoo_ITemplate
if ($compiler === null || $compiler === array('Dwoo_Compiler', 'compilerFactory')) {
if (class_exists('Dwoo_Compiler', false) === false) {
include 'Dwoo/Compiler.php';
include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
}
$compiler = Dwoo_Compiler::compilerFactory();
} else {
......@@ -337,7 +372,9 @@ class Dwoo_Template_String implements Dwoo_ITemplate
$compiler->setSecurityPolicy($dwoo->getSecurityPolicy());
$this->makeDirectory(dirname($compiledFile));
file_put_contents($compiledFile, $compiler->compile($dwoo, $this));
chmod($compiledFile, DWOO_CHMOD);
if ($this->chmod !== null) {
chmod($compiledFile, $this->chmod);
}
self::$cache['compiled'][$this->compileId] = true;
}
......@@ -420,6 +457,10 @@ class Dwoo_Template_String implements Dwoo_ITemplate
return;
}
mkdir($path, DWOO_CHMOD, true);
if ($this->chmod !== null) {
mkdir($path, $this->chmod, true);
} else {
mkdir($path, 0777, true);
}
}
}
<?php
function dwooAutoload($class)
{
if (substr($class, 0, 5) === 'Dwoo_') {
include strtr($class, '_', DIRECTORY_SEPARATOR).'.php';
}
}
spl_autoload_register('dwooAutoload');
set_include_path(str_replace(PATH_SEPARATOR.dirname(__FILE__), '', get_include_path()) . PATH_SEPARATOR . dirname(__FILE__));
include 'Dwoo.php';
\ No newline at end of file
......@@ -6,7 +6,7 @@ if (!ini_get('date.timezone'))
define('DWOO_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR.'cache');
define('DWOO_COMPILE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR.'compiled');
require dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'Dwoo.php';
require dirname(dirname(__FILE__)) . '/lib/dwooAutoload.php';
define('TEST_DIRECTORY', dirname(__FILE__));
class DwooTests extends PHPUnit_Framework_TestSuite {
......
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