Last active
January 5, 2023 17:50
-
-
Save alexander-schranz/e7488e1f2da0166b25b84d80aa6686d7 to your computer and use it in GitHub Desktop.
Detect Symfony Components used inside your project to migrate symfony/symfony to specific components
This file contains hidden or 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
| # copy this into your shell/terminal: | |
| php -r ' | |
| require_once("vendor/autoload.php"); | |
| use Symfony\\Component\\Finder\\Finder; | |
| $symfonyComponents = []; | |
| $useFinder = new Finder(); | |
| $useFinder->files()->in(__DIR__ . "/src")->name("*.php")->contains("use Symfony"); | |
| $validationFinder = new Finder(); | |
| $validationFinder->files()->in(__DIR__ . "/config")->name("*.xml")->contains("constraint-mapping"); | |
| $doctrineFinder = new Finder(); | |
| $doctrineFinder->files()->in(__DIR__ . "/config")->name("*.orm.xml"); | |
| foreach ($useFinder as $file) { | |
| $content = $file->getContents(); $lines = explode(PHP_EOL, $content); | |
| foreach ($lines as $line) { | |
| if (0 === strpos($line, "use Symfony")) { | |
| $parts = explode("\\\\", substr($line, 4)); | |
| $use = implode("\\\\", array_slice($parts, 0, 3)); | |
| $symfonyComponents[$use] = $use; | |
| } | |
| } | |
| } | |
| if (count($doctrineFinder) > 0) { | |
| $symfonyComponents[\'Symfony\\Bridge\\Doctrine\'] = \'Symfony\\Bridge\\Doctrine\'; | |
| } | |
| if (count($validationFinder) > 0) { | |
| $symfonyComponents[\'Symfony\\Component\\Validator\'] = \'Symfony\\Component\\Validator\'; | |
| } | |
| echo implode(PHP_EOL, $symfonyComponents);' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment