Development

/branches/1.2/lib/task/project/sfProjectFreezeTask.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/task/project/sfProjectFreezeTask.class.php

Revision 14421, 3.8 kB (checked in by Carl.Vondrick, 5 years ago)

1.2: updated sfProjectFreezeTask help text to be more verbose

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Freezes symfony libraries.
13  *
14  * @package    symfony
15  * @subpackage task
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfProjectFreezeTask extends sfBaseTask
20 {
21   /**
22    * @see sfTask
23    */
24   protected function configure()
25   {
26     $this->addArguments(array(
27       new sfCommandArgument('symfony_data_dir', sfCommandArgument::REQUIRED, 'The symfony data directory'),
28     ));
29
30     $this->aliases = array('freeze');
31     $this->namespace = 'project';
32     $this->name = 'freeze';
33     $this->briefDescription = 'Freezes symfony libraries';
34
35     $this->detailedDescription = <<<EOF
36 The [project:freeze|INFO] task copies all the symfony core files to
37 the current project:
38
39   [./symfony project:freeze /path/to/symfony/data/directory|INFO]
40
41 The task takes a mandatory argument of the path to the symfony data
42 directory.
43
44 The task also changes [config/config.php|COMMENT] to switch to the
45 embedded symfony files.
46 EOF;
47   }
48
49   /**
50    * @see sfTask
51    */
52   protected function execute($arguments = array(), $options = array())
53   {
54     // check that the symfony librairies are not already freeze for this project
55     if (is_readable(sfConfig::get('sf_lib_dir').'/symfony'))
56     {
57       throw new sfCommandException('You can only freeze when lib/symfony is empty.');
58     }
59
60     if (is_readable(sfConfig::get('sf_data_dir').'/symfony'))
61     {
62       throw new sfCommandException('You can only freeze when data/symfony is empty.');
63     }
64
65     if (is_readable(sfConfig::get('sf_web_dir').'/sf'))
66     {
67       throw new sfCommandException('You can only freeze when web/sf is empty.');
68     }
69
70     if (is_link(sfConfig::get('sf_web_dir').'/sf'))
71     {
72       $this->getFilesystem()->remove(sfConfig::get('sf_web_dir').'/sf');
73     }
74
75     $symfonyLibDir  = sfConfig::get('sf_symfony_lib_dir');
76     $symfonyDataDir = $arguments['symfony_data_dir'];
77
78     if (!is_readable($symfonyDataDir))
79     {
80       throw new sfCommandException(sprintf('The symfony data dir does not seem to be located at "%s".', $symfonyDataDir));
81     }
82
83     $this->logSection('freeze', sprintf('freezing lib found in "%s"', $symfonyLibDir));
84     $this->logSection('freeze', sprintf('freezing data found in "%s"', $symfonyDataDir));
85
86     $this->getFilesystem()->mkdirs('lib'.DIRECTORY_SEPARATOR.'symfony');
87     $this->getFilesystem()->mkdirs('data'.DIRECTORY_SEPARATOR.'symfony');
88
89     $finder = sfFinder::type('any')->exec(array($this, 'excludeTests'));
90     $this->getFilesystem()->mirror($symfonyLibDir, sfConfig::get('sf_lib_dir').'/symfony', $finder);
91     $this->getFilesystem()->mirror($symfonyDataDir, sfConfig::get('sf_data_dir').'/symfony', $finder);
92     $this->getFilesystem()->rename(sfConfig::get('sf_data_dir').'/symfony/web/sf', sfConfig::get('sf_web_dir').'/sf');
93
94     $publishAssets = new sfPluginPublishAssetsTask($this->dispatcher, $this->formatter);
95     $publishAssets->setCommandApplication($this->commandApplication);
96
97     // change symfony path in ProjectConfiguration.class.php
98     $config = sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php';
99     $content = file_get_contents($config);
100     $content = str_replace('<?php', "<?php\n\n# FROZEN_SF_LIB_DIR: $symfonyLibDir", $content);
101     $content = preg_replace('#(\'|")'.preg_quote($symfonyLibDir, '#').'#', "dirname(__FILE__).$1/../lib/symfony", $content);
102     file_put_contents($config, $content);
103
104     // re-publish assets
105     $publishAssets->run(array(), array('--symfony-lib-dir='.sfConfig::get('sf_lib_dir').'/symfony'));
106   }
107
108   public function excludeTests($dir, $entry)
109   {
110     return false === strpos($dir.'/'.$entry, 'Plugin/test/');
111   }
112 }
113
Note: See TracBrowser for help on using the browser.