Switch to PHP templates only.
authorGunnar Wrobel <p@rdus.de>
Fri, 14 Jan 2011 15:09:45 +0000 (16:09 +0100)
committerGunnar Wrobel <p@rdus.de>
Fri, 14 Jan 2011 15:09:45 +0000 (16:09 +0100)
components/data/hudson-component-config.xml.template
components/data/hudson-component-phpunit.xml.template
components/lib/Components/Helper/Template.php
components/lib/Components/Helper/Template/Php.php [deleted file]
components/lib/Components/Helper/Template/Printf.php [deleted file]
components/lib/Components/Helper/Templates.php
components/package.xml
components/test/Components/Unit/Components/Helper/TemplatesTest.php
components/test/Components/fixture/templates/variables.template

index e641191..805f888 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
+<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
 <project>
   <actions/>
   <description>%4$s</description>
index 5a7fa06..3cad015 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
 
 <phpunit backupGlobals="false"
          backupStaticAttributes="false"
index 7c0e120..0974848 100644 (file)
@@ -62,21 +62,13 @@ class Components_Helper_Template
      */
     public function write(array $parameters = array())
     {
-        throw new Horde_Component_Exception('Overwrite in the extending class!');
-    }
-
-    /**
-     * A factory for the specific template type.
-     */
-    static public function factory($source, $target)
-    {
-        $sh = fopen($source, 'r');
-        $lead = fread($sh, 5);
-        fclose($sh);
-        if ($lead == '<?php') {
-            return new Components_Helper_Template_Php($source, $target);
-        } else {
-            return new Components_Helper_Template_Printf($source, $target);
+        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/Php.php b/components/lib/Components/Helper/Template/Php.php
deleted file mode 100644 (file)
index 611239f..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-/**
- * Components_Helper_Template_Php:: converts a PHP template into a target file.
- *
- * PHP version 5
- *
- * @category Horde
- * @package  Components
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @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 <wrobel@pardus.de>
- * @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 (file)
index 3103392..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * Components_Helper_Template_Printf:: converts a template into a target file using vsprintf().
- *
- * PHP version 5
- *
- * @category Horde
- * @package  Components
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @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 <wrobel@pardus.de>
- * @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
index 842d11f..bad702c 100644 (file)
@@ -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
index 6c522c4..c9fe01d 100644 (file)
@@ -25,7 +25,7 @@
   <active>yes</active>
  </lead>
  <date>2011-01-14</date>
- <time>15:22:29</time>
+ <time>16:08:10</time>
  <version>
   <release>0.0.1</release>
   <api>0.0.1</api>
       <file name="Pear.php" role="php" />
      </dir> <!-- /lib/Components/Exception -->
      <dir name="Helper">
-      <dir name="Template">
-       <file name="Php.php" role="php" />
-       <file name="Printf.php" role="php" />
-      </dir> <!-- /lib/Components/Helper/Template -->
       <dir name="Templates">
        <file name="Directory.php" role="php" />
        <file name="Single.php" role="php" />
    <install as="Components/Helper/Template.php" name="lib/Components/Helper/Template.php" />
    <install as="Components/Helper/Templates.php" name="lib/Components/Helper/Templates.php" />
    <install as="Components/Helper/Tree.php" name="lib/Components/Helper/Tree.php" />
-   <install as="Components/Helper/Template/Php.php" name="lib/Components/Helper/Template/Php.php" />
-   <install as="Components/Helper/Template/Printf.php" name="lib/Components/Helper/Template/Printf.php" />
    <install as="Components/Helper/Templates/Directory.php" name="lib/Components/Helper/Templates/Directory.php" />
    <install as="Components/Helper/Templates/Single.php" name="lib/Components/Helper/Templates/Single.php" />
    <install as="Components/Module/Base.php" name="lib/Components/Module/Base.php" />
index 769ef8b..d41022e 100644 (file)
@@ -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();