Development

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

You must first sign up to be able to contribute.

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

Revision 13213, 3.4 kB (checked in by FabianLange, 6 years ago)

[1.1] fixed regular expression back reference bug on windows pathes like "symfony\1.2". fixes #5021

  • 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|INFO]
40
41 The task also changes [config/config.php|COMMENT] to switch to the
42 embedded symfony files.
43 EOF;
44   }
45
46   /**
47    * @see sfTask
48    */
49   protected function execute($arguments = array(), $options = array())
50   {
51     // check that the symfony librairies are not already freeze for this project
52     if (is_readable(sfConfig::get('sf_lib_dir').'/symfony'))
53     {
54       throw new sfCommandException('You can only freeze when lib/symfony is empty.');
55     }
56
57     if (is_readable(sfConfig::get('sf_data_dir').'/symfony'))
58     {
59       throw new sfCommandException('You can only freeze when data/symfony is empty.');
60     }
61
62     if (is_readable(sfConfig::get('sf_web_dir').'/sf'))
63     {
64       throw new sfCommandException('You can only freeze when web/sf is empty.');
65     }
66
67     if (is_link(sfConfig::get('sf_web_dir').'/sf'))
68     {
69       $this->getFilesystem()->remove(sfConfig::get('sf_web_dir').'/sf');
70     }
71
72     $symfonyLibDir  = sfConfig::get('sf_symfony_lib_dir');
73     $symfonyDataDir = $arguments['symfony_data_dir'];
74
75     if (!is_readable($symfonyDataDir))
76     {
77       throw new sfCommandException(sprintf('The symfony data dir does not seem to be located at "%s".', $symfonyDataDir));
78     }
79
80     $this->logSection('freeze', sprintf('freezing lib found in "%s"', $symfonyLibDir));
81     $this->logSection('freeze', sprintf('freezing data found in "%s"', $symfonyDataDir));
82
83     $this->getFilesystem()->mkdirs('lib'.DIRECTORY_SEPARATOR.'symfony');
84     $this->getFilesystem()->mkdirs('data'.DIRECTORY_SEPARATOR.'symfony');
85
86     $finder = sfFinder::type('any')->exec(array($this, 'excludeTests'));
87     $this->getFilesystem()->mirror($symfonyLibDir, sfConfig::get('sf_lib_dir').'/symfony', $finder);
88     $this->getFilesystem()->mirror($symfonyDataDir, sfConfig::get('sf_data_dir').'/symfony', $finder);
89     $this->getFilesystem()->rename(sfConfig::get('sf_data_dir').'/symfony/web/sf', sfConfig::get('sf_web_dir').'/sf');
90
91     // change symfony path in ProjectConfiguration.class.php
92     $config = sfConfig::get('sf_config_dir').'/ProjectConfiguration.class.php';
93     $content = file_get_contents($config);
94     $content = str_replace('<?php', "<?php\n\n# FROZEN_SF_LIB_DIR: $symfonyLibDir", $content);
95     $content = preg_replace('#(\'|")'.preg_quote($symfonyLibDir, '#').'#', "dirname(__FILE__).$1/../lib/symfony", $content);
96     file_put_contents($config, $content);
97   }
98
99   public function excludeTests($dir, $entry)
100   {
101     return false === strpos($dir.'/'.$entry, 'Plugin/test/');
102   }
103 }
104
Note: See TracBrowser for help on using the browser.