Development

/branches/1.3/lib/task/generator/sfGenerateProjectTask.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/task/generator/sfGenerateProjectTask.class.php

Revision 30530, 5.6 kB (checked in by fabien, 4 years ago)

[1.3, 1.4] fixed path when a project is created on Windows and used on Linux (closes #8835)

  • 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 require_once(dirname(__FILE__).'/sfGeneratorBaseTask.class.php');
12
13 /**
14  * Generates a new project.
15  *
16  * @package    symfony
17  * @subpackage task
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfGenerateProjectTask extends sfGeneratorBaseTask
22 {
23   /**
24    * @see sfTask
25    */
26   protected function doRun(sfCommandManager $commandManager, $options)
27   {
28     $this->process($commandManager, $options);
29
30     return $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues());
31   }
32
33   /**
34    * @see sfTask
35    */
36   protected function configure()
37   {
38     $this->addArguments(array(
39       new sfCommandArgument('name', sfCommandArgument::REQUIRED, 'The project name'),
40       new sfCommandArgument('author', sfCommandArgument::OPTIONAL, 'The project author', 'Your name here'),
41     ));
42
43     $this->addOptions(array(
44       new sfCommandOption('orm', null, sfCommandOption::PARAMETER_REQUIRED, 'The ORM to use by default', 'Doctrine'),
45       new sfCommandOption('installer', null, sfCommandOption::PARAMETER_REQUIRED, 'An installer script to execute', null),
46     ));
47
48     $this->aliases = array('init-project');
49     $this->namespace = 'generate';
50     $this->name = 'project';
51
52     $this->briefDescription = 'Generates a new project';
53
54     $this->detailedDescription = <<<EOF
55 The [generate:project|INFO] task creates the basic directory structure
56 for a new project in the current directory:
57
58   [./symfony generate:project blog|INFO]
59
60 If the current directory already contains a symfony project,
61 it throws a [sfCommandException|COMMENT].
62
63 By default, the task configures Doctrine as the ORM. If you want to use
64 Propel, use the [--orm|COMMENT] option:
65
66   [./symfony generate:project blog --orm=Propel|INFO]
67
68 If you don't want to use an ORM, pass [none|COMMENT] to [--orm|COMMENT] option:
69
70   [./symfony generate:project blog --orm=none|INFO]
71
72 You can also pass the [--installer|COMMENT] option to further customize the
73 project:
74
75   [./symfony generate:project blog --installer=./installer.php|INFO]
76
77 You can optionally include a second [author|COMMENT] argument to specify what name to
78 use as author when symfony generates new classes:
79
80   [./symfony generate:project blog "Jack Doe"|INFO]
81 EOF;
82   }
83
84   /**
85    * @see sfTask
86    */
87   protected function execute($arguments = array(), $options = array())
88   {
89     if (file_exists('symfony'))
90     {
91       throw new sfCommandException(sprintf('A symfony project already exists in this directory (%s).', getcwd()));
92     }
93
94     if (!in_array(strtolower($options['orm']), array('propel', 'doctrine', 'none')))
95     {
96       throw new InvalidArgumentException(sprintf('Invalid ORM name "%s".', $options['orm']));
97     }
98
99     if ($options['installer'] && $this->commandApplication && !file_exists($options['installer']))
100     {
101       throw new InvalidArgumentException(sprintf('The installer "%s" does not exist.', $options['installer']));
102     }
103
104     // clean orm option
105     $options['orm'] = ucfirst(strtolower($options['orm']));
106
107     $this->arguments = $arguments;
108     $this->options = $options;
109
110     // create basic project structure
111     $this->installDir(dirname(__FILE__).'/skeleton/project');
112
113     // update ProjectConfiguration class (use a relative path when the symfony core is nested within the project)
114     $symfonyCoreAutoload = 0 === strpos(sfConfig::get('sf_symfony_lib_dir'), sfConfig::get('sf_root_dir')) ?
115       sprintf('dirname(__FILE__).\'/..%s/autoload/sfCoreAutoload.class.php\'', str_replace(sfConfig::get('sf_root_dir'), '', sfConfig::get('sf_symfony_lib_dir'))) :
116       var_export(sfConfig::get('sf_symfony_lib_dir').'/autoload/sfCoreAutoload.class.php', true);
117
118     $this->replaceTokens(array(sfConfig::get('sf_config_dir')), array('SYMFONY_CORE_AUTOLOAD' => str_replace('\\', '/', $symfonyCoreAutoload)));
119
120     $this->tokens = array(
121       'ORM'          => $this->options['orm'],
122       'PROJECT_NAME' => $this->arguments['name'],
123       'AUTHOR_NAME'  => $this->arguments['author'],
124       'PROJECT_DIR'  => sfConfig::get('sf_root_dir'),
125     );
126
127     $this->replaceTokens();
128
129     // execute the choosen ORM installer script
130     if (in_array($options['orm'], array('Doctrine', 'Propel')))
131     {
132       include dirname(__FILE__).'/../../plugins/sf'.$options['orm'].'Plugin/config/installer.php';
133     }
134
135     // execute a custom installer
136     if ($options['installer'] && $this->commandApplication)
137     {
138       if ($this->canRunInstaller($options['installer']))
139       {
140         $this->reloadTasks();
141         include $options['installer'];
142       }
143     }
144
145     // fix permission for common directories
146     $fixPerms = new sfProjectPermissionsTask($this->dispatcher, $this->formatter);
147     $fixPerms->setCommandApplication($this->commandApplication);
148     $fixPerms->setConfiguration($this->configuration);
149     $fixPerms->run();
150
151     $this->replaceTokens();
152   }
153
154   protected function canRunInstaller($installer)
155   {
156     if (preg_match('#^(https?|ftps?)://#', $installer))
157     {
158       if (ini_get('allow_url_fopen') === false)
159       {
160         $this->logSection('generate', sprintf('Cannot run remote installer "%s" because "allow_url_fopen" is off', $installer));
161       }
162       if (ini_get('allow_url_include') === false)
163       {
164         $this->logSection('generate', sprintf('Cannot run remote installer "%s" because "allow_url_include" is off', $installer));
165       }
166       return ini_get('allow_url_fopen') && ini_get('allow_url_include');
167     }
168     return true;
169   }
170 }
171
Note: See TracBrowser for help on using the browser.