Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched from GoaopParserReflection to BetterReflection #14

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install php
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: "8.2"

- name: Install dependencies
run: composer update --dev --no-interaction --prefer-dist --no-progress --no-suggest --ansi
Expand All @@ -32,7 +32,7 @@ jobs:
- name: Install php
uses: shivammathur/setup-php@v2
with:
php-version: "7.4"
php-version: "8.2"

- name: Install dependencies
run: composer update --dev --no-interaction --prefer-dist --no-progress --no-suggest --ansi
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
php: ['8.2', '8.3']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The main purpose for this tool is to generate stub-files from php classes to hav
completion for your IDE when encrypting your library with e.g.
[the ioncube encoder](http://www.ioncube.com/php_encoder.php).

[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%207.3-8892BF.svg)](https://php.net/)
[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%208.2-8892BF.svg)](https://php.net/)
[![License](https://img.shields.io/packagist/l/setasign/php-stub-generator.svg)](https://packagist.org/packages/setasign/php-stub-generator)

## Installation
Expand Down Expand Up @@ -75,12 +75,19 @@ class PhpStubGenerator
* @var bool
*/
public static $addClassConstantsVisibility = false;

/**
* If false the interface \Stringable won't be filtered out (the generated stubs require PHP >= 8.0).
*
* Within the cli tool can be set with the option "--includeStringable"
*
* @var bool
*/
public static bool $includeStringable = false;
}
```

## Drawbacks / TODOs
- Traits are not supported yet and probably won't be because of bugs like [this](https://bugs.php.net/bug.php?id=69180).
The actual reflection api doesn't give enough information to rebuild the conflict resolution block.
Additionally the "declaring class" of imported trait methods is the importing class and not like expected the trait.
## Drawbacks
- Calculated constants or constants that use other constants like \_\_DIR\_\_ will be filled with the values of the
runtime environment.
- Global Functions and Constants are currently ignored
89 changes: 58 additions & 31 deletions bin/php-stub-generator
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,23 @@ declare(strict_types=1);

use setasign\PhpStubGenerator\PhpStubGenerator;
use setasign\PhpStubGenerator\Reader\AllFiles;
use setasign\PhpStubGenerator\Reader\SingleFile;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

if (version_compare('7.2', PHP_VERSION, '>=')) {
fwrite(
STDERR,
sprintf(
'This version of php-stub-generator is supported on PHP 7.2.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
);

die(1);
}

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
define('PHP_STUB_GENERATOR_COMPOSER_INSTALL', $file);
break;
if (!defined('PHP_STUB_GENERATOR_COMPOSER_INSTALL')) {
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
define('PHP_STUB_GENERATOR_COMPOSER_INSTALL', $file);
break;
}
}
}

Expand All @@ -47,39 +36,51 @@ if (!defined('PHP_STUB_GENERATOR_COMPOSER_INSTALL')) {
die(1);
}

/** @noinspection PhpIncludeInspection */
require PHP_STUB_GENERATOR_COMPOSER_INSTALL;

/** @noinspection PhpUnhandledExceptionInspection */
(new Application('setasign php-stub-generator', 'v1.0.0-dev'))
(new Application('setasign php-stub-generator', 'v2.0.0'))
->register('generate')
->setDescription('Build the stub-file')
->addArgument(
'source',
InputArgument::REQUIRED,
'The root directory of your library'
)
->addArgument(
'output',
InputArgument::REQUIRED,
'The output file'
)
->addOption(
'exclude',
null,
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'Exclude any directories'
)
->addOption(
'resolvingSource',
null,
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'Additional directory to resolve dependencies but without generating own stubs'
)
->addArgument(
'output',
InputArgument::REQUIRED,
'The output file'
)
->addOption(
'addClassConstantsVisibility',
false,
null,
InputOption::VALUE_NONE,
'If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1)'
)
->addOption(
'includeStringable',
null,
InputOption::VALUE_NONE,
'If enabled the interface \Stringable won\'t be filtered out (the generated stubs require PHP >= 8.0)'
)
->setCode(function (
InputInterface $input,
OutputInterface $output
) {
gc_disable();
// $start = microtime(true);
$sourceDirectory = $input->getArgument('source');
$outputPath = $input->getArgument('output');
$excludes = $input->getOption('exclude');
Expand All @@ -94,13 +95,39 @@ require PHP_STUB_GENERATOR_COMPOSER_INSTALL;
}

$generator = new PhpStubGenerator();
$generator->addSource(
'setapdf-core',
new AllFiles($sourceDirectory, $excludes)
);
if (is_file($sourceDirectory)) {
$generator->addSource(
'source',
new SingleFile($sourceDirectory)
);
} else {
$generator->addSource(
'source',
new AllFiles($sourceDirectory, $excludes)
);
}

$additionalSources = $input->getOption('resolvingSource');
if (is_array($additionalSources)) {
foreach ($additionalSources as $k => $source) {
if (is_file($source)) {
$generator->addResolvingSource(
'rs' . $k,
new SingleFile($source)
);
} else {
$generator->addResolvingSource(
'rs' . $k,
new AllFiles($source)
);
}
}
}

$stubs = $generator->generate();
file_put_contents($outputPath, $stubs, LOCK_EX);
$output->write('The stubs were successfully generated to: ' . realpath($outputPath) . PHP_EOL);
// $output->write('Time: ' . microtime(true) - $start . PHP_EOL);
})
->getApplication()
->run();
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
],

"require": {
"php": "^7.4 || ^8.0",
"php": "^8.2",
"ext-pcre": "*",
"ext-mbstring": "*",

"goaop/parser-reflection": "^2.1",
"symfony/console": "^4.0"
"roave/better-reflection": "^6.42",
"symfony/console": "^6.0"
},

"require-dev": {
"bamarni/composer-bin-plugin": "^1.8"
"bamarni/composer-bin-plugin": "^1.8",

"phpunit/phpunit": "^11.0",
"php-defer/php-defer": "^5.0"
},

"autoload": {
Expand Down
Loading
Loading