Permalink
Browse files

! 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
  • Loading branch information...
1 parent 396dcf0 commit 478bf67793eb1ba6cb6bd9b600c6b72676527fbc Seldaek committed Sep 7, 2008
Showing with 121 additions and 66 deletions.
  1. +5 −1 CHANGELOG
  2. +2 −2 README
  3. +26 −1 UPGRADE_NOTES
  4. +1 −2 lib/Dwoo.compiled.php
  5. +8 −29 lib/Dwoo.php
  6. +1 −1 lib/Dwoo/Compiler.php
  7. +14 −23 lib/Dwoo/Loader.php
  8. +4 −2 lib/Dwoo/Template/File.php
  9. +45 −4 lib/Dwoo/Template/String.php
  10. +14 −0 lib/dwooAutoload.php
  11. +1 −1 tests/DwooTests.php
View
@@ -1,4 +1,7 @@
-[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
View
4 README
@@ -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');
View
@@ -1,9 +1,34 @@
-----------------------------------------------------------------------------
+-- 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
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,38 +1,17 @@
<?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;
}
View
@@ -1,6 +1,6 @@
<?php
-include 'Dwoo/Compilation/Exception.php';
+include dirname(__FILE__) . '/Compilation/Exception.php';
/**
* default dwoo compiler class, compiles dwoo templates into php
View
@@ -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 @@ protected function rebuildClassPathCache($path, $cacheFile)
// 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 @@ protected function rebuildClassPathCache($path, $cacheFile)
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 @@ public function addDirectory($pluginDirectory)
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 @@ public function getCompiledTemplate(Dwoo $dwoo, Dwoo_ICompiler $compiler = null)
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 @@ public function getCompiledTemplate(Dwoo $dwoo, Dwoo_ICompiler $compiler = null)
$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 @@ public function setCacheTime($seconds = null)
}
/**
+ * 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 @@ public function cache(Dwoo $dwoo, $output)
@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 @@ public function getCompiledTemplate(Dwoo $dwoo, Dwoo_ICompiler $compiler = null)
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 @@ public function getCompiledTemplate(Dwoo $dwoo, Dwoo_ICompiler $compiler = null)
$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 @@ protected function makeDirectory($path)
return;
}
- mkdir($path, DWOO_CHMOD, true);
+ if ($this->chmod !== null) {
+ mkdir($path, $this->chmod, true);
+ } else {
+ mkdir($path, 0777, true);
+ }
}
}
View
@@ -0,0 +1,14 @@
+<?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';
View
@@ -6,7 +6,7 @@
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 {

0 comments on commit 478bf67

Please sign in to comment.