Skip to content
This repository

[Generator] removed Filesystem class. Propel now relies on the standalon... #295

Merged
merged 1 commit into from almost 2 years ago

3 participants

Hugo Hamon Don't Add Me To Your Organization a.k.a The Travis Bot William Durand
Hugo Hamon
Collaborator

...e Filesystem component of the Symfony2 framework installable via Composer.

Hugo Hamon hhamon [Generator] removed Filesystem class. Propel now relies on the standa…
…lone Filesystem component of the Symfony2 framework installable via Composer.
cd22336
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged cd22336 into 338752a).

William Durand willdurand merged commit a24f5fe into from
William Durand
Owner

Great, thank you Hugo!

William Durand
Owner

Oh shhhh...

Hugo Hamon
Collaborator

Why is it failing?

William Durand
Owner
Hugo Hamon
Collaborator

Is it my fault? I haven't changed any permissions and tests pass on my machine...

Hugo Hamon
Collaborator

Ok I see why now. The Filesystem::mkdir() method of Symfony2 does not return a boolean value. It returns nothing or throw an exception. I'm fixing the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 22, 2012
Hugo Hamon hhamon [Generator] removed Filesystem class. Propel now relies on the standa…
…lone Filesystem component of the Symfony2 framework installable via Composer.
cd22336
This page is out of date. Refresh to see the latest.
3  composer.json
@@ -21,7 +21,8 @@
21 21 "symfony/console": "2.1.*",
22 22 "monolog/monolog": "1.0.*",
23 23 "symfony/finder": "2.1.*",
24   - "symfony/validator": "2.1.*"
  24 + "symfony/validator": "2.1.*",
  25 + "symfony/filesystem": "2.1.*"
25 26 },
26 27 "require-dev": {
27 28 "behat/behat": "2.4@stable"
19 src/Propel/Generator/Command/AbstractCommand.php
@@ -13,7 +13,7 @@
13 13 use Symfony\Component\Console\Command\Command;
14 14 use Symfony\Component\Console\Input\InputOption;
15 15 use Symfony\Component\Finder\Finder;
16   -
  16 +use Symfony\Component\Filesystem\Filesystem;
17 17 use Propel\Generator\Exception\RuntimeException;
18 18
19 19 /**
@@ -22,9 +22,10 @@
22 22 abstract class AbstractCommand extends Command
23 23 {
24 24 const DEFAULT_INPUT_DIRECTORY = '.';
25   -
26 25 const DEFAULT_PLATFORM = 'MysqlPlatform';
27 26
  27 + protected $filesystem;
  28 +
28 29 /**
29 30 * {@inheritdoc}
30 31 */
@@ -72,6 +73,20 @@ protected function getSchemas($directory)
72 73 );
73 74 }
74 75
  76 + /**
  77 + * Returns a Filesystem instance.
  78 + *
  79 + * @return Filesystem
  80 + */
  81 + protected function getFilesystem()
  82 + {
  83 + if (null === $this->filesystem) {
  84 + $this->filesystem = new Filesystem();
  85 + }
  86 +
  87 + return $this->filesystem;
  88 + }
  89 +
75 90 protected function parseConnection($connection)
76 91 {
77 92 $pos = strpos($connection, '=');
6 src/Propel/Generator/Command/ConfigConvertXmlCommand.php
@@ -10,16 +10,14 @@
10 10
11 11 namespace Propel\Generator\Command;
12 12
13   -use Symfony\Component\Console\Command\Command;
14 13 use Symfony\Component\Console\Input\InputOption;
15 14 use Symfony\Component\Console\Input\InputInterface;
16 15 use Symfony\Component\Console\Output\OutputInterface;
17 16 use Symfony\Component\Console\Output\Output;
18 17 use Propel\Generator\Config\XmlToArrayConverter;
19 18 use Propel\Generator\Config\ArrayToPhpConverter;
20   -use Propel\Generator\Util\Filesystem;
21 19
22   -class ConfigConvertXmlCommand extends Command
  20 +class ConfigConvertXmlCommand extends AbstractCommand
23 21 {
24 22 const DEFAULT_INPUT_DIRECTORY = '.';
25 23 const DEFAULT_INPUT_FILE = 'runtime-conf.xml';
@@ -51,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
51 49 throw new \RuntimeException(sprintf('Unable to find the "%s" configuration file', $inputFilePath));
52 50 }
53 51
54   - $filesystem = new Filesystem();
  52 + $filesystem = $this->getFilesystem();
55 53 if (!$filesystem->mkdir($input->getOption('output-dir'))) {
56 54 throw new \RuntimeException(sprintf('Unable to write the "%s" output directory', $input->getOption('output-dir')));
57 55 };
3  src/Propel/Generator/Command/DatabaseReverseCommand.php
@@ -17,7 +17,6 @@
17 17 use Symfony\Component\Console\Output\Output;
18 18 use Propel\Generator\Config\GeneratorConfig;
19 19 use Propel\Generator\Manager\ReverseManager;
20   -use Propel\Generator\Util\Filesystem;
21 20
22 21 /**
23 22 * @author William Durand <william.durand1@gmail.com>
@@ -61,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
61 60 'propel.reverse.parser.class' => sprintf('\\Propel\\Generator\\Reverse\\%sSchemaParser', $vendor),
62 61 ));
63 62
64   - $filesystem = new Filesystem();
  63 + $filesystem = $this->getFilesystem();
65 64 $filesystem->mkdir($input->getOption('output-dir'));
66 65
67 66 $manager = new ReverseManager();
3  src/Propel/Generator/Command/GraphvizGenerateCommand.php
@@ -16,7 +16,6 @@
16 16 use Symfony\Component\Console\Output\Output;
17 17 use Propel\Generator\Config\GeneratorConfig;
18 18 use Propel\Generator\Manager\GraphvizManager;
19   -use Propel\Generator\Util\Filesystem;
20 19
21 20 /**
22 21 * @author William Durand <william.durand1@gmail.com>
@@ -49,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
49 48 'propel.packageObjectModel' => true,
50 49 ));
51 50
52   - $filesystem = new Filesystem();
  51 + $filesystem = $this->getFilesystem();
53 52 $filesystem->mkdir($input->getOption('output-dir'));
54 53
55 54 $manager = new GraphvizManager();
3  src/Propel/Generator/Command/MigrationDiffCommand.php
@@ -18,7 +18,6 @@
18 18 use Propel\Generator\Exception\RuntimeException;
19 19 use Propel\Generator\Manager\MigrationManager;
20 20 use Propel\Generator\Model\IdMethod;
21   -use Propel\Generator\Util\Filesystem;
22 21
23 22 /**
24 23 * @author William Durand <william.durand1@gmail.com>
@@ -55,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
55 54 'propel.platform.class' => $input->getOption('platform'),
56 55 ));
57 56
58   - $filesystem = new Filesystem();
  57 + $filesystem = $this->getFilesystem();
59 58 $filesystem->mkdir($input->getOption('output-dir'));
60 59
61 60 $manager = new MigrationManager();
3  src/Propel/Generator/Command/MigrationDownCommand.php
@@ -16,7 +16,6 @@
16 16 use Symfony\Component\Console\Output\Output;
17 17 use Propel\Generator\Config\GeneratorConfig;
18 18 use Propel\Generator\Manager\MigrationManager;
19   -use Propel\Generator\Util\Filesystem;
20 19
21 20 /**
22 21 * @author William Durand <william.durand1@gmail.com>
@@ -52,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
52 51 'propel.platform.class' => $input->getOption('platform'),
53 52 ));
54 53
55   - $filesystem = new Filesystem();
  54 + $filesystem = $this->getFilesystem();
56 55 $filesystem->mkdir($input->getOption('output-dir'));
57 56
58 57 $manager = new MigrationManager();
3  src/Propel/Generator/Command/MigrationMigrateCommand.php
@@ -16,7 +16,6 @@
16 16 use Symfony\Component\Console\Output\Output;
17 17 use Propel\Generator\Config\GeneratorConfig;
18 18 use Propel\Generator\Manager\MigrationManager;
19   -use Propel\Generator\Util\Filesystem;
20 19
21 20 /**
22 21 * @author William Durand <william.durand1@gmail.com>
@@ -52,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
52 51 'propel.platform.class' => $input->getOption('platform'),
53 52 ));
54 53
55   - $filesystem = new Filesystem();
  54 + $filesystem = $this->getFilesystem();
56 55 $filesystem->mkdir($input->getOption('output-dir'));
57 56
58 57 $manager = new MigrationManager();
3  src/Propel/Generator/Command/MigrationStatusCommand.php
@@ -16,7 +16,6 @@
16 16 use Symfony\Component\Console\Output\Output;
17 17 use Propel\Generator\Config\GeneratorConfig;
18 18 use Propel\Generator\Manager\MigrationManager;
19   -use Propel\Generator\Util\Filesystem;
20 19
21 20 /**
22 21 * @author William Durand <william.durand1@gmail.com>
@@ -52,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
52 51 'propel.platform.class' => $input->getOption('platform'),
53 52 ));
54 53
55   - $filesystem = new Filesystem();
  54 + $filesystem = $this->getFilesystem();
56 55 $filesystem->mkdir($input->getOption('output-dir'));
57 56
58 57 $manager = new MigrationManager();
3  src/Propel/Generator/Command/MigrationUpCommand.php
@@ -16,7 +16,6 @@
16 16 use Symfony\Component\Console\Output\Output;
17 17 use Propel\Generator\Config\GeneratorConfig;
18 18 use Propel\Generator\Manager\MigrationManager;
19   -use Propel\Generator\Util\Filesystem;
20 19
21 20 /**
22 21 * @author William Durand <william.durand1@gmail.com>
@@ -52,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
52 51 'propel.platform.class' => $input->getOption('platform'),
53 52 ));
54 53
55   - $filesystem = new Filesystem();
  54 + $filesystem = $this->getFilesystem();
56 55 $filesystem->mkdir($input->getOption('output-dir'));
57 56
58 57 $manager = new MigrationManager();
3  src/Propel/Generator/Command/ModelBuildCommand.php
@@ -16,7 +16,6 @@
16 16 use Symfony\Component\Console\Output\Output;
17 17 use Propel\Generator\Config\GeneratorConfig;
18 18 use Propel\Generator\Manager\ModelManager;
19   -use Propel\Generator\Util\Filesystem;
20 19
21 20 /**
22 21 * @author Florian Klein <florian.klein@free.fr>
@@ -133,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
133 132 'propel.mysql.tableEngineKeyword' => 'ENGINE',
134 133 ), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties')));
135 134
136   - $filesystem = new Filesystem();
  135 + $filesystem = $this->getFilesystem();
137 136 $filesystem->mkdir($input->getOption('output-dir'));
138 137
139 138 $manager = new ModelManager();
3  src/Propel/Generator/Command/SqlBuildCommand.php
@@ -16,7 +16,6 @@
16 16 use Symfony\Component\Console\Output\Output;
17 17 use Propel\Generator\Config\GeneratorConfig;
18 18 use Propel\Generator\Manager\SqlManager;
19   -use Propel\Generator\Util\Filesystem;
20 19
21 20 /**
22 21 * @author William Durand <william.durand1@gmail.com>
@@ -64,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
64 63 'propel.mysql.tableEngineKeyword' => 'ENGINE',
65 64 ), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties')));
66 65
67   - $filesystem = new Filesystem();
  66 + $filesystem = $this->getFilesystem();
68 67 $filesystem->mkdir($input->getOption('output-dir'));
69 68
70 69 $manager = new SqlManager();
275 src/Propel/Generator/Util/Filesystem.php
... ... @@ -1,275 +0,0 @@
1   -<?php
2   -
3   -/**
4   - * This file is part of the Propel package.
5   - * For the full copyright and license information, please view the LICENSE
6   - * file that was distributed with this source code.
7   - *
8   - * @license MIT License
9   - */
10   -
11   -namespace Propel\Generator\Util;
12   -
13   -/**
14   - * Provides basic utility to manipulate the file system.
15   - * This class comes from the Symfony2 framework.
16   - *
17   - * @author Fabien Potencier <fabien@symfony.com>
18   - */
19   -class Filesystem
20   -{
21   - /**
22   - * Copies a file.
23   - *
24   - * This method only copies the file if the origin file is newer than the target file.
25   - *
26   - * By default, if the target already exists, it is not overridden.
27   - *
28   - * @param string $originFile The original filename
29   - * @param string $targetFile The target filename
30   - * @param array $override Whether to override an existing file or not
31   - */
32   - public function copy($originFile, $targetFile, $override = false)
33   - {
34   - $this->mkdir(dirname($targetFile));
35   -
36   - if (!$override && is_file($targetFile)) {
37   - $doCopy = filemtime($originFile) > filemtime($targetFile);
38   - } else {
39   - $doCopy = true;
40   - }
41   -
42   - if ($doCopy) {
43   - copy($originFile, $targetFile);
44   - }
45   - }
46   -
47   - /**
48   - * Creates a directory recursively.
49   - *
50   - * @param string|array|\Traversable $dirs The directory path
51   - * @param int $mode The directory mode
52   - *
53   - * @return boolean true if the directory has been created, false otherwise
54   - */
55   - public function mkdir($dirs, $mode = 0777)
56   - {
57   - $ret = true;
58   - foreach ($this->toIterator($dirs) as $dir) {
59   - if (is_dir($dir)) {
60   - continue;
61   - }
62   -
63   - $ret = @mkdir($dir, $mode, true) && $ret;
64   - }
65   -
66   - return $ret;
67   - }
68   -
69   - /**
70   - * Creates empty files.
71   - *
72   - * @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
73   - */
74   - public function touch($files)
75   - {
76   - foreach ($this->toIterator($files) as $file) {
77   - touch($file);
78   - }
79   - }
80   -
81   - /**
82   - * Removes files or directories.
83   - *
84   - * @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
85   - */
86   - public function remove($files)
87   - {
88   - $files = iterator_to_array($this->toIterator($files));
89   - $files = array_reverse($files);
90   - foreach ($files as $file) {
91   - if (!file_exists($file)) {
92   - continue;
93   - }
94   -
95   - if (is_dir($file) && !is_link($file)) {
96   - $this->remove(new \FilesystemIterator($file));
97   -
98   - rmdir($file);
99   - } else {
100   - unlink($file);
101   - }
102   - }
103   - }
104   -
105   - /**
106   - * Change mode for an array of files or directories.
107   - *
108   - * @param string|array|\Traversable $files A filename, an array of files, or a \Traversable instance to remove
109   - * @param integer $mode The new mode
110   - * @param integer $umask The mode mask (octal)
111   - */
112   - public function chmod($files, $mode, $umask = 0000)
113   - {
114   - $currentUmask = umask();
115   - umask($umask);
116   -
117   - foreach ($this->toIterator($files) as $file) {
118   - chmod($file, $mode);
119   - }
120   -
121   - umask($currentUmask);
122   - }
123   -
124   - /**
125   - * Renames a file.
126   - *
127   - * @param string $origin The origin filename
128   - * @param string $target The new filename
129   - *
130   - * @throws \RuntimeException When target file already exists
131   - */
132   - public function rename($origin, $target)
133   - {
134   - // we check that target does not exist
135   - if (is_readable($target)) {
136   - throw new \RuntimeException(sprintf('Cannot rename because the target "%s" already exist.', $target));
137   - }
138   -
139   - rename($origin, $target);
140   - }
141   -
142   - /**
143   - * Creates a symbolic link or copy a directory.
144   - *
145   - * @param string $originDir The origin directory path
146   - * @param string $targetDir The symbolic link name
147   - * @param boolean $copyOnWindows Whether to copy files if on Windows
148   - */
149   - public function symlink($originDir, $targetDir, $copyOnWindows = false)
150   - {
151   - if (!function_exists('symlink') && $copyOnWindows) {
152   - $this->mirror($originDir, $targetDir);
153   -
154   - return;
155   - }
156   -
157   - $ok = false;
158   - if (is_link($targetDir)) {
159   - if (readlink($targetDir) != $originDir) {
160   - unlink($targetDir);
161   - } else {
162   - $ok = true;
163   - }
164   - }
165   -
166   - if (!$ok) {
167   - symlink($originDir, $targetDir);
168   - }
169   - }
170   -
171   - /**
172   - * Given an existing path, convert it to a path relative to a given starting path
173   - *
174   - * @var string Absolute path of target
175   - * @var string Absolute path where traversal begins
176   - *
177   - * @return string Path of target relative to starting path
178   - */
179   - public function makePathRelative($endPath, $startPath)
180   - {
181   - // Find for which character the the common path stops
182   - $offset = 0;
183   - while ($startPath[$offset] === $endPath[$offset]) {
184   - $offset++;
185   - }
186   -
187   - // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels)
188   - $depth = substr_count(substr($startPath, $offset), DIRECTORY_SEPARATOR) + 1;
189   -
190   - // Repeated "../" for each level need to reach the common path
191   - $traverser = str_repeat('../', $depth);
192   -
193   - // Construct $endPath from traversing to the common path, then to the remaining $endPath
194   - return $traverser.substr($endPath, $offset);
195   - }
196   -
197   - /**
198   - * Mirrors a directory to another.
199   - *
200   - * @param string $originDir The origin directory
201   - * @param string $targetDir The target directory
202   - * @param \Traversable $iterator A Traversable instance
203   - * @param array $options An array of boolean options
204   - * Valid options are:
205   - * - $options['override'] Whether to override an existing file on copy or not (see copy())
206   - * - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink())
207   - *
208   - * @throws \RuntimeException When file type is unknown
209   - */
210   - public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array())
211   - {
212   - $copyOnWindows = false;
213   - if (isset($options['copy_on_windows']) && !function_exists('symlink')) {
214   - $copyOnWindows = $options['copy_on_windows'];
215   - }
216   -
217   - if (null === $iterator) {
218   - $flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
219   - $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
220   - }
221   -
222   - if ('/' === substr($targetDir, -1) || '\\' === substr($targetDir, -1)) {
223   - $targetDir = substr($targetDir, 0, -1);
224   - }
225   -
226   - if ('/' === substr($originDir, -1) || '\\' === substr($originDir, -1)) {
227   - $originDir = substr($originDir, 0, -1);
228   - }
229   -
230   - foreach ($iterator as $file) {
231   - $target = $targetDir.'/'.str_replace($originDir.DIRECTORY_SEPARATOR, '', $file->getPathname());
232   -
233   - if (is_link($file)) {
234   - $this->symlink($file, $target);
235   - } elseif (is_dir($file)) {
236   - $this->mkdir($target);
237   - } elseif (is_file($file) || ($copyOnWindows && is_link($file))) {
238   - $this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
239   - } else {
240   - throw new \RuntimeException(sprintf('Unable to guess "%s" file type.', $file));
241   - }
242   - }
243   - }
244   -
245   - /**
246   - * Returns whether the file path is an absolute path.
247   - *
248   - * @param string $file A file path
249   - *
250   - * @return boolean
251   - */
252   - public function isAbsolutePath($file)
253   - {
254   - if ($file[0] == '/' || $file[0] == '\\'
255   - || (strlen($file) > 3 && ctype_alpha($file[0])
256   - && $file[1] == ':'
257   - && ($file[2] == '\\' || $file[2] == '/')
258   - )
259   - || null !== parse_url($file, PHP_URL_SCHEME)
260   - ) {
261   - return true;
262   - }
263   -
264   - return false;
265   - }
266   -
267   - private function toIterator($files)
268   - {
269   - if (!$files instanceof \Traversable) {
270   - $files = new \ArrayObject(is_array($files) ? $files : array($files));
271   - }
272   -
273   - return $files;
274   - }
275   -}

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.