/** * @param ServiceContainer $container */ private function setupGenerators(ServiceContainer $container) { $container->setShared('code_generator', function (ServiceContainer $c) { $generator = new CodeGenerator\GeneratorManager(); array_map(array($generator, 'registerGenerator'), $c->getByPrefix('code_generator.generators')); return $generator; }); $container->set('code_generator.generators.specification', function (ServiceContainer $c) { $specificationGenerator = new CodeGenerator\Generator\SpecificationGenerator($c->get('console.io'), $c->get('code_generator.templates')); return new CodeGenerator\Generator\NewFileNotifyingGenerator($specificationGenerator, $c->get('event_dispatcher')); }); $container->set('code_generator.generators.class', function (ServiceContainer $c) { $classGenerator = new CodeGenerator\Generator\ClassGenerator($c->get('console.io'), $c->get('code_generator.templates'), null, $c->get('process.executioncontext')); return new CodeGenerator\Generator\NewFileNotifyingGenerator($classGenerator, $c->get('event_dispatcher')); }); $container->set('code_generator.generators.interface', function (ServiceContainer $c) { $interfaceGenerator = new CodeGenerator\Generator\InterfaceGenerator($c->get('console.io'), $c->get('code_generator.templates'), null, $c->get('process.executioncontext')); return new CodeGenerator\Generator\NewFileNotifyingGenerator($interfaceGenerator, $c->get('event_dispatcher')); }); $container->set('code_generator.generators.method', function (ServiceContainer $c) { return new CodeGenerator\Generator\MethodGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->set('code_generator.generators.methodSignature', function (ServiceContainer $c) { return new CodeGenerator\Generator\MethodSignatureGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->set('code_generator.generators.returnConstant', function (ServiceContainer $c) { return new CodeGenerator\Generator\ReturnConstantGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->set('code_generator.generators.named_constructor', function (ServiceContainer $c) { return new CodeGenerator\Generator\NamedConstructorGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->set('code_generator.generators.private_constructor', function (ServiceContainer $c) { return new CodeGenerator\Generator\PrivateConstructorGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->setShared('code_generator.templates', function (ServiceContainer $c) { $renderer = new CodeGenerator\TemplateRenderer(); $renderer->setLocations($c->getParam('code_generator.templates.paths', array())); return $renderer; }); if (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) { $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']; } else { $home = getenv('HOME'); } $container->setParam('code_generator.templates.paths', array(rtrim(getcwd(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.phpspec', rtrim($home, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.phpspec')); }
/** * @param ServiceContainer $container */ protected function setupGenerators(ServiceContainer $container) { $container->setShared('code_generator', function ($c) { $generator = new CodeGenerator\GeneratorManager(); array_map(array($generator, 'registerGenerator'), $c->getByPrefix('code_generator.generators')); return $generator; }); $container->set('code_generator.generators.specification', function ($c) { return new CodeGenerator\Generator\SpecificationGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->set('code_generator.generators.class', function ($c) { return new CodeGenerator\Generator\ClassGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->set('code_generator.generators.method', function ($c) { return new CodeGenerator\Generator\MethodGenerator($c->get('console.io'), $c->get('code_generator.templates')); }); $container->setShared('code_generator.templates', function ($c) { $renderer = new CodeGenerator\TemplateRenderer(); $renderer->setLocations($c->getParam('code_generator.templates.paths', array())); return $renderer; }); if (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) { $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']; } else { $home = $_SERVER['HOME']; } $container->setParam('code_generator.templates.paths', array(rtrim(getcwd(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.phpspec', rtrim($home, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '.phpspec')); }