Author: Bulat Shakirzyanov (mallluhuct@gmail.com)
Ejemplo n.º 1
0
 protected function addInterfaceInjector(InterfaceInjector $injector, \DOMElement $parent)
 {
     $interface = $this->document->createElement('interface');
     $interface->setAttribute('class', $injector->getClass());
     $this->addMethodCalls($injector->getMethodCalls(), $interface);
     $parent->appendChild($interface);
 }
 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);
 }
Ejemplo n.º 3
0
 public function testInterfaceInjectors()
 {
     $interfaceInjector = new InterfaceInjector('FooClass');
     $interfaceInjector->addMethodCall('setBar', array('someValue'));
     $container = (include self::$fixturesPath . '/containers/interfaces1.php');
     $container->addInterfaceInjector($interfaceInjector);
     $dumper = new XmlDumper($container);
     $classBody = $dumper->dump();
     //TODO: find a better way to test dumper
     //var_dump($classBody);
     $this->assertEquals("<?xml version=\"1.0\" ?>\n\n<container xmlns=\"http://www.symfony-project.org/schema/dic/services\"\n    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n    xsi:schemaLocation=\"http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd\">\n  <parameters>\n    <parameter key=\"cla\">Fo</parameter>\n    <parameter key=\"ss\">Class</parameter>\n  </parameters>\n  <interfaces>\n    <interface class=\"FooClass\">\n      <call method=\"setBar\">\n        <argument>someValue</argument>\n      </call>\n    </interface>\n  </interfaces>\n  <services>\n    <service id=\"foo\" class=\"%cla%o%ss%\">\n    </service>\n  </services>\n</container>\n", $classBody);
 }
Ejemplo n.º 4
0
 protected function addInterfaceInjector(InterfaceInjector $injector)
 {
     $code = \sprintf("    <interface class=\"%s\">\n", $injector->getClass());
     foreach ($injector->getMethodCalls() as $call) {
         if (count($call[1])) {
             $code .= sprintf("      <call method=\"%s\">\n%s      </call>\n", $call[0], $this->convertParameters($call[1], 'argument', 8));
         } else {
             $code .= sprintf("      <call method=\"%s\" />\n", $call[0]);
         }
     }
     $code .= "    </interface>\n";
     return $code;
 }
Ejemplo n.º 5
0
 public function testInterfaceInjectors()
 {
     $interfaceInjector = new InterfaceInjector('FooClass');
     $interfaceInjector->addMethodCall('setBar', array('someValue'));
     $container = (include self::$fixturesPath . '/containers/interfaces1.php');
     $container->addInterfaceInjector($interfaceInjector);
     $dumper = new XmlDumper($container);
     $classBody = $dumper->dump();
     //TODO: find a better way to test dumper
     //var_dump($classBody);
     $this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<container xmlns=\"http://www.symfony-project.org/schema/dic/services\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd\">\n  <parameters>\n    <parameter key=\"cla\">Fo</parameter>\n    <parameter key=\"ss\">Class</parameter>\n  </parameters>\n  <services>\n    <service id=\"foo\" class=\"%cla%o%ss%\"/>\n  </services>\n  <interfaces>\n    <interface class=\"FooClass\">\n      <call method=\"setBar\">\n        <argument>someValue</argument>\n      </call>\n    </interface>\n  </interfaces>\n</container>\n", $classBody);
     $dom = new \DOMDocument();
     $dom->loadXML($classBody);
     $this->assertTrue($dom->schemaValidate(__DIR__ . '/../../../../../../src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd'));
 }
Ejemplo n.º 6
0
 /**
  * Parses an interface injector.
  *
  * @param string $class
  * @param array $interface
  * @param string $file
  * @return void
  */
 private function parseInterfaceInjector($class, $interface, $file)
 {
     $injector = new InterfaceInjector($class);
     if (isset($interface['calls'])) {
         foreach ($interface['calls'] as $call) {
             $injector->addMethodCall($call[0], $this->resolveServices($call[1]));
         }
     }
     $this->container->addInterfaceInjector($injector);
 }
Ejemplo n.º 7
0
 /**
  * Parses an individual interface injector
  *
  * @param string $class
  * @param SimpleXMLElement $interface
  * @param string $file
  */
 protected function parseInterfaceInjector($class, $interface, $file)
 {
     $injector = new InterfaceInjector($class);
     foreach ($interface->call as $call) {
         $injector->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument'));
     }
     $this->container->addInterfaceInjector($injector);
 }
Ejemplo n.º 8
0
 /**
  * Merges another InterfaceInjector
  *
  * @param InterfaceInjector $injector
  */
 public function merge(InterfaceInjector $injector)
 {
     if ($this->class === $injector->getClass()) {
         foreach ($injector->getMethodCalls() as $call) {
             list($method, $arguments) = $call;
             $this->addMethodCall($method, $arguments);
         }
     }
 }
Ejemplo n.º 9
0
 public function addInterfaceInjector(InterfaceInjector $injector)
 {
     $class = $injector->getClass();
     if (isset($this->injectors[$class])) {
         return $this->injectors[$class]->merge($injector);
     }
     $this->injectors[$class] = $injector;
 }
Ejemplo n.º 10
0
 public function testFrozenContainerInterfaceInjectors()
 {
     $interfaceInjector = new InterfaceInjector('FooClass');
     $interfaceInjector->addMethodCall('setBar', array('someValue'));
     $container = (include self::$fixturesPath . '/containers/interfaces1.php');
     $container->addInterfaceInjector($interfaceInjector);
     $container->compile();
     $dumper = new PhpDumper($container);
     file_put_contents(self::$fixturesPath . '/php/services_interfaces-1-1.php', $dumper->dump());
     $this->assertStringEqualsFile(self::$fixturesPath . '/php/services_interfaces-1-1.php', $dumper->dump(), '->dump() dumps interface injectors');
 }
 public function getInjectorsAndDefinitions()
 {
     $injector = new InterfaceInjector('Symfony\\Tests\\Component\\DependencyInjection\\Service');
     $injector->addMethodCall('method');
     $injector->addMethodCall('method');
     $injector->addMethodCall('method');
     $injector->addMethodCall('method');
     $definition1 = $this->getMockDefinition('stdClass', 0);
     $definition2 = $this->getMockDefinition('Symfony\\Tests\\Component\\DependencyInjection\\Service', 4);
     return array(array($injector, $definition1), array($injector, $definition2));
 }