@@ -5,34 +5,23 @@ declare(strict_types=1);
5
5
6
6
use setasign \PhpStubGenerator \PhpStubGenerator ;
7
7
use setasign \PhpStubGenerator \Reader \AllFiles ;
8
+ use setasign \PhpStubGenerator \Reader \SingleFile ;
8
9
use Symfony \Component \Console \Application ;
9
10
use Symfony \Component \Console \Input \InputArgument ;
10
11
use Symfony \Component \Console \Input \InputInterface ;
11
12
use Symfony \Component \Console \Input \InputOption ;
12
13
use Symfony \Component \Console \Output \OutputInterface ;
13
14
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
-
28
15
if (!ini_get ('date.timezone ' )) {
29
16
ini_set ('date.timezone ' , 'UTC ' );
30
17
}
31
18
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
+ }
36
25
}
37
26
}
38
27
@@ -47,39 +36,51 @@ if (!defined('PHP_STUB_GENERATOR_COMPOSER_INSTALL')) {
47
36
die (1 );
48
37
}
49
38
50
- /** @noinspection PhpIncludeInspection */
51
39
require PHP_STUB_GENERATOR_COMPOSER_INSTALL ;
52
40
53
- /** @noinspection PhpUnhandledExceptionInspection */
54
- (new Application ('setasign php-stub-generator ' , 'v1.0.0-dev ' ))
41
+ (new Application ('setasign php-stub-generator ' , 'v2.0.0 ' ))
55
42
->register ('generate ' )
56
43
->setDescription ('Build the stub-file ' )
57
44
->addArgument (
58
45
'source ' ,
59
46
InputArgument::REQUIRED ,
60
47
'The root directory of your library '
61
48
)
62
- ->addArgument (
63
- 'output ' ,
64
- InputArgument::REQUIRED ,
65
- 'The output file '
66
- )
67
49
->addOption (
68
50
'exclude ' ,
69
51
null ,
70
52
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED ,
71
53
'Exclude any directories '
72
54
)
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
+ )
73
66
->addOption (
74
67
'addClassConstantsVisibility ' ,
75
- false ,
68
+ null ,
76
69
InputOption::VALUE_NONE ,
77
70
'If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1) '
78
71
)
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
+ )
79
78
->setCode (function (
80
79
InputInterface $ input ,
81
80
OutputInterface $ output
82
81
) {
82
+ gc_disable ();
83
+ // $start = microtime(true);
83
84
$ sourceDirectory = $ input ->getArgument ('source ' );
84
85
$ outputPath = $ input ->getArgument ('output ' );
85
86
$ excludes = $ input ->getOption ('exclude ' );
@@ -94,13 +95,39 @@ require PHP_STUB_GENERATOR_COMPOSER_INSTALL;
94
95
}
95
96
96
97
$ 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
+
101
127
$ stubs = $ generator ->generate ();
102
128
file_put_contents ($ outputPath , $ stubs , LOCK_EX );
103
129
$ output ->write ('The stubs were successfully generated to: ' . realpath ($ outputPath ) . PHP_EOL );
130
+ // $output->write('Time: ' . microtime(true) - $start . PHP_EOL);
104
131
})
105
132
->getApplication ()
106
133
->run ();
0 commit comments