Beispiel #1
0
 /**
  * @dataProvider getSchemas
  */
 public function testGenerateSchema(SchemaDescriptor $schema, array $files)
 {
     $response = $this->generator->generateSchema($schema);
     $this->assertInstanceOf('Gdbots\\Pbjc\\Generator\\GeneratorResponse', $response);
     $this->assertCount(count($files), $response->getFiles());
     foreach ($response->getFiles() as $path => $outputFile) {
         $this->assertEquals($files[$path], $outputFile->getContents());
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function render($template, array $parameters)
 {
     $code = parent::render($template, $parameters);
     // use statements: removed duplicate
     if (preg_match_all('/\\nuse\\s(.*);/', $code, $matches) !== false) {
         $unique = array_unique($matches[1]);
         foreach ($matches[1] as $match) {
             if (in_array($match, $unique)) {
                 unset($unique[array_search($match, $unique)]);
             } else {
                 $code = preg_replace(sprintf("/\nuse\\s%s;/", str_replace('\\', '\\\\', $match)), '', $code, 1);
             }
         }
     }
     // use statements: sorting
     if (preg_match_all('/\\nuse\\s(.*);/', $code, $matches) !== false) {
         $unique = array_unique($matches[1]);
         asort($unique);
         $unique = array_values($unique);
         foreach ($matches[1] as $key => $match) {
             $from = sprintf("\nuse %s;", $match);
             $to = sprintf("\nuse %s[use_tmp];", $unique[$key]);
             $code = str_replace($from, $to, $code);
         }
         $code = preg_replace("/\\[use_tmp\\];/", ';', $code);
     }
     // generate replacements
     $code = str_replace([';;', "\n\n\n", "{\n\n", "{\n    \n}", "}\n\n}"], [';', "\n\n", "{\n", "{\n}", "}\n}"], $code);
     return $code;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 protected function render($template, array $parameters)
 {
     return str_replace(['    ', '\\/'], ['  ', '/'], json_encode(json_decode(str_replace(["\n", '  ', ', }', ', ]', ',}', ',]', ': INF', ': NAN'], ['', '', '}', '}', '}', ']', ': "INF"', ': "NAN"'], parent::render($template, $parameters))), JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT));
 }