Пример #1
0
 public function testRenderFile()
 {
     $t = new PropelTemplate();
     $t->setTemplateFile(dirname(__FILE__) . '/template.php');
     $res = $t->render(array('name' => 'John'));
     $this->assertEquals('Hello, John', $res);
 }
 /**
  * @param string $filename
  * @param array  $vars
  * @param string $templateDir
  *
  * @return string
  * @throws \Exception
  */
 public function renderTemplate($filename, $vars = array(), $templateDir = '/templates/')
 {
     $basePath = $this->getTemplateBasePath();
     $filePath = $basePath . $templateDir . $filename;
     if (!file_exists($filePath)) {
         $filePath = $filePath . '.php';
         if (!file_exists($filePath)) {
             throw new \InvalidArgumentException(sprintf('Template "%s" not found in "%s" directory', $filename, $basePath . $templateDir));
         }
     }
     $template = new PropelTemplate();
     $template->setTemplateFile($filePath);
     $vars = array_merge($vars, ['behavior' => $this]);
     return $template->render($vars);
 }
Пример #3
0
 private function generateProject(OutputInterface $output, array $options)
 {
     $schema = new PropelTemplate();
     $schema->setTemplateFile(__DIR__ . '/templates/schema.xml.php');
     $config = new PropelTemplate();
     $config->setTemplateFile(__DIR__ . '/templates/propel.' . $options['format'] . '.php');
     $distConfig = new PropelTemplate();
     $distConfig->setTemplateFile(__DIR__ . '/templates/propel.' . $options['format'] . '.dist.php');
     if (!isset($options['schema'])) {
         $options['schema'] = $schema->render($options);
     }
     $this->writeFile($output, sprintf('%s/schema.xml', $options['schemaDir']), $options['schema']);
     $this->writeFile($output, sprintf('%s/propel.%s', getcwd(), $options['format']), $config->render($options));
     $this->writeFile($output, sprintf('%s/propel.%s.dist', getcwd(), $options['format']), $distConfig->render($options));
 }