public function notify(\Exception $exception) { if (!$exception instanceof ServiceNotFoundException) { return; } $serviceId = $exception->getId(); $guessedFqcn = $this->guessFqcn($serviceId); $definition = new Definition(); $definition->setClass($guessedFqcn); $containerBuilder = new ContainerBuilder(); $containerBuilder->addDefinitions([$serviceId => $definition]); $dumper = new YamlDumper($containerBuilder); $result = $dumper->dump(); $message = sprintf('Service `%s` missing. Define it in your services.yml:', $serviceId); $this->output->writeln('--- ' . $message . PHP_EOL); $this->output->write($result, true); $errorMessages = ['Service ' . $serviceId . ' was not found.']; $formatter = new FormatterHelper(); $formattedBlock = $formatter->formatBlock($errorMessages, 'error', true); $this->output->writeln(''); $this->output->writeln($formattedBlock); $this->output->writeln(''); $question = sprintf('<question>Do you want to create a specification for %s? (Y/n)</question>', $guessedFqcn); $dialog = new DialogHelper(); if ($dialog->askConfirmation($this->output, $question, true)) { $this->specRunner->runDescCommand($guessedFqcn); } }
public function testInterfaceInjectors() { $interfaceInjector = new InterfaceInjector('FooClass'); $interfaceInjector->addMethodCall('setBar', array('someValue')); $container = (include self::$fixturesPath . '/containers/interfaces1.php'); $container->addInterfaceInjector($interfaceInjector); $dumper = new YamlDumper($container); $classBody = $dumper->dump(); //TODO: find a better way to test dumper //var_dump($classBody); $this->assertEquals("parameters:\n cla: Fo\n ss: Class\n\ninterfaces:\n FooClass:\n calls:\n - [setBar, [someValue]]\n \n\nservices:\n foo:\n class: %cla%o%ss%\n", $classBody); }
public function testAddService() { $container = (include self::$fixturesPath . '/containers/container9.php'); $dumper = new YamlDumper($container); $this->assertEqualYamlStructure(str_replace('%path%', self::$fixturesPath . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR, file_get_contents(self::$fixturesPath . '/yaml/services9.yml')), $dumper->dump(), '->dump() dumps services'); $dumper = new YamlDumper($container = new ContainerBuilder()); $container->register('foo', 'FooClass')->addArgument(new \stdClass()); try { $dumper->dump(); $this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); } catch (\Exception $e) { $this->assertInstanceOf('\\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); $this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources'); } }
private function dump(string $configFile, string $servicesFile) { $container = $this->loadContainer($configFile, $servicesFile); $dumper = null; $dumper = new XmlDumper($container); self::assertNotEmpty($dumper->dump()); $dumper = new YamlDumper($container); self::assertNotEmpty($dumper->dump()); }
/** * @param \Heystack\Core\DependencyInjection\SilverStripe\HeystackSilverStripeContainerBuilder $container * @param stirng $mode * @param bool|void $debug * @return string */ protected function dumpContainer(HeystackSilverStripeContainerBuilder $container, $mode, $debug = false) { $container->compile(); if ($debug) { $dumper = new YamlDumper($container); return $dumper->dump(); } else { $location = $this->heystackBasePath . '/cache/'; if (!file_exists($location)) { mkdir($location, 0777, true); } $class = "HeystackServiceContainer{$mode}"; $dumper = new PhpDumper($container); if (class_exists('Symfony\\Bridge\\ProxyManager\\LazyProxy\\PhpDumper\\ProxyDumper')) { $dumper->setProxyDumper(new ProxyDumper()); } file_put_contents($this->getRealPath($location) . "/{$class}.php", $dumper->dump(['class' => $class, 'base_class' => "Heystack\\Core\\DependencyInjection\\SilverStripe\\HeystackSilverStripeContainer"])); return 'Container generated'; } }
public function testDumpAutowireData() { $container = (include self::$fixturesPath . '/containers/container24.php'); $dumper = new YamlDumper($container); $this->assertStringEqualsFile(self::$fixturesPath . '/yaml/services24.yml', $dumper->dump()); }