Exemple #1
0
 /**
  * Evaluates a template file.
  *
  * @param string The template file path
  *
  * @return string The evaluated template
  */
 protected function evalTemplate($templateFile)
 {
     $templateFile = sfLoader::getGeneratorTemplate($this->getGeneratorClass(), $this->getTheme(), $templateFile);
     // eval template file
     ob_start();
     require $templateFile;
     $content = ob_get_clean();
     // replace [?php and ?]
     $content = $this->replacePhpMarks($content);
     $retval = "<?php\n" . "// auto-generated by " . $this->getGeneratorClass() . "\n" . "// date: %s\n?>\n%s";
     $retval = sprintf($retval, date('Y/m/d H:i:s'), $content);
     return $retval;
 }
 /**
  * Generates classes and templates in cache.
  *
  * @param array The parameters
  *
  * @return string The data to put in configuration cache
  */
 public function generate($params = array())
 {
     $this->params = $params;
     $required_parameters = array('model_class', 'moduleName');
     foreach ($required_parameters as $entry) {
         if (!isset($this->params[$entry])) {
             $error = 'You must specify a "%s"';
             $error = sprintf($error, $entry);
             throw new sfParseException($error);
         }
     }
     $modelClass = $this->params['model_class'];
     if (!class_exists($modelClass)) {
         $error = 'Unable to scaffold unexistant model "%s"';
         $error = sprintf($error, $modelClass);
         throw new sfInitializationException($error);
     }
     $this->setScaffoldingClassName($modelClass);
     // generated module name
     $this->setGeneratedModuleName('auto' . ucfirst($this->params['moduleName']));
     $this->setModuleName($this->params['moduleName']);
     // get some model metadata
     $this->loadMapBuilderClasses();
     // load all primary keys
     $this->loadPrimaryKeys();
     // theme exists?
     $theme = isset($this->params['theme']) ? $this->params['theme'] : 'default';
     $themeDir = sfLoader::getGeneratorTemplate($this->getGeneratorClass(), $theme, '');
     if (!is_dir($themeDir)) {
         $error = 'The theme "%s" does not exist.';
         $error = sprintf($error, $theme);
         throw new sfConfigurationException($error);
     }
     $this->setTheme($theme);
     $templateFiles = sfFinder::type('file')->ignore_version_control()->name('*.php')->relative()->in($themeDir . '/templates');
     $configFiles = sfFinder::type('file')->ignore_version_control()->name('*.yml')->relative()->in($themeDir . '/config');
     $this->generatePhpFiles($this->generatedModuleName, $templateFiles, $configFiles);
     // require generated action class
     $data = "require_once(sfConfig::get('sf_module_cache_dir').'/" . $this->generatedModuleName . "/actions/actions.class.php');\n";
     return $data;
 }