Skip to content

Commit 69fc248

Browse files
Added class constant visibility as cli option
1 parent 6577616 commit 69fc248

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ completion for your IDE when encrypting your library with e.g.
66
[the ioncube encoder](http://www.ioncube.com/php_encoder.php).
77

88
[![Build Status](https://travis-ci.org/Setasign/php-stub-generator.svg?branch=master)](https://travis-ci.org/Setasign/php-stub-generator)
9-
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%207.1-8892BF.svg)](https://php.net/)
9+
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/)
1010
[![License](https://img.shields.io/packagist/l/setasign/php-stub-generator.svg)](https://packagist.org/packages/setasign/php-stub-generator)
1111

1212
## Installation
@@ -44,7 +44,39 @@ file_put_contents(__DIR__ . '/setapdf-core-stub.php', $output);
4444
Alternatively you could just call the cli helper.
4545

4646
```bash
47-
vendor/bin/php-stub-generator generate vendor/setasign/setapdf-core/library setapdf-core-stub.php
47+
vendor/bin/php-stub-generator generate setapdf-core/library setapdf-core-stub.php
48+
```
49+
50+
## Settings
51+
The PhpStubGenerator class has following settings:
52+
```php
53+
class PhpStubGenerator
54+
{
55+
/**
56+
* End of line character(s).
57+
*
58+
* Doesn't change the used EOL character(s) of doc blocks.
59+
*
60+
* @var string
61+
*/
62+
public static $eol = "\n";
63+
64+
/**
65+
* Tab character(s)
66+
*
67+
* @var string
68+
*/
69+
public static $tab = ' ';
70+
71+
/**
72+
* If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1)
73+
*
74+
* Within the cli tool can be set with the option "--addClassConstantsVisibility"
75+
*
76+
* @var bool
77+
*/
78+
public static $addClassConstantsVisibility = false;
79+
}
4880
```
4981

5082
## Drawbacks / TODOs
@@ -53,4 +85,3 @@ vendor/bin/php-stub-generator generate vendor/setasign/setapdf-core/library seta
5385
Additionally the "declaring class" of imported trait methods is the importing class and not like expected the trait.
5486
- Calculated constants or constants that use other constants like \_\_DIR\_\_ will be filled with the values of the
5587
runtime environment.
56-
- At the moment we only support public class constants due to missing support of ReflectionClassConstant in [goaop/parser-reflection](https://github.com/goaop/parser-reflection).

bin/php-stub-generator

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Input\InputOption;
1111
use Symfony\Component\Console\Output\OutputInterface;
1212

13-
if (version_compare('7.1.0', PHP_VERSION, '>=')) {
13+
if (version_compare('7.2', PHP_VERSION, '>=')) {
1414
fwrite(
1515
STDERR,
1616
sprintf(
17-
'This version of php-stub-generator is supported on PHP 7.1.' . PHP_EOL .
17+
'This version of php-stub-generator is supported on PHP 7.2.' . PHP_EOL .
1818
'You are using PHP %s (%s).' . PHP_EOL,
1919
PHP_VERSION,
2020
PHP_BINARY
@@ -69,18 +69,29 @@ require PHP_STUB_GENERATOR_COMPOSER_INSTALL;
6969
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
7070
'Exclude any directories'
7171
)
72+
->addOption(
73+
'addClassConstantsVisibility',
74+
false,
75+
InputOption::VALUE_NONE,
76+
'If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1)'
77+
)
7278
->setCode(function (
7379
InputInterface $input,
7480
OutputInterface $output
7581
) {
7682
$sourceDirectory = $input->getArgument('source');
7783
$outputPath = $input->getArgument('output');
7884
$excludes = $input->getOption('exclude');
85+
$addClassConstantsVisibility = $input->getOption('addClassConstantsVisibility');
7986

8087
if (!is_dir($sourceDirectory)) {
8188
throw new \InvalidArgumentException('Invalid source directory!');
8289
}
8390

91+
if ($addClassConstantsVisibility) {
92+
PhpStubGenerator::$addClassConstantsVisibility = true;
93+
}
94+
8495
$generator = new PhpStubGenerator();
8596
$generator->addSource(
8697
'setapdf-core',

src/PhpStubGenerator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@
1414
class PhpStubGenerator
1515
{
1616
/**
17+
* End of line character(s).
18+
*
19+
* Doesn't change the used EOL character(s) of doc blocks.
20+
*
1721
* @var string
1822
*/
1923
public static $eol = "\n";
2024

2125
/**
26+
* Tab character(s)
27+
*
2228
* @var string
2329
*/
2430
public static $tab = ' ';
2531

2632
/**
33+
* If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1).
34+
*
35+
* Within the cli tool can be set with the option "--addClassConstantsVisibility"
36+
*
2737
* @var bool
2838
*/
2939
public static $addClassConstantsVisibility = false;

0 commit comments

Comments
 (0)