Last active
July 3, 2024 12:37
-
-
Save dr0bz/0fd18255f5a5c3b6b17ab3e8152be225 to your computer and use it in GitHub Desktop.
Find unused symfony services
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
<?php | |
$filename = './srcApp_KernelDevDebugContainer.xml'; | |
$content = file_get_contents($filename); | |
// the \> at the end of a service definition means this service has no dependencies. | |
preg_match_all('/\<service id="(App.+?)".* autowire="true" .*?\/>/', $content, $matches); | |
$serviceIds = $matches[1]; | |
foreach ($serviceIds as $serviceId) { | |
$serviceId = str_replace('\\', '\\\\', $serviceId); | |
if (!preg_match(sprintf('/\<argument (key=".*?")? type="service" id="%s"\/>/', $serviceId), $content)) { | |
echo sprintf("Unused service: %s\n", $serviceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment