From ddb7e9a4a44d94e5b2561d964329edd43ec5eaf3 Mon Sep 17 00:00:00 2001
From: Gunnar Wrobel
Date: Fri, 14 Jan 2011 16:09:45 +0100
Subject: [PATCH] Switch to PHP templates only.
---
.../data/hudson-component-config.xml.template | 2 +-
.../data/hudson-component-phpunit.xml.template | 2 +-
components/lib/Components/Helper/Template.php | 22 +++------
components/lib/Components/Helper/Template/Php.php | 49 -------------------
.../lib/Components/Helper/Template/Printf.php | 57 ----------------------
components/lib/Components/Helper/Templates.php | 4 +-
components/package.xml | 8 +--
.../Unit/Components/Helper/TemplatesTest.php | 15 ------
.../fixture/templates/variables.template | 4 +-
9 files changed, 15 insertions(+), 148 deletions(-)
delete mode 100644 components/lib/Components/Helper/Template/Php.php
delete mode 100644 components/lib/Components/Helper/Template/Printf.php
diff --git a/components/data/hudson-component-config.xml.template b/components/data/hudson-component-config.xml.template
index e64119100..805f88817 100644
--- a/components/data/hudson-component-config.xml.template
+++ b/components/data/hudson-component-config.xml.template
@@ -1,4 +1,4 @@
-
+'; ?>
%4$s
diff --git a/components/data/hudson-component-phpunit.xml.template b/components/data/hudson-component-phpunit.xml.template
index 5a7fa0655..3cad015e5 100644
--- a/components/data/hudson-component-phpunit.xml.template
+++ b/components/data/hudson-component-phpunit.xml.template
@@ -1,4 +1,4 @@
-
+'; ?>
$value) {
+ ${$key} = $value;
}
+ $tdir = dirname($this->_target);
+ $target = basename($this->_target);
+ ob_start();
+ include $this->_source;
+ file_put_contents($tdir . DIRECTORY_SEPARATOR . $target, ob_get_clean());
}
}
\ No newline at end of file
diff --git a/components/lib/Components/Helper/Template/Php.php b/components/lib/Components/Helper/Template/Php.php
deleted file mode 100644
index 611239fda..000000000
--- a/components/lib/Components/Helper/Template/Php.php
+++ /dev/null
@@ -1,49 +0,0 @@
-
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Components
- */
-
-/**
- * Components_Helper_Template_Php:: converts a PHP template into a target file.
- *
- * Copyright 2011 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Horde
- * @package Components
- * @author Gunnar Wrobel
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Components
- */
-class Components_Helper_Template_Php
-extends Components_Helper_Template
-{
- /**
- * Rewrite the template from the source to the target location.
- *
- * @param array $parameters The template parameters.
- *
- * @return NULL
- */
- public function write(array $parameters = array())
- {
- foreach ($parameters as $key => $value) {
- ${$key} = $value;
- }
- $tdir = dirname($this->_target);
- $target = basename($this->_target);
- ob_start();
- include $this->_source;
- file_put_contents($tdir . DIRECTORY_SEPARATOR . $target, ob_get_clean());
- }
-}
\ No newline at end of file
diff --git a/components/lib/Components/Helper/Template/Printf.php b/components/lib/Components/Helper/Template/Printf.php
deleted file mode 100644
index 3103392d3..000000000
--- a/components/lib/Components/Helper/Template/Printf.php
+++ /dev/null
@@ -1,57 +0,0 @@
-
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Components
- */
-
-/**
- * Components_Helper_Template_Printf:: converts a template into a target file using vsprintf().
- *
- * Copyright 2011 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Horde
- * @package Components
- * @author Gunnar Wrobel
- * @license http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link http://pear.horde.org/index.php?package=Components
- */
-class Components_Helper_Template_Printf
-extends Components_Helper_Template
-{
- /**
- * Rewrite the template from the source to the target location.
- *
- * @param array $parameters The template parameters.
- *
- * @return NULL
- */
- public function write(array $parameters = array())
- {
- foreach ($parameters as $key => $value) {
- if (!is_string($value)) {
- throw new Components_Exception(
- sprintf(
- 'File %s is a printf() based template and requires string input only. Key "%s" however is of type %s!',
- $this->_source,
- $key,
- gettype($value)
- )
- );
- }
- }
- $source = file_get_contents($this->_source);
- file_put_contents(
- $this->_target, vsprintf($source, $parameters)
- );
- }
-}
\ No newline at end of file
diff --git a/components/lib/Components/Helper/Templates.php b/components/lib/Components/Helper/Templates.php
index 842d11f4e..bad702c2d 100644
--- a/components/lib/Components/Helper/Templates.php
+++ b/components/lib/Components/Helper/Templates.php
@@ -38,7 +38,7 @@ abstract class Components_Helper_Templates
*/
protected function writeSourceToTarget($source, $target, array $parameters = array())
{
- $template = Components_Helper_Template::factory($source, $target)
- ->write($parameters);
+ $template = new Components_Helper_Template($source, $target);
+ $template->write($parameters);
}
}
\ No newline at end of file
diff --git a/components/package.xml b/components/package.xml
index 6c522c4c0..c9fe01dca 100644
--- a/components/package.xml
+++ b/components/package.xml
@@ -25,7 +25,7 @@
yes
2011-01-14
-
+
0.0.1
0.0.1
@@ -72,10 +72,6 @@
-
-
-
-
@@ -350,8 +346,6 @@
-
-
diff --git a/components/test/Components/Unit/Components/Helper/TemplatesTest.php b/components/test/Components/Unit/Components/Helper/TemplatesTest.php
index 769ef8b80..d41022e98 100644
--- a/components/test/Components/Unit/Components/Helper/TemplatesTest.php
+++ b/components/test/Components/Unit/Components/Helper/TemplatesTest.php
@@ -89,21 +89,6 @@ extends Components_TestCase
);
}
- /**
- * @expectedException Components_Exception
- */
- public function testNoStringInput()
- {
- $tdir = $this->getTemporaryDirectory();
- $templates = new Components_Helper_Templates_Single(
- dirname(__FILE__) . '/../../../fixture/templates',
- $tdir,
- 'variables',
- 'target'
- );
- $templates->write(array('1' => new stdClass, '2' => 'Two'));
- }
-
public function testPhp()
{
$tdir = $this->getTemporaryDirectory();
diff --git a/components/test/Components/fixture/templates/variables.template b/components/test/Components/fixture/templates/variables.template
index 948737199..38aecf18d 100644
--- a/components/test/Components/fixture/templates/variables.template
+++ b/components/test/Components/fixture/templates/variables.template
@@ -1 +1,3 @@
-%1$s : %2$s
+