fromArray() public static method

Generate from array
public static fromArray ( array $array ) : self
$array array
return self
 /**
  * {@inheritdoc}
  */
 public function visit(Entity $entity)
 {
     $name = $entity->getName();
     $namespace = $entity->getNamespace();
     $shortDescription = 'Protobuf extension : ' . $entity->getClass();
     $class = ClassGenerator::fromArray(['name' => $name, 'namespacename' => $namespace, 'implementedinterfaces' => ['\\Protobuf\\Extension'], 'properties' => $this->generateFields($entity), 'methods' => $this->generateMethods($entity), 'docblock' => ['shortDescription' => $shortDescription]]);
     $entity->setContent($this->generateFileContent($class, $entity));
 }
Ejemplo n.º 2
0
 public function generate()
 {
     $class = ClassGenerator::fromArray($this->getClassArrayRepresentation());
     $class->addUse($this->useTableGatewayClass)->addUse('Zend\\Db\\TableGateway\\Feature')->addUse('Zend\\Db\\Sql\\Expression')->addUse($this->data['_namespace'] . '\\Entity\\Entity')->addUse('Pimple\\Container')->addUse('Zend\\Db\\Adapter\\Adapter');
     $this->defineFileInfo($class);
     $fileGenerator = $this->getFileGenerator();
     return $fileGenerator->setClass($class)->generate();
 }
 /**
  * {@inheritdoc}
  */
 public function visit(Entity $entity)
 {
     $name = $entity->getName();
     $namespace = $entity->getNamespace();
     $descriptor = $entity->getDescriptor();
     $shortDescription = 'Protobuf message : ' . $entity->getClass();
     $class = ClassGenerator::fromArray(['name' => $name, 'namespacename' => $namespace, 'extendedClass' => '\\Protobuf\\AbstractMessage', 'docblock' => ['shortDescription' => $shortDescription]]);
     foreach ($this->generators as $generator) {
         $generator->visit($entity, $class);
     }
     $entity->setContent($this->generateFileContent($class, $entity));
 }
Ejemplo n.º 4
0
 public static function fromArray(array $values)
 {
     $fileGenerator = new static();
     foreach ($values as $name => $value) {
         switch ($name) {
             case 'filename':
                 $fileGenerator->filename = $value;
                 continue;
             case 'class':
                 $fileGenerator->setClass($value instanceof ClassGenerator ?: ClassGenerator::fromArray($value));
                 continue;
             default:
                 if (property_exists($fileGenerator, $name)) {
                     $fileGenerator->{$name} = $value;
                 } elseif (method_exists($fileGenerator, 'set' . $name)) {
                     $fileGenerator->{'set' . $name}($value);
                 }
         }
     }
     return $fileGenerator;
 }
Ejemplo n.º 5
0
 /**
  * @param  array|string|ClassGenerator $class
  * @throws Exception\InvalidArgumentException
  * @return FileGenerator
  */
 public function setClass($class)
 {
     if (is_array($class)) {
         $class = ClassGenerator::fromArray($class);
     } elseif (is_string($class)) {
         $class = new ClassGenerator($class);
     } elseif (!$class instanceof ClassGenerator) {
         throw new Exception\InvalidArgumentException(sprintf('%s is expecting either a string, array or an instance of %s\\ClassGenerator', __METHOD__, __NAMESPACE__));
     }
     // @todo check for dup here
     $className = $class->getName();
     $this->classes[$className] = $class;
     return $this;
 }
    public function testCreateFromArrayWithDocBlockInstance()
    {
        $classGenerator = ClassGenerator::fromArray(array(
            'name' => 'SampleClass',
            'docblock' => new DocBlockGenerator('foo'),
        ));

        $docBlock = $classGenerator->getDocBlock();
        $this->assertInstanceOf('Zend\Code\Generator\DocBlockGenerator', $docBlock);
    }
Ejemplo n.º 7
0
    public function testToString()
    {
        $classGenerator = new ClassGenerator(
            'SampleClass',
            null,
            ClassGenerator::FLAG_ABSTRACT,
            'ExtendedClassName',
            array('Iterator', 'Traversable'),
            array('foo', 'bar'),
            array('baz')
        );


        $classGenerator = ClassGenerator::fromArray(
            array(
            'name' => 'SampleClass',
            //'abstract' => true,
            'flags' => ClassGenerator::FLAG_ABSTRACT,
            'name' => 'SampleClass',
            'extendedClass' => 'ExtendedClassName',
            'implementedInterfaces' => array('Iterator', 'Traversable'),
            'properties' => array('foo',
                array('name' => 'bar')
                ),
            'methods' => array(
                array('name' => 'baz')
                ),
            ));


        $expectedOutput = <<<EOS
abstract class SampleClass extends ExtendedClassName implements Iterator, Traversable
{

    public \$foo = null;

    public \$bar = null;

    public function baz()
    {
    }


}

EOS;

        $output = $classGenerator->generate();
        $this->assertEquals($expectedOutput, $output, $output);
    }
Ejemplo n.º 8
0
 /**
  * setClass()
  *
  * @param  array|string|ClassGenerator $class
  * @return FileGenerator
  */
 public function setClass($class)
 {
     if (is_array($class)) {
         $class = ClassGenerator::fromArray($class);
         $className = $class->getName();
     }
     if (is_string($class)) {
         $class = new ClassGenerator($class);
     }
     if (!$class instanceof ClassGenerator) {
         throw new Exception\InvalidArgumentException('setClass() is expecting either a string, array or an instance of Zend\\Code\\Generator\\ClassGenerator');
     }
     $className = $class->getName();
     // @todo check for dup here
     $className = $class->getName();
     $this->classes[$className] = $class;
     return $this;
 }
Ejemplo n.º 9
0
 public function generate()
 {
     $class = ClassGenerator::fromArray($this->getClassArrayRepresentation());
     $this->defineFileInfo($class);
     return $this->fileGenerator->setClass($class)->generate();
 }
Ejemplo n.º 10
0
 /**
  *
  * @return type
  */
 public function generate()
 {
     $class = ClassGenerator::fromArray($this->getClassArrayRepresentation());
     $class->addUse($this->data['_namespace'] . '\\Entity\\Entity');
     $this->defineFileInfo($class);
     $fileGenerator = $this->getFileGenerator();
     return $fileGenerator->setClass($class)->generate();
 }
Ejemplo n.º 11
0
 /**
  *
  * @return type
  */
 public function generate()
 {
     $class = ClassGenerator::fromArray($this->getClassArrayRepresentation());
     $class->addUse($this->data['_namespace'] . '\\Table\\Manager')->addUse('Zend\\Db\\Adapter\\Adapter')->addUse($this->data['_namespace'] . '\\Entity\\Entity')->addUse($this->data['_namespace'] . '\\Entity\\' . $this->data['_className'], $this->data['_className'] . 'Entity');
     $this->defineFileInfo($class);
     $fileGenerator = $this->getFileGenerator();
     return $fileGenerator->setClass($class)->generate();
 }