Application.php 962 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace ClassPreloader;
  3. use Symfony\Component\Finder\Finder;
  4. use Symfony\Component\Console\Application as BaseApplication;
  5. /**
  6. * ClassPreloader application CLI
  7. */
  8. class Application extends BaseApplication
  9. {
  10. public function __construct()
  11. {
  12. parent::__construct('ClassPreloader');
  13. // Create a finder to find each non-abstract command in the filesystem
  14. $finder = new Finder();
  15. $finder->files()
  16. ->in(__DIR__ . '/Command')
  17. ->notName('Abstract*')
  18. ->name('*.php');
  19. // Add each command to the CLI
  20. foreach ($finder as $file) {
  21. $filename = str_replace('\\', '/', $file->getRealpath());
  22. $pos = strrpos($filename, '/ClassPreloader/') + strlen('/ClassPreloader/');
  23. $class = __NAMESPACE__ . '\\'
  24. . substr(str_replace('/', '\\', substr($filename, $pos)), 0, -4);
  25. $this->add(new $class());
  26. }
  27. }
  28. }