示例#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();
 }
示例#2
0
 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);
     }
 }
示例#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;
}
示例#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);
     }
 }
示例#6
0
<?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);
 }
示例#8
0
文件: fetch.php 项目: bmdevel/ezc
 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];
 }
示例#9
0
 public function testCompileOnly()
 {
     file_put_contents($this->templatePath . "/test.ezt", '{use $myVar}{$myVar}');
     $tc = ezcTemplateConfiguration::getInstance();
     $tc->executeTemplate = false;
     self::assertEquals(0, count(glob($tc->compilePath . "/compiled_templates/xhtml-*/*.php")));
     $template = new ezcTemplate();
     $out = $template->process("test.ezt");
     // Should work, because we compile the template only.
     $template->process("test.ezt");
     self::assertEquals(1, count(glob($tc->compilePath . "/compiled_templates/xhtml-*/*.php")));
 }
示例#10
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";
}
示例#12
0
 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');
 }
示例#13
0
 public function stopCaching()
 {
     ezcSignalStaticConnections::getInstance()->disconnect("UserBla", "ezcTemplateCacheRead", array(ezcTemplateConfiguration::getInstance()->cacheManager, "register"));
     $this->depth--;
     array_pop($this->keys);
 }