* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class GenerateCommand extends Command { /** @var \PSX\Api\ListingInterface */ protected $listing; /** @var \PSX\Api\GeneratorFactoryInterface */ protected $factory; /** @var \PSX\Api\Listing\FilterFactoryInterface */ protected $filterFactory; /** * @param \PSX\Api\ListingInterface $listing * @param \PSX\Api\GeneratorFactoryInterface $factory * @param \PSX\Api\Listing\FilterFactoryInterface $filterFactory */ public function __construct( ListingInterface $listing, GeneratorFactoryInterface $factory, FilterFactoryInterface $filterFactory = null, ) { parent::__construct(); $this->listing = $listing; $this->factory = $factory; $this->filterFactory = $filterFactory; } protected function configure() { $this ->setName('api:generate') ->setDescription('Generates for each API resource a file in a specific format') ->addArgument('dir', InputArgument::REQUIRED, 'The target directory') ->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Optional the output format possible values are: ' . implode(', ', GeneratorFactory::getPossibleTypes())) ->addOption('config', 'c', InputOption::VALUE_REQUIRED, 'Optional a config value which gets passed to the generator') ->addOption('filter', 'i', InputOption::VALUE_REQUIRED, 'Optional a specific filter'); } protected function execute(InputInterface $input, OutputInterface $output) { $format = $input->getOption('format'); $config = $input->getOption('config'); $filterName = $input->getOption('filter'); if ($this->filterFactory instanceof FilterFactoryInterface && !empty($filterName)) { $filter = $this->filterFactory->getFilter($filterName); } else { $filter = null; } $dir = $input->getArgument('dir'); if (!is_dir($dir)) { throw new \InvalidArgumentException('Directory does not exist'); } $generator = $this->factory->getGenerator($format, $config); $extension = $this->factory->getFileExtension($format, $config); $output->writeln('Generating ...'); $content = $generator->generate($this->listing->findAll(null, $filter)); if ($content instanceof Chunks) { if (!empty($filterName)) { $file = 'sdk-' . $format . '-' . $filterName . '.zip'; } else { $file = 'sdk-' . $format . '.zip'; } $content->writeTo($dir . '/' . $file); } else { if (!empty($filterName)) { $file = 'output-' . $format . '-' . $filterName . '.' . $extension; } else { $file = 'output-' . $format . '.' . $extension; } file_put_contents($dir . '/' . $file, $content); } $output->writeln('Successful!'); return 0; } } __halt_compiler();----SIGNATURE:----JxNpXK8GFguOmF2ekCtl3IiKQiDAkZYfPa2FzaCwM4MDMmyggWnmrmzmCxrpBhh3TWqG9P0GTehkgwPc52+tLlVN8nNJlrt3aTOHSGaM1iwRbRPSi7+q5Kf3ALA5pNN3gvCN4vB9Oll76N4ER45k1Au1heVcQgxgwu79cuaB8iHYYPo3ACPIRFEZw7fOkopM9xleoBvnr0iB//uTmnah72oQiZFMdWOc1Ifxh9Nl1Ijl7J2rsZDh1jUY16/NL1ctwTUDOzRW6ni3kY38osFvJE3sbn/hsGQLe0dDDYswD7Noz7nNVpYUHhSz5H0eHWTHs3dF8RvKLC8ONo3JD0oUw6Gwal5oK+yv3wcYh55rEvVvR54arpml3Pse8OaofR6vw0SAM553NAcVP9thh9KDoG5IGQzhtrrusqn8Uxt0W9fkNLcMvdKpfcoxTOu6nMIeFUz0LhvriX2UmUVOEBL0unBXxFtr6Ul2uE+jKXLVBewj8lsp1+OibJPuG/OPUPj5lWRo2NOLE2yJ7qfpLCpTgLEwVqiMGB/yuNzL1kCOduKikRirezn6t/6YO/YrKrGY9H0ppzKC0H+zFgkEz8TKjshUNbnBOLN2I6CUJ95ocvFm/vP21gWqBW9yI8LrQh0hiMf04b0zqQtDJzlDGuRsg1ua7Q8mJ/OAdjnXwmRHgA8=----ATTACHMENT:----NjA1MDcwODIyODI5MDM1NyA2NzkxNjcwMjYwMTA2Nzk3IDE4NzQ0ODgwNDQyNjYwNjA=