|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +use Symfony\Component\Console\Application; |
| 5 | +use Symfony\Component\Console\Input\InputArgument; |
| 6 | +use Symfony\Component\Console\Input\InputOption; |
| 7 | + |
| 8 | +if (version_compare('7.1.0', PHP_VERSION, '>=')) { |
| 9 | + fwrite( |
| 10 | + STDERR, |
| 11 | + sprintf( |
| 12 | + 'This version of php-stub-generator is supported on PHP 7.1.' . PHP_EOL . |
| 13 | + 'You are using PHP %s (%s).' . PHP_EOL, |
| 14 | + PHP_VERSION, |
| 15 | + PHP_BINARY |
| 16 | + ) |
| 17 | + ); |
| 18 | + |
| 19 | + die(1); |
| 20 | +} |
| 21 | + |
| 22 | +if (!ini_get('date.timezone')) { |
| 23 | + ini_set('date.timezone', 'UTC'); |
| 24 | +} |
| 25 | + |
| 26 | +foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) { |
| 27 | + if (file_exists($file)) { |
| 28 | + define('PHP_STUB_GENERATOR_COMPOSER_INSTALL', $file); |
| 29 | + break; |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +if (!defined('PHP_STUB_GENERATOR_COMPOSER_INSTALL')) { |
| 34 | + fwrite( |
| 35 | + STDERR, |
| 36 | + 'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL . |
| 37 | + ' composer install' . PHP_EOL . PHP_EOL . |
| 38 | + 'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL |
| 39 | + ); |
| 40 | + |
| 41 | + die(1); |
| 42 | +} |
| 43 | + |
| 44 | +require PHP_STUB_GENERATOR_COMPOSER_INSTALL; |
| 45 | + |
| 46 | +(new Application('setasign php-stub-generator', 'v0.2.0-alpha')) |
| 47 | +->register('generate') |
| 48 | + ->setDescription('Build the stub-file') |
| 49 | + ->addArgument( |
| 50 | + 'source', |
| 51 | + InputArgument::REQUIRED, |
| 52 | + 'The root directory of your library' |
| 53 | + ) |
| 54 | + ->addArgument( |
| 55 | + 'output', |
| 56 | + InputArgument::REQUIRED, |
| 57 | + 'The output file' |
| 58 | + ) |
| 59 | + ->addOption( |
| 60 | + 'exclude', |
| 61 | + null, |
| 62 | + InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, |
| 63 | + 'Exclude any directories' |
| 64 | + ) |
| 65 | + ->setCode(function ( |
| 66 | + \Symfony\Component\Console\Input\InputInterface $input, |
| 67 | + \Symfony\Component\Console\Output\OutputInterface $output |
| 68 | + ) { |
| 69 | + $sourceDirectory = $input->getArgument('source'); |
| 70 | + $outputPath = $input->getArgument('output'); |
| 71 | + $excludes = $input->getOption('exclude'); |
| 72 | + |
| 73 | + if (!is_dir($sourceDirectory)) { |
| 74 | + throw new \InvalidArgumentException('Invalid source directory!'); |
| 75 | + } |
| 76 | + |
| 77 | + $generator = new \setasign\PhpStubGenerator\PhpStubGenerator(); |
| 78 | + $generator->addSource( |
| 79 | + 'setapdf-core', |
| 80 | + new \setasign\PhpStubGenerator\Reader\AllFiles($sourceDirectory, $excludes) |
| 81 | + ); |
| 82 | + $stubs = $generator->generate(); |
| 83 | + file_put_contents($outputPath, $stubs, LOCK_EX); |
| 84 | + $output->write('The stubs were successfully generated to: ' . realpath($outputPath)); |
| 85 | + }) |
| 86 | +->getApplication() |
| 87 | +->run(); |
0 commit comments