Пример #1
0
 public function testRun()
 {
     $compiler = new Compiler();
     $count = 0;
     $compiler->run('php', new CompileOptions(['namespaces' => ['acme:blog', 'acme:core'], 'output' => __DIR__ . '/../examples/src', 'manifest' => __DIR__ . '/../examples/pbj-schemas.php', 'callback' => function (OutputFile $file) use(&$count) {
         $count++;
     }]));
     $this->assertEquals(15, $count);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $file = $input->getOption('config') ?: sprintf('%s/pbjc.yml', getcwd());
     if (!file_exists($file)) {
         $io->error(sprintf('File "%s" does not exists.', $file));
         return;
     }
     $parser = new Parser();
     $data = $parser->parse(file_get_contents($file));
     if (!is_array($data['namespaces'])) {
         $data['namespaces'] = [$data['namespaces']];
     }
     $io->title('Generated files for namespaces:');
     $io->listing($data['namespaces']);
     // output callback
     $callback = function (OutputFile $file) use($io) {
         $io->text($file->getFile());
         if (!is_dir(dirname($file->getFile()))) {
             mkdir(dirname($file->getFile()), 0777, true);
         }
         file_put_contents($file->getFile(), $file->getContents());
     };
     $languages = [];
     if (isset($data['languages'])) {
         $languages = $data['languages'];
         unset($data['languages']);
     }
     $compile = new Compiler();
     foreach ($languages as $language => $options) {
         if ($input->getOption('language') && $input->getOption('language') != $language) {
             continue;
         }
         $options = array_merge($data, $options, ['callback' => $callback]);
         try {
             $io->section($language);
             $compile->run($language, new CompileOptions($options));
             $io->success("👍");
             //thumbs-up-sign
         } catch (\Exception $e) {
             $io->error($e->getMessage());
         }
     }
 }
Пример #3
0
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../pbj-schema-stores.php';
use Gdbots\Pbjc\Compiler;
use Gdbots\Pbjc\CompileOptions;
use Gdbots\Pbjc\Util\OutputFile;
use Symfony\Component\Yaml\Parser;
$parser = new Parser();
$settings = $parser->parse(file_get_contents(__DIR__ . '/../pbjc.yml'));
$languages = $settings['languages'];
$compiler = new Compiler();
$rootDir = __DIR__ . '/.';
// folder location hack
foreach ($languages as $language => $values) {
    $options = array_merge($settings, $settings['languages'][$language], ['output' => $rootDir . $values['output'], 'callback' => function (OutputFile $file) {
        echo highlight_string($file->getContents(), true) . '<hr />';
        if (!is_dir(dirname($file->getFile()))) {
            mkdir(dirname($file->getFile()), 0777, true);
        }
        file_put_contents($file->getFile(), $file->getContents());
    }]);
    if (isset($values['manifest']) && $values['manifest']) {
        $options['manifest'] = $rootDir . $values['manifest'];
    }
    $compiler->run($language, new CompileOptions($options));
}