Exemple #1
0
 protected function setUp()
 {
     $this->basePath = $this->createTempDir("ezcTemplate_");
     $this->templatePath = $this->basePath . "/templates";
     $this->compilePath = $this->basePath . "/compiled";
     mkdir($this->templatePath);
     mkdir($this->compilePath);
     $config = ezcTemplateConfiguration::getInstance();
     $config->templatePath = $this->templatePath;
     $config->compilePath = $this->compilePath;
     $config->context = new ezcTemplateNoContext();
 }
 protected function setUp()
 {
     try {
         $this->setLocale(LC_ALL, 'de_DE', 'de_DE.UTF-8', 'deu', 'german');
     } catch (PHPUnit_Framework_Exception $e) {
         $this->markTestSkipped('System does not support setting locale to de_DE.UTF-8.');
     }
     $this->basePath = $this->createTempDir("ezcTemplate_");
     $this->templatePath = $this->basePath . "/templates";
     $this->compilePath = $this->basePath . "/compiled";
     mkdir($this->templatePath);
     mkdir($this->compilePath);
     $config = ezcTemplateConfiguration::getInstance();
     $config->templatePath = $this->templatePath;
     $config->compilePath = $this->compilePath;
     $config->context = new ezcTemplateNoContext();
 }
 /**
  * Writes the given $schema to $dir using $template.
  *
  * Iterates through all tables in $schema, sends each of them to a {@link
  * ezcTemplate} with $template and writes the result to $dir with the file
  * name returned by the template.
  * 
  * @param ezcDbSchema $schema 
  * @param string $template
  * @param mixed $dir 
  */
 public function write(ezcDbSchema $schema, $template, $dir)
 {
     $tplConf = ezcTemplateConfiguration::getInstance();
     $tplConf->templatePath = $this->properties['options']->templatePath;
     $tplConf->compilePath = $this->properties['options']->templateCompilePath;
     $tpl = new ezcTemplate();
     $tpl->send->classPrefix = $this->properties['options']->classPrefix;
     foreach ($schema->getSchema() as $tableName => $tableSchema) {
         $tpl->send->schema = $tableSchema;
         $tpl->send->tableName = $tableName;
         $content = $tpl->process($template);
         $fileName = $dir . '/' . $tpl->receive->fileName;
         if (!$this->properties['options']->overwrite && file_exists($fileName)) {
             throw new ezcPersistentObjectSchemaOverwriteException($fileName);
         }
         file_put_contents($fileName, $content);
     }
 }
Exemple #4
0
function getBody($example, $form)
{
    $c = ezcTemplateConfiguration::getInstance();
    $c->templatePath = dirname(__FILE__) . "/dir";
    $c->compilePath = "/tmp";
    $t = new ezcTemplate();
    $t->send->form = $form;
    $t->process($example . '.ezt');
    return $t->output;
}
Exemple #5
0
 /**
  * Returns the value of the property $name.
  *
  * @throws ezcBasePropertyNotFoundException if the property does not exist.
  * @param string $name
  * @return mixed
  * @ignore
  */
 public function __get($name)
 {
     switch ($name) {
         case 'send':
         case 'receive':
         case 'tstTree':
         case 'astTree':
         case 'stream':
         case 'streamStack':
         case 'compiledTemplatePath':
         case 'usedConfiguration':
         case 'output':
             return $this->properties[$name];
         case 'configuration':
             if ($this->properties[$name] === null) {
                 $this->properties[$name] = ezcTemplateConfiguration::getInstance();
                 if (get_class($this->properties[$name]) != 'ezcTemplateConfiguration') {
                     throw new ezcTemplateInternalException("Static method ezcTemplateConfiguration::getInstance() did not return an object of class ezcTemplateConfiguration");
                 }
             }
             return $this->properties[$name];
         default:
             throw new ezcBasePropertyNotFoundException($name);
     }
 }
 /**
  * Grab a cleaned up ezctemplate instance.
  *
  * @return     ezcTemplate A ezcTemplate instance.
  *
  * @author     Felix Weis <*****@*****.**>
  * @since      0.11.0
  */
 protected function getEngine()
 {
     // ezcTemplate already initialized, only clear the assigns and retun the engine
     if ($this->ezcTemplate) {
         $this->ezcTemplate->send = new ezcTemplateVariableCollection();
         return $this->ezcTemplate;
     }
     $this->ezcTemplate = $this->createEngineInstance();
     // initialize ezcTemplate
     $parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
     $compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
     AgaviToolkit::mkdir($compileDir, $parentMode, true);
     // templatePath unnessesary because Agavi will always supply the absolute ressource path
     $config = new ezcTemplateConfiguration();
     $config->templatePath = "";
     $config->compilePath = $compileDir;
     // set the ezcTemplateOutputContext (standard is ezcTemplateXhtmlContext)
     if ($this->hasParameter('context')) {
         $contextClass = $this->getParameter('context');
         $config->context = new $contextClass();
     }
     // add some usefull Agavi Functions/Blocks as Extension
     $config->addExtension('AgaviEzctemplateCustomBlocks');
     $config->addExtension('AgaviEzctemplateCustomFunctions');
     foreach ($this->getParameter('extensions', array()) as $extension) {
         $config->addExtension($extension);
     }
     $this->ezcTemplate->configuration = $config;
     return $this->ezcTemplate;
 }
<?php

// Autoload.
require_once 'tutorial_autoload.php';
$config = ezcTemplateConfiguration::getInstance();
$config->templatePath = "/usr/share/templates";
$config->compilePath = "/tmp/compiled_templates";
$config->context = new ezcTemplateXhtmlContext();
// Is already the default, though.
$t = new ezcTemplate();
$t->process("hello_world.ezt");
 public function testCacheBlock()
 {
     $t = new ezcTemplate();
     $t->configuration->addExtension("Fetch");
     $r = $t->process("show_users_cache_block.ezt");
     $this->assertEquals("\n\n\n\n1 Raymond sunRay\n\n2 Derick Tiger\n\n3 Jan Amos\n", $r);
     // Update a single user.
     $db = ezcDbInstance::get();
     $db->exec('UPDATE user SET nickname="bla" WHERE id=1');
     // Still cached.
     $r = $t->process("show_users_cache_block.ezt");
     $this->assertEquals("\n\n\n\n1 Raymond sunRay\n\n2 Derick Tiger\n\n3 Jan Amos\n", $r);
     // Send a update signal to the configuration manager.
     ezcTemplateConfiguration::getInstance()->cacheManager->update("user", 1);
     $r = $t->process("show_users_cache_block.ezt");
     $this->assertEquals("\n\n\n\n1 Raymond bla\n\n2 Derick Tiger\n\n3 Jan Amos\n", $r);
 }
Exemple #9
0
 protected function renderViewTemplate($controller)
 {
     $debug = ezcDebug::getInstance();
     $tplConfig = new ezcTemplateConfiguration(SITE_ROOT . "/app", SITE_ROOT . "/tmp");
     $tplConfig->addExtension("CustomDate");
     $tplConfig->addExtension("CustomMath");
     $tplConfig->addExtension("MoneyFormat");
     $tplConfig->addExtension("UrlCreator");
     $tplConfig->disableCache = true;
     $tplConfig->checkModifiedTemplates = true;
     $tpl = new ezcTemplate();
     $tpl->configuration = $tplConfig;
     $send = new ezcTemplateVariableCollection($controller->vars);
     $tpl->send = $send;
     $receive = $tpl->receive;
     //var_dump($controller->vars);
     $result = $tpl->process($controller->templateFile . '.ezt');
     //echo $result;
     $merged = array_merge($send->getVariableArray(), $receive->getVariableArray(), array('result' => $result));
     $layoutTpl = new ezcTemplate();
     $layoutTpl->configuration = $tplConfig;
     $layoutTpl->send = new ezcTemplateVariableCollection($merged);
     $path = 'layouts/' . $controller->layout . '.ezt';
     echo $layoutTpl->process($path);
     //$output = $debug->generateOutput();
     //echo $output;
 }
Exemple #10
0
 public static function user($id)
 {
     $db = ezcDbInstance::get();
     $s = $db->createSelectQuery();
     $s->select("*")->from("user")->where($s->expr->eq("id", $id));
     $statement = $s->prepare();
     $statement->execute();
     $res = $statement->fetchAll();
     // Execute only when we are creating the template.
     foreach ($res as $a) {
         ezcTemplateConfiguration::getInstance()->cacheManager->read("user", $a["id"]);
     }
     ////////////
     return $res[0];
 }
 public function testAddExtensionTestWrong3()
 {
     $c = new ezcTemplateConfiguration();
     try {
         $c->addExtension('ezcTemplateConfiguration');
         self::fail("Expected exception was not thrown");
     } catch (ezcBaseValueException $e) {
         self::assertEquals("The value 'ezcTemplateConfiguration' that you were trying to assign to argument 'customClass' is invalid. Allowed values are: string with classname that implements the ezcTemplateCustomBlock or ezcTemplateCustomFunction interface.", $e->getMessage());
     }
 }
Exemple #12
0
    public function testChangeTemplateThenRenewCache()
    {
        $t = new ezcTemplate();
        $t->send->name = "Bernard";
        $config = ezcTemplateConfiguration::getInstance();
        $config->templatePath = $this->tempDir;
        file_put_contents($config->templatePath . DIRECTORY_SEPARATOR . "blarp.tpl", '
{use $name}
{cache_template}
[{$name}]
');
        $out = $t->process("blarp.tpl");
        $this->assertEquals("\n[Bernard]\n", $out);
        // Retry, the old name should be in the cached template.
        $t->send->name = "Guybrush";
        $out = $t->process("blarp.tpl");
        $this->assertEquals("\n[Bernard]\n", $out);
        sleep(1);
        // Make sure that the mtime is changed.
        // Update the contents
        file_put_contents($this->tempDir . DIRECTORY_SEPARATOR . "blarp.tpl", '
{use $name}
{cache_template}
[[[[[[{$name}]]]]]]
');
        $t->send->name = "Guybrush";
        $out = $t->process("blarp.tpl");
        $this->assertEquals("\n[[[[[[Guybrush]]]]]]\n", $out);
    }
$t = new ezcTemplate();
// Set the template configuration for printer templates.
$c = ezcTemplateConfiguration::getInstance("printer");
$c->templatePath = "printer";
// ./printer directory;
$c->context = new ezcTemplateNoContext();
// Use a context that doesn't do anything.
$c = ezcTemplateConfiguration::getInstance();
$c->templatePath = "html";
// ./html directory.
// And another way to configure your template engine.
$pdfConf = new ezcTemplateConfiguration("pdf", ".", new ezcTemplateNoContext());
try {
    // Uses the default configuration.
    $t->process("hello_world.ezt");
} catch (Exception $e) {
    echo $e->getMessage() . "\n\n";
}
try {
    // Uses the printer configuration
    $t->process("hello_world.ezt", ezcTemplateConfiguration::getInstance("printer"));
} catch (Exception $e) {
    echo $e->getMessage() . "\n\n";
}
try {
    // Uses the PDF configuration.
    $t->configuration = $pdfConf;
    $t->process("hello_world.ezt");
} catch (Exception $e) {
    echo $e->getMessage() . "\n\n";
}
 public function getPath()
 {
     $tested = array();
     $tc = ezcTemplateConfiguration::getInstance();
     $userPath = $tc->templatePath;
     // check $tc->templatePath/$request->host.
     if ($this->requestHost) {
         $testPath = join(DIRECTORY_SEPARATOR, array($userPath, $this->requestHost, $this->templateName));
         if (file_exists($testPath)) {
             return $testPath;
         }
         $tested[] = $testPath;
     }
     // check $tc->templatePath/
     $testPath = join(DIRECTORY_SEPARATOR, array($userPath, $this->templateName));
     if (file_exists($testPath)) {
         return $testPath;
     }
     $tested[] = $testPath;
     // check self::$paths
     foreach (self::$paths as $path) {
         $testPath = join(DIRECTORY_SEPARATOR, array($path, $this->templateName));
         if (file_exists($testPath)) {
             return $testPath;
         }
         $tested[] = $testPath;
     }
     var_dump($tested);
     throw new Exception('Could not locate template');
 }
Exemple #15
0
 public function stopCaching()
 {
     ezcSignalStaticConnections::getInstance()->disconnect("UserBla", "ezcTemplateCacheRead", array(ezcTemplateConfiguration::getInstance()->cacheManager, "register"));
     $this->depth--;
     array_pop($this->keys);
 }