[Tip]How to use External Tools to generate Doctrine Getters and Setters

0 votes
asked Jul 9, 2014 in How To & Manuals by Martin Freki Stradej Skipper developer (74,840 points)

Getters and Setters are generated by Doctrine tools. In order to avoid duplication of the functionality, Skipper will not contain this feature as one of its core functions.

But because of the large interest for this functionality, we have prepared a workaround how to configure External tools to generate Getters and Setters in one click, for this see the answer below.

This was prepared thanks to renaatdemuynck and his Doctrine export schema tutorial.

2 Answers

0 votes
answered Jul 9, 2014 by Martin Freki Stradej Skipper developer (74,840 points)
edited Jul 22, 2014 by Martin Freki Stradej
 
Best answer

How to generate Getters and Setters using Skipper External Tools

1./ Install Doctrine2 (it's not even necessary to set up a complete project)

2./ Create an entry in 'External Tools':
* Title:
Generate Getters and Setters
* Command:
cmd /C php "C:/WAMP/www/doctrine2-master/bin/doctrine.php"
* Arguments:
orm:generate-entities --update-entities="true" --generate-methods="true" [path to your entities]"
* Initial Directory:
%PROJECT_DIRECTORY%

3./ Create a Doctrine config file (cli-config.php) in your project's main folder:

<?php
require_once "vendor/autoload.php";

// The path to your entities generated by skipper18
$entityPath = array(__DIR__."/Entities");

$config = Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($entityPath, true);
$config->setMetadataDriverImpl(
    new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
        new Doctrine\Common\Annotations\CachedReader(
            new Doctrine\Common\Annotations\AnnotationReader(),
            new Doctrine\Common\Cache\ArrayCache()
        ),
        $entityPath
    )
);

$connectionOptions = array(
    'driver' => 'pdo_sqlite',
    'path' => 'database.sqlite'
);

$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

$helpers = new Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));

4./ Launching the 'Generate Getters and Setters' External Tool from the Skipper GUI will generate the required methods.

edit: updated the example based on djandyr's feedback

commented Jul 9, 2014 by fiya (220 points)

What should be *nix, mac equivalent of cmd /C php "C:/WAMP/www/doctrine2-master/bin/doctrine.php" and %PROJECT_DIRECTORY% ? Is any pre-defined environment variable required?

commented Jul 9, 2014 by Martin Freki Stradej Skipper developer (74,840 points)

Unix, Mac equivalent would be:

Command: php /var/www/doctrine2-master/bin/doctrine.php

Initial Directory: $PROJECT_DIRECTORY

No environment variable is necessary.

0 votes
answered Jul 16, 2014 by djandyr (150 points)
edited Jul 16, 2014 by djandyr

I experienced "No Metadata classes to process" when using this example on a Symfony2 export, due to the namespaced @ORM/ annotations.

  1. Install Doctrine2, recommend using composer
  2. Create an entry in 'External Tools':

    • Title:
    Generate Getters and Setters
    • Command:
    /tmp/doctrine/vendor/bin/doctrine
    • Arguments:
    orm:generate-entities --update-entities=true --generate-methods=true [path for new entities]
    • Initial Directory:
    /tmp/doctrine

  3. Create a Doctrine config file, cli-config.php in /tmp/doctrine

commented Jul 16, 2014 by ludek.vodicka Skipper developer (140,450 points)

Sorry, I don't understand what is the question. "No metadata classes to process" isn't ORM Designer/Skipper message, so it's probably Doctrine2 error.

Does your settings work correctly if you execute it manually from the shell? Because Skipper doesn't do anything more than executing configured commands in shell.

commented Jul 16, 2014 by djandyr (150 points)

Hi Ludek,

The cli-config.php provided in the first answer is incorrect for Symfony2, as the generate getters and setters external tool fails silently.

When executing manually from the shell "No metadata classes to process" is thrown internally by Doctrine2 CLI. The error is due the entities created by Skipper for Symfony2 projects having namespaced annotations.

I provided a cli-config.php which addresses this issue.

commented Jul 16, 2014 by ludek.vodicka Skipper developer (140,450 points)

Ok, It's a clear now ;-). Thank you for sharing your file.

...