Skip to content

Commit d4c8be7

Browse files
committed
feature #37915 Improve link script with rollback when using symlink (noniagriconomie)
This PR was merged into the 5.2-dev branch. Discussion ---------- Improve link script with rollback when using symlink | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Improve when dev `symfony/symfony` with local project | License | MIT | Doc PR | . Hi, this just `rollback` the local project state when finishing testing via `symlink` (default) Commits ------- abf40ce Improve link script with rollback when using symlink
2 parents 374a0b2 + abf40ce commit d4c8be7

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

link

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ require __DIR__.'/src/Symfony/Component/Filesystem/Filesystem.php';
1818
use Symfony\Component\Filesystem\Filesystem;
1919

2020
/**
21-
* Links dependencies to components to a local clone of the main symfony/symfony GitHub repository.
21+
* Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.
2222
*
2323
* @author Kévin Dunglas <dunglas@gmail.com>
2424
*/
2525

2626
$copy = false !== $k = array_search('--copy', $argv, true);
2727
$copy && array_splice($argv, $k, 1);
28+
$rollback = false !== $k = array_search('--rollback', $argv, true);
29+
$rollback && array_splice($argv, $k, 1);
2830
$pathToProject = $argv[1] ?? getcwd();
2931

3032
if (!is_dir("$pathToProject/vendor/symfony")) {
31-
echo 'Link (or copy) dependencies to components to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
33+
echo 'Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.'.PHP_EOL.PHP_EOL;
3234
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
3335
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
36+
echo ' Use `--rollback` to rollback'.PHP_EOL.PHP_EOL;
3437
echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
3538
exit(1);
3639
}
@@ -44,7 +47,6 @@ $directories = array_merge(...array_values(array_map(function ($part) {
4447
}, $braces)));
4548

4649
$directories[] = __DIR__.'/src/Symfony/Contracts';
47-
4850
foreach ($directories as $dir) {
4951
if ($filesystem->exists($composer = "$dir/composer.json")) {
5052
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
@@ -53,12 +55,19 @@ foreach ($directories as $dir) {
5355

5456
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
5557
$package = 'symfony/'.basename($dir);
56-
if (!$copy && is_link($dir)) {
57-
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
58+
59+
if (!isset($sfPackages[$package])) {
5860
continue;
5961
}
6062

61-
if (!isset($sfPackages[$package])) {
63+
if ($rollback) {
64+
$filesystem->remove($dir);
65+
echo "\"$package\" has been rollback from \"$sfPackages[$package]\".".PHP_EOL;
66+
continue;
67+
}
68+
69+
if (!$copy && is_link($dir)) {
70+
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
6271
continue;
6372
}
6473

@@ -78,3 +87,7 @@ foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as
7887
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
7988
$filesystem->remove($cacheDir);
8089
}
90+
91+
if ($rollback) {
92+
echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL;
93+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy