Наследование: use trait Transphpile\IO\IO
Пример #1
0
 function assertTranspile($yamlPath)
 {
     $input = new ArrayInput(array());
     $stream = fopen('php://memory', 'rw', false);
     $output = new StreamOutput($stream);
     $symfonyio = new SymfonyIO($input, $output);
     // Load and parse yaml
     $config = Yaml::parse(file_get_contents($yamlPath));
     if (!isset($config['stdout'])) {
         $this->fail('Stdout section not found in $yamlPath');
     }
     if (!isset($config['code'])) {
         $this->fail('Code section not found in $yamlPath');
     }
     // Create temp file for code to transpile
     $tmpPath = tempnam(sys_get_temp_dir(), 'transphpile');
     file_put_contents($tmpPath, "<?php\n" . $config['code']);
     // Transpile code and send to stdout
     $transpiler = new Transpile($symfonyio);
     $transpiler->transpile($tmpPath, '-');
     // unlink tmp file
     unlink($tmpPath);
     // Fetch php5 code written by transpiler
     rewind($stream);
     $php5 = stream_get_contents($stream);
     // Run php5 code
     $process = new PhpProcess($php5);
     $process->run();
     $stdout = $process->getOutput();
     $stderr = $process->getErrorOutput();
     // If we don't define stderr, there should not be any stderr output from our php5 file
     if (!empty($stderr) && !isset($config['stderr'])) {
         $this->fail('Error reported, but no stderr section found in $yamlPath');
     }
     // Check output
     $config['stdout'] = trim($config['stdout']);
     $this->assertRegExp('{' . $config['stdout'] . '}', $stdout, isset($config['name']) ? $config['name'] : "");
     // Check stderr if any
     if (isset($config['stderr'])) {
         $config['stderr'] = trim($config['stderr']);
         if (empty($stderr)) {
             $this->fail('stderr seems empty but should contain an error');
         }
         $this->assertRegExp('{' . $config['stderr'] . '}', $stderr, isset($config['name']) ? $config['name'] : "");
     }
 }
Пример #2
0
 /**
  * Add final anonymous classes to the statements
  *
  * @param array $nodes
  * @return array
  */
 public function afterTraverse(array $nodes)
 {
     // Nothing to do when there are no anonymous classes
     if (NodeStateStack::getInstance()->count('anonClasses') == 0) {
         return $nodes;
     }
     // We must transpile anonymous classes first, as we haven't done this yet
     $traverser = Transpile::getTraverser();
     $anonClassStmts = $traverser->traverse(NodeStateStack::getInstance()->get('anonClasses'));
     // Find hook point for anonymous classes, which must be after declare, namespaces and use-statements, and can
     // before anything else. This might cause issues when anonymous classes implement interfaces that are defined
     // later on.
     $idx = $this->getAnonymousClassHookIndex($nodes);
     // Array_merge the anonymous class statements on the correct position
     $preStmts = array_slice($nodes, 0, $idx);
     $postStmts = array_slice($nodes, $idx);
     $nodes = array_merge($preStmts, $anonClassStmts, $postStmts);
     return $nodes;
 }