setasign / php-stub-generator
A tool to generate stub-files for your php classes.
Installs: 1 929
Dependents: 1
Suggesters: 0
Security: 0
Stars: 28
Watchers: 5
Forks: 7
Open Issues: 0
Requires
- php: ^8.2
- ext-mbstring: *
- ext-pcre: *
- roave/better-reflection: ^6.42
- symfony/console: ^6.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- php-defer/php-defer: ^5.0
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2024-11-21 16:44:43 UTC
README
A tool to generate stub-files for your php classes.
The main purpose for this tool is to generate stub-files from php classes to have code completion for your IDE when encrypting your library with e.g. the ioncube encoder.
Installation
A basic installation via Composer could be done this way:
composer require setasign/php-stub-generator
Composer will install the tool to your project's vendor/setasign/php-stub-generator
directory.
Basic usage
<?php declare(strict_types=1); use setasign\PhpStubGenerator\PhpStubGenerator; use setasign\PhpStubGenerator\Reader\AllFiles; require_once __DIR__ . '/vendor/autoload.php'; $generator = new PhpStubGenerator(); $generator->addSource( 'setapdf-core', new AllFiles(__DIR__ . '/vendor/setasign/setapdf-core/library') ); $output = $generator->generate(); file_put_contents(__DIR__ . '/setapdf-core-stub.php', $output);
Alternatively you could just call the cli helper.
vendor/bin/php-stub-generator generate setapdf-core/library setapdf-core-stub.php
Settings
The PhpStubGenerator class has following settings:
class PhpStubGenerator { /** * End of line character(s). * * Doesn't change the used EOL character(s) of doc blocks. * * @var string */ public static $eol = "\n"; /** * Tab character(s) * * @var string */ public static $tab = ' '; /** * If enabled all generated class constants get a visibility (the generated stubs require PHP >= 7.1) * * Within the cli tool can be set with the option "--addClassConstantsVisibility" * * @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
- 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