|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | +* This file is part of the Symfony package. |
| 6 | +* |
| 7 | +* (c) Fabien Potencier <fabien@symfony.com> |
| 8 | +* |
| 9 | +* For the full copyright and license information, please view the LICENSE |
| 10 | +* file that was distributed with this source code. |
| 11 | +*/ |
| 12 | + |
| 13 | +require __DIR__.'/src/Symfony/Component/Filesystem/Exception/ExceptionInterface.php'; |
| 14 | +require __DIR__.'/src/Symfony/Component/Filesystem/Exception/IOExceptionInterface.php'; |
| 15 | +require __DIR__.'/src/Symfony/Component/Filesystem/Exception/IOException.php'; |
| 16 | +require __DIR__.'/src/Symfony/Component/Filesystem/Filesystem.php'; |
| 17 | + |
| 18 | +use Symfony\Component\Filesystem\Filesystem; |
| 19 | + |
| 20 | +/** |
| 21 | + * Links dependencies to components to a local clone of the main symfony/symfony GitHub repository. |
| 22 | + * |
| 23 | + * @author Kévin Dunglas <dunglas@gmail.com> |
| 24 | + */ |
| 25 | + |
| 26 | +if (2 !== $argc) { |
| 27 | + echo 'Link dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL; |
| 28 | + echo "Usage: $argv[0] /path/to/the/project".PHP_EOL; |
| 29 | + exit(1); |
| 30 | +} |
| 31 | + |
| 32 | +if (!is_dir("$argv[1]/vendor/symfony")) { |
| 33 | + echo "The directory \"$argv[1]\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL; |
| 34 | + exit(1); |
| 35 | +} |
| 36 | + |
| 37 | +$sfPackages = array('symfony/symfony' => __DIR__); |
| 38 | +foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { |
| 39 | + $sfPackages[json_decode(file_get_contents("$dir/composer.json"))->name] = $dir; |
| 40 | +} |
| 41 | + |
| 42 | +$filesystem = new Filesystem(); |
| 43 | +foreach (glob("$argv[1]/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { |
| 44 | + $package = 'symfony/'.basename($dir); |
| 45 | + if (is_link($dir)) { |
| 46 | + echo "\"$package\" is already a symlink, skipping.".PHP_EOL; |
| 47 | + continue; |
| 48 | + } |
| 49 | + |
| 50 | + if (!isset($sfPackages[$package])) { |
| 51 | + continue; |
| 52 | + } |
| 53 | + |
| 54 | + $sfDir = '\\' === DIRECTORY_SEPARATOR ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir))); |
| 55 | + |
| 56 | + $filesystem->remove($dir); |
| 57 | + $filesystem->symlink($sfDir, $dir); |
| 58 | + echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL; |
| 59 | +} |
0 commit comments