Пример #1
0
 /**
  * Create classes from array
  *
  * @param  array $builderData
  * @return void
  */
 public function createClassesFromArray(array $builderData)
 {
     foreach ($builderData as $className => $classInfo) {
         $class = new Builder\PhpClass();
         $class->setName($className);
         foreach ($classInfo as $type => $typeData) {
             switch (strtolower($type)) {
                 case 'supertypes':
                     foreach ($typeData as $superType) {
                         $class->addSuperType($superType);
                     }
                     break;
                 case 'instantiator':
                     $class->setInstantiator($typeData);
                     break;
                 case 'methods':
                 case 'method':
                     foreach ($typeData as $injectionMethodName => $injectionMethodData) {
                         $injectionMethod = new Builder\InjectionMethod();
                         $injectionMethod->setName($injectionMethodName);
                         foreach ($injectionMethodData as $parameterName => $parameterType) {
                             $parameterType = $parameterType ?: null;
                             // force empty string to null
                             $injectionMethod->addParameter($parameterName, $parameterType);
                         }
                         $class->addInjectionMethod($injectionMethod);
                     }
                     break;
             }
         }
         $this->addClass($class);
     }
 }
Пример #2
0
 public function testBuilderCanBuildClassWithMethods()
 {
     $class = new Builder\PhpClass();
     $class->setName('Foo');
     $class->addSuperType('Parent');
     $injectionMethod = new Builder\InjectionMethod();
     $injectionMethod->setName('injectBar');
     $injectionMethod->addParameter('bar', 'Bar');
     $class->addInjectionMethod($injectionMethod);
     $definition = new BuilderDefinition();
     $definition->addClass($class);
     $this->assertTrue($definition->hasClass('Foo'));
     $this->assertEquals('__construct', $definition->getInstantiator('Foo'));
     $this->assertContains('Parent', $definition->getClassSupertypes('Foo'));
     $this->assertTrue($definition->hasMethods('Foo'));
     $this->assertTrue($definition->hasMethod('Foo', 'injectBar'));
     $this->assertContains('injectBar', $definition->getMethods('Foo'));
     $this->assertEquals(array('Foo::injectBar:0' => array('bar', 'Bar', true, null)), $definition->getMethodParameters('Foo', 'injectBar'));
 }