$test_namespace = $namespace . '\\test'; // the use string for the test cases $use = '\\' . $namespace . '\\' . $className; $conf_target_dir = $parser->getTargetDir(); $target_dir = $base_dir . '/' . $conf_target_dir . '/' . $className . '/'; $target_test_dir = $target_dir . '/test/'; checkDirExists($target_dir); checkDirExists($target_test_dir); $operations = $parser->getOperations(); $queries = $parser->getQueries(); $states = $parser->getStates(); $generator = new InterfaceGenerator(); $generator->generate($namespace, $operations, $interfaceName, $target_dir); $generator = new TransitionExceptionGenerator(); $generator->generate($namespace, $target_dir); $generator = new AbstractStateClassGenerator(); $generator->generate($namespace, $operations, $abstractClassName, $interfaceName, $target_dir); $generator = new ClassGenerator(); $generator->generate($namespace, $operations, $states, $className, $interfaceName, $target_dir); $codeGenerator = new StateClassGenerator(); $testGenerator = new TestGenerator(); // namespace of the class to be tested foreach ($states as $state => $data) { echo "Generating {$className} -> {$state}\n"; $codeGenerator->generate($namespace, $data, $state, $abstractClassName, $target_dir); $testGenerator->generate($use, $namespace, $test_namespace, $data, $operations, $queries, $states, $state, $className, $abstractClassName, $target_test_dir); } echo "===========================================\n"; } echo "Done\n"; echo "===========================================\n";
#!/usr/bin/env php <?php if (!file_exists(__DIR__ . '/../vendor/autoload.php')) { die('You need to set up the project dependencies using the following commands:' . PHP_EOL . 'wget https://getcomposer.org/composer.phar' . PHP_EOL . 'php composer.phar install' . PHP_EOL); } require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/autoload.php'; $parser = new SpecificationParser(new SpecificationFilename()); $className = $parser->getClassName(); $abstractClassName = $parser->getAbstractClassName(); $interfaceName = $parser->getInterfaceClassName(); $operations = $parser->getOperations(); $queries = $parser->getQueries(); $states = $parser->getStates(); $generator = new InterfaceGenerator(); $generator->generate($operations, $interfaceName); $generator = new AbstractStateClassGenerator(); $generator->generate($operations, $abstractClassName, $interfaceName); $generator = new ClassGenerator(); $generator->generate($operations, $states, $className, $interfaceName); $codeGenerator = new StateClassGenerator(); $testGenerator = new TestGenerator(); foreach ($states as $state => $data) { $codeGenerator->generate($data, $state, $abstractClassName); $testGenerator->generate($data, $operations, $queries, $states, $state, $className, $abstractClassName); }