-<?xml version='1.0' encoding='UTF-8'?>
+<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<project>
<actions/>
<description>%4$s</description>
-<?xml version="1.0" encoding="UTF-8"?>
+<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
*/
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
+++ /dev/null
-<?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
+++ /dev/null
-<?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
*/
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
<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" />
);
}
- /**
- * @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();
-%1$s : %2$s
+<?php
+
+echo "${1} : ${2}\n";