Skip to content

davidkalosi/dto-generator-bundle

Repository files navigation

DTOGeneratorBundle

DTO Generator Bundle for Symfony 2.

The bundle provides an intuitive interface to generate Data Transfer Objects (DTOs). Features include:

  • Interactive and non-interactive modes
  • DTO assembler skeleton generation
  • Configurable root directory
  • Implemented as a Symfony command

Usage

Usage:
 geckolibs:dto:generate [--dto="..."] [--properties="..."] [--root[="..."]] [--with-assembler]

Options:
 --dto                 The DTO class name to be generated
 --properties          The properties of the newly created DTO
 --root                The root directory for DTO classes, defaults to Model (default: "Model")
 --with-assembler      Weather a Assembler class skeleton shoud be generated
 --help (-h)           Display this help message.

Example Code Generation

Executing the following command

php app/console geckolibs:dto:generate --dto="AcmeDemoBundle:SampleDTO" 
--properties="id:string name:string createdAt:\DateTime" --with-assembler

will generate the a DTO object names Acme\DemoBundle\Model\SampleDTO.php with the following content:

<?php

namespace Acme\DemoBundle\Model;

/**
 * Generated by GeckoLibs DTO generator 
 */
class SampleDTO
{
    private $name = NULL;
    private $id = NULL;
    private $createdAt = NULL;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return \DateTime
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * @param string
     * @param string
     * @param \DateTime
     */
    public function __construct($id, $name, \DateTime $createdAt)
    {
        $this->id = $id;
        $this->name = $name;
        $this->createdAt = $createdAt;
    }
}

In addition a skeleton assembler class named Acme\DemoBundle\Model\SampleDTOAssembler.php will be generated with the following content:

<?php

namespace Acme\DemoBundle\Model;

/**
 * Generated by GeckoLibs DTO generator 
 */
class SampleDTOAssembler
{
    /** 
     * @param $object mixed
     * @return \Acme\DemoBundle\Model\SampleDTO 
     */
    public function createDTO($object)
    {
    }
}

About

DTO Generator Bundle for Symfony 2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages