Permalink
Browse files

Added cache option to model:build

  • Loading branch information...
1 parent 00fc6e9 commit 8d4023fca537958cbc0523c0d9606b4c688e2888 @mpscholten committed Oct 13, 2013
@@ -63,21 +63,20 @@
public function __construct(Table $table)
{
parent::__construct($table);
- $this->twig = $this->createTwig();
}
- protected function initTwig()
+ protected function createTwig()
{
$loader = new \Twig_Loader_Filesystem(__DIR__ . '/templates/');
$twig = new \Twig_Environment($loader, [
'autoescape' => false,
'strict_variables' => true,
- 'cache' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'propel2-cache',
+ 'cache' => $this->getGeneratorConfig()->getBuildProperty('builderCachePath'),
'auto_reload' => true
]);
$twig->addExtension(new PropelTwigExtension());
- foreach ($table->getBehaviors() as $behavior) {
+ foreach ($this->getTable()->getBehaviors() as $behavior) {
$path = $behavior->getTemplateDirectory();
if ($path !== null) {
$loader->prependPath($behavior->getTemplateDirectory(), $behavior->getTemplateNamespace());
@@ -87,6 +86,14 @@ protected function initTwig()
return $twig;
}
+ public function getTwig()
+ {
+ if($this->twig === null) {
+ $this->twig = $this->createTwig(); // Create twig only when we need it
+ }
+ return $this->twig;
+ }
+
/**
* Builds the PHP source for current class and returns it as a string.
@@ -80,6 +80,9 @@ protected function configure()
'')
->addOption('disable-namespace-auto-package', null, InputOption::VALUE_NONE,
'Disable namespace auto-packaging')
+ ->addOption('cache-path', null, InputOption::VALUE_OPTIONAL,
+ 'The path which to use as a cache', sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'propel2')
+ ->addOption('disable-cache', null, InputOption::VALUE_OPTIONAL, 'Disable cache', false)
->setName('model:build')
->setAliases(array('build'))
->setDescription('Build the model classes based on Propel XML schemas')
@@ -91,6 +94,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $cachePath = $input->getOption('disable-cache') ? null : $input->getOption('cache-path');
$generatorConfig = $this->getGeneratorConfig(array(
'propel.platform.class' => $input->getOption('platform'),
'propel.builder.object.class' => $input->getOption('object-class'),
@@ -102,6 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.builder.queryinheritancestub.class' => $input->getOption('query-inheritance-stub-class'),
'propel.builder.tablemap.class' => $input->getOption('tablemap-class'),
'propel.builder.pluralizer.class' => $input->getOption('pluralizer-class'),
+ 'propel.builder.cachePath' => $cachePath,
'propel.disableIdentifierQuoting' => !$input->getOption('enable-identifier-quoting'),
'propel.targetPackage' => $input->getOption('target-package'),
'propel.packageObjectModel' => $input->getOption('enable-package-object-model'),
@@ -124,6 +129,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->createDirectory($input->getOption('output-dir'));
+ if($cachePath !== null) {
+ $output->writeln('Cache directory is <info>"' . $cachePath . '"</info>.');
+ } else {
+ $output->writeln('Cache is disabled.');
+ }
+
$manager = new ModelManager();
$manager->setFilesystem($this->getFilesystem());
$manager->setGeneratorConfig($generatorConfig);

0 comments on commit 8d4023f

Please sign in to comment.