-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13665 from nextcloud/bugfix/noid/migrate-to-php-s…
…coper fix(dependencies): Migrate to PHP scoper
- Loading branch information
Showing
7 changed files
with
850 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
$sourceDirectory = $argv[1]; | ||
$sourceDirectory = rtrim($sourceDirectory, '/') . '/'; | ||
|
||
if (!str_starts_with('/', $sourceDirectory)) { | ||
$sourceDirectory = getcwd() . '/' . $sourceDirectory; | ||
} | ||
|
||
$stripNamespacePrefix = $argv[2] ?? ''; | ||
if ($stripNamespacePrefix) { | ||
printf("Namespace Prefix to strip from destination dir is %s%s", $stripNamespacePrefix, PHP_EOL); | ||
} | ||
|
||
if (!file_exists($sourceDirectory) || !is_dir($sourceDirectory)) { | ||
print("Directory not found"); | ||
exit(1); | ||
} | ||
$organizationList = []; | ||
foreach(scandir($sourceDirectory) as $file) { | ||
if (!is_dir($sourceDirectory . $file) || $file === '.' || $file === '..') { | ||
continue; | ||
} | ||
$organizationList[] = $sourceDirectory . $file . '/'; | ||
} | ||
|
||
$projectList = []; | ||
foreach($organizationList as $organizationDir) { | ||
foreach(scandir($organizationDir) as $file) { | ||
if (!is_dir($organizationDir . $file) || $file === '.' || $file === '..') { | ||
continue; | ||
} | ||
$projectList[] = $organizationDir . $file . '/'; | ||
} | ||
} | ||
|
||
foreach ($projectList as $projectDir) { | ||
if (!file_exists($projectDir . 'composer.json')) { | ||
continue; | ||
} | ||
$projectInfo = json_decode(file_get_contents($projectDir . 'composer.json'), true); | ||
if (!isset($projectInfo['autoload']['psr-4'])) { | ||
printf("No supported autoload configuration in %s" . PHP_EOL, $projectDir); | ||
exit(2); | ||
} | ||
foreach ($projectInfo['autoload']['psr-4'] as $namespace => $codeDir) { | ||
if ($stripNamespacePrefix !== '' && strpos($namespace, $stripNamespacePrefix) === 0) { | ||
$namespace = str_replace($stripNamespacePrefix, '', $namespace); | ||
} | ||
$destination = $sourceDirectory . str_replace('\\', '/', $namespace); | ||
if (file_exists($destination)) { | ||
rmdir_recursive($destination); | ||
} | ||
mkdir($destination, 0777, true); | ||
if (!rename($projectDir . $codeDir, $destination)) { | ||
printf("Failed to move %s to %s" . PHP_EOL, $projectDir . $codeDir, $destination); | ||
exit(3); | ||
} | ||
} | ||
} | ||
|
||
foreach($organizationList as $organizationDir) { | ||
rmdir_recursive($organizationDir); | ||
} | ||
|
||
function rmdir_recursive($dir) { | ||
foreach(scandir($dir) as $file) { | ||
if ('.' === $file || '..' === $file) { | ||
continue; | ||
} | ||
if (is_dir("$dir/$file")) { | ||
rmdir_recursive("$dir/$file"); | ||
} else { | ||
unlink("$dir/$file"); | ||
} | ||
} | ||
rmdir($dir); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
use Isolated\Symfony\Component\Finder\Finder; | ||
|
||
// You can do your own things here, e.g. collecting symbols to expose dynamically | ||
// or files to exclude. | ||
// However, beware that this file is executed by PHP-Scoper, hence if you are using | ||
// the PHAR it will be loaded by the PHAR. So it is highly recommended to avoid | ||
// to autoload any code here: it can result in a conflict or even corrupt | ||
// the PHP-Scoper analysis. | ||
|
||
return [ | ||
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#prefix | ||
'prefix' => 'OCA\\Talk\\Vendor', | ||
'output-dir' => 'lib/Vendor', | ||
|
||
// For more see: https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#finders-and-paths | ||
'finders' => [ | ||
Finder::create()->files() | ||
->exclude([ | ||
'test', | ||
'composer', | ||
'bin', | ||
]) | ||
->notName('autoload.php') | ||
->in('vendor/cuyz'), | ||
Finder::create()->files() | ||
->exclude([ | ||
'test', | ||
'composer', | ||
'bin', | ||
]) | ||
->notName('autoload.php') | ||
->in('vendor/psr/simple-cache'), | ||
Finder::create()->files() | ||
->exclude([ | ||
'test', | ||
'composer', | ||
'bin', | ||
]) | ||
->notName('autoload.php') | ||
->in('vendor/firebase'), | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
"sort-packages": true | ||
}, | ||
"require": { | ||
"coenjacobs/mozart": "^0.7.1" | ||
"humbug/php-scoper": "^0.18.7" | ||
} | ||
} |
Oops, something went wrong.