hasPostCreateProjectCmdEvent checks if any installed Composer plugin subscribes to the post-create-project-cmd event. It parses the verbose output of `composer run-script --list` to extract plugin class names, then uses PHP reflection to check each plugin's getSubscribedEvents() method for the event
(app *ddevapp.DdevApp)
| 492 | // reflection to check each plugin's getSubscribedEvents() method for the event. |
| 493 | // Returns true if any plugin handles post-create-project-cmd, false otherwise. |
| 494 | func hasPostCreateProjectCmdEvent(app *ddevapp.DdevApp) bool { |
| 495 | userOutFunc := util.CaptureUserOut() |
| 496 | _, _, err := app.Exec(&ddevapp.ExecOpts{ |
| 497 | Service: "web", |
| 498 | Dir: getComposerRootInContainer(app), |
| 499 | Cmd: ` |
| 500 | composer run-script --list -vvv 2>&1 | |
| 501 | grep -i 'Loading plugin' | |
| 502 | awk '{print $3}' | |
| 503 | while IFS= read -r class; do |
| 504 | php -r " |
| 505 | require 'vendor/autoload.php'; |
| 506 | \$pluginClass = '$class'; |
| 507 | if (method_exists(\$pluginClass, 'getSubscribedEvents')) { |
| 508 | \$events = \$pluginClass::getSubscribedEvents(); |
| 509 | foreach (array_keys(\$events) as \$eventName) { |
| 510 | echo \$eventName . PHP_EOL; |
| 511 | } |
| 512 | } |
| 513 | " |
| 514 | done | grep -q '^post-create-project-cmd$' |
| 515 | `, |
| 516 | Env: []string{"XDEBUG_MODE=off"}, |
| 517 | }) |
| 518 | _ = userOutFunc() |
| 519 | return err == nil |
| 520 | } |
| 521 | |
| 522 | // getComposerRootInContainer returns the composer root in the container |
| 523 | func getComposerRootInContainer(app *ddevapp.DdevApp) string { |
no test coverage detected