@@ -5,34 +5,23 @@ declare(strict_types=1);
55
66use setasign \PhpStubGenerator \PhpStubGenerator ;
77use setasign \PhpStubGenerator \Reader \AllFiles ;
8+ use setasign \PhpStubGenerator \Reader \SingleFile ;
89use Symfony \Component \Console \Application ;
910use Symfony \Component \Console \Input \InputArgument ;
1011use Symfony \Component \Console \Input \InputInterface ;
1112use Symfony \Component \Console \Input \InputOption ;
1213use Symfony \Component \Console \Output \OutputInterface ;
1314
14- if (version_compare ('7.2 ' , PHP_VERSION , '>= ' )) {
15- fwrite (
16- STDERR ,
17- sprintf (
18- 'This version of php-stub-generator is supported on PHP 7.2. ' . PHP_EOL .
19- 'You are using PHP %s (%s). ' . PHP_EOL ,
20- PHP_VERSION ,
21- PHP_BINARY
22- )
23- );
24-
25- die (1 );
26- }
27-
2815if (!ini_get ('date.timezone ' )) {
2916 ini_set ('date.timezone ' , 'UTC ' );
3017}
3118
32- foreach ([__DIR__ . '/../../../autoload.php ' , __DIR__ . '/../vendor/autoload.php ' ] as $ file ) {
33- if (file_exists ($ file )) {
34- define ('PHP_STUB_GENERATOR_COMPOSER_INSTALL ' , $ file );
35- break ;
19+ if (!defined ('PHP_STUB_GENERATOR_COMPOSER_INSTALL ' )) {
20+ foreach ([__DIR__ . '/../../../autoload.php ' , __DIR__ . '/../vendor/autoload.php ' ] as $ file ) {
21+ if (file_exists ($ file )) {
22+ define ('PHP_STUB_GENERATOR_COMPOSER_INSTALL ' , $ file );
23+ break ;
24+ }
3625 }
3726}
3827
@@ -47,39 +36,51 @@ if (!defined('PHP_STUB_GENERATOR_COMPOSER_INSTALL')) {
4736 die (1 );
4837}
4938
50- /** @noinspection PhpIncludeInspection */
5139require PHP_STUB_GENERATOR_COMPOSER_INSTALL ;
5240
53- /** @noinspection PhpUnhandledExceptionInspection */
54- (new Application ('setasign php-stub-generator ' , 'v1.0.0-dev ' ))
41+ (new Application ('setasign php-stub-generator ' , 'v2.0.0 ' ))
5542->register ('generate ' )
5643 ->setDescription ('Build the stub-file ' )
5744 ->addArgument (
5845 'source ' ,
5946 InputArgument::REQUIRED ,
6047 'The root directory of your library '
6148 )
62- ->addArgument (
63- 'output ' ,
64- InputArgument::REQUIRED ,
65- 'The output file '
66- )
6749 ->addOption (
6850 'exclude ' ,
6951 null ,
7052 InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED ,
7153 'Exclude any directories '
7254 )
55+ ->addOption (
56+ 'resolvingSource ' ,
57+ null ,
58+ InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED ,
59+ 'Additional directory to resolve dependencies but without generating own stubs '
60+ )
61+ ->addArgument (
62+ 'output ' ,
63+ InputArgument::REQUIRED ,
64+ 'The output file '
65+ )
7366 ->addOption (
7467 'addClassConstantsVisibility ' ,
75- false ,
68+ null ,
7669 InputOption::VALUE_NONE ,
7770 'If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1) '
7871 )
72+ ->addOption (
73+ 'includeStringable ' ,
74+ null ,
75+ InputOption::VALUE_NONE ,
76+ 'If enabled the interface \Stringable won \'t be filtered out (the generated stubs require PHP >= 8.0) '
77+ )
7978 ->setCode (function (
8079 InputInterface $ input ,
8180 OutputInterface $ output
8281 ) {
82+ gc_disable ();
83+ // $start = microtime(true);
8384 $ sourceDirectory = $ input ->getArgument ('source ' );
8485 $ outputPath = $ input ->getArgument ('output ' );
8586 $ excludes = $ input ->getOption ('exclude ' );
@@ -94,13 +95,39 @@ require PHP_STUB_GENERATOR_COMPOSER_INSTALL;
9495 }
9596
9697 $ generator = new PhpStubGenerator ();
97- $ generator ->addSource (
98- 'setapdf-core ' ,
99- new AllFiles ($ sourceDirectory , $ excludes )
100- );
98+ if (is_file ($ sourceDirectory )) {
99+ $ generator ->addSource (
100+ 'source ' ,
101+ new SingleFile ($ sourceDirectory )
102+ );
103+ } else {
104+ $ generator ->addSource (
105+ 'source ' ,
106+ new AllFiles ($ sourceDirectory , $ excludes )
107+ );
108+ }
109+
110+ $ additionalSources = $ input ->getOption ('resolvingSource ' );
111+ if (is_array ($ additionalSources )) {
112+ foreach ($ additionalSources as $ k => $ source ) {
113+ if (is_file ($ source )) {
114+ $ generator ->addResolvingSource (
115+ 'rs ' . $ k ,
116+ new SingleFile ($ source )
117+ );
118+ } else {
119+ $ generator ->addResolvingSource (
120+ 'rs ' . $ k ,
121+ new AllFiles ($ source )
122+ );
123+ }
124+ }
125+ }
126+
101127 $ stubs = $ generator ->generate ();
102128 file_put_contents ($ outputPath , $ stubs , LOCK_EX );
103129 $ output ->write ('The stubs were successfully generated to: ' . realpath ($ outputPath ) . PHP_EOL );
130+ // $output->write('Time: ' . microtime(true) - $start . PHP_EOL);
104131 })
105132->getApplication ()
106133->run ();
0 commit comments