Skip to content

Commit

Permalink
renmaed class MetaData to MetadataInfo and optimized folder structure…
Browse files Browse the repository at this point in the history
…, updated docs
  • Loading branch information
Sandro Keil committed Sep 24, 2014
1 parent fa42460 commit 8dc4d08
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 40 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,19 @@ zf:generate-form [--filter="..."] [--force] [--from-database] [--extend[="..."]]
```

## Console Zend Framework 2

## Generated Classes
At the moment the following classes can be generated:

* ZF2 Form Fieldsets (Collections)
* ZF2 Input Filter

## Known limitations
Unfortunately is it necessary to change some generated code lines by yourself, because some information is currently missing
to make some classes working out of the box.

### Form Fieldsets (Collections)
If you have relations (foreign keys) defined in your entities the `\DoctrineModule\Persistence\ObjectManagerAwareInterface`
must be implemented by yourself. Additionally you must set `property` option for the name of the text which should be
displayed in select box.

19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@
}
},
"require": {
"php": "~5.3",
"zendframework/zend-stdlib": "~2.2",
"zendframework/zend-code": "~2.2"
"php": "~5.4",
"zendframework/zend-stdlib": "~2.3",
"zendframework/zend-code": "~2.3"
},
"require-dev": {
"zendframework/zend-test": "~2.2",
"zendframework/zend-config": "~2.2",
"zendframework/zend-form": "~2.2",
"zendframework/zend-serializer": "~2.2",
"zendframework/zend-log": "~2.2",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-test": "~2.3",
"zendframework/zend-config": "~2.3",
"zendframework/zend-form": "~2.3",
"zendframework/zend-serializer": "~2.3",
"zendframework/zend-log": "~2.3",
"zendframework/zend-modulemanager": "~2.3",
"sandrokeil/citools": "~1.0"
},
"suggest": {
"doctrine/orm": "Doctrine\\ORM if you want to generate classes from doctrine 2",
"symfony/console": "Symfony\\Console if you want to generate classes from doctrine 2",
"zendframework/zend-db": "Zend\\Db if you want to generate classes from zend framework 2 db",
"zendframework/zend-modulemanager": "Zend\\ModuleManager to use default module configuration e.g. services"
}
Expand Down
13 changes: 7 additions & 6 deletions src/Code/Generator/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Sake\CodeGenerator\Code\Generator;

use Sake\CodeGenerator\Code\Metadata\MetadataInfo;
use Zend\Code\Generator\FileGenerator;

/**
Expand Down Expand Up @@ -55,10 +56,10 @@ public function generate(array $metadatas, $outputDirectory)
/**
* Generates and writes class to disk for the given ClassMetadataInfo instance.
*
* @param MetaData $metadata
* @param MetadataInfo $metadata
* @param string $outputDirectory
*/
public function writeClass(MetaData $metadata, $outputDirectory)
public function writeClass(MetadataInfo $metadata, $outputDirectory)
{
$path = $outputDirectory . '/'
. str_replace('\\', DIRECTORY_SEPARATOR, $this->getName($metadata))
Expand Down Expand Up @@ -132,16 +133,16 @@ protected function getIntendation($number = 1)
/**
* Generates class
*
* @param MetaData $metadata
* @param MetadataInfo $metadata
* @return FileGenerator
*/
abstract public function generateClass(MetaData $metadata);
abstract public function generateClass(MetadataInfo $metadata);

/**
* Returns file name for specifc generated type
*
* @param MetaData $metadata
* @param MetadataInfo $metadata
* @return string
*/
abstract public function getName(MetaData $metadata);
abstract public function getName(MetadataInfo $metadata);
}
13 changes: 7 additions & 6 deletions src/Code/Generator/FormGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Sake\CodeGenerator\Code\Generator;

use Sake\CodeGenerator\Code\Metadata\MetadataInfo;
use Zend\Code\Generator\DocBlock\Tag;
use Zend\Code\Generator\DocBlockGenerator;
use Zend\Code\Generator\FileGenerator;
Expand Down Expand Up @@ -39,21 +40,21 @@ class FormGenerator extends AbstractGenerator
/**
* Returns file name for specifc generated type
*
* @param MetaData $metadata
* @param MetadataInfo $metadata
* @return string
*/
public function getName(MetaData $metadata)
public function getName(MetadataInfo $metadata)
{
return 'Form/Fieldset/' . $this->convertName($metadata->getTable('name'));
}

/**
* Generates zend form class
*
* @param MetaData $metadata
* @param MetadataInfo $metadata
* @return FileGenerator
*/
public function generateClass(MetaData $metadata)
public function generateClass(MetadataInfo $metadata)
{
$methods = array($this->getInitMethod($metadata), );

Expand Down Expand Up @@ -104,10 +105,10 @@ public function generateClass(MetaData $metadata)
/**
* Generate form init method which calls add functions.
*
* @param MetaData $metadataInfo
* @param MetadataInfo $metadataInfo
* @return MethodGenerator
*/
protected function getInitMethod(MetaData $metadataInfo)
protected function getInitMethod(MetadataInfo $metadataInfo)
{
$body = '';

Expand Down
20 changes: 7 additions & 13 deletions src/Code/Generator/InputFilterGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Sake\CodeGenerator\Code\Generator;

use Sake\CodeGenerator\Code\Metadata\MetadataInfo;
use Zend\Code\Generator\DocBlockGenerator;
use Zend\Code\Generator\FileGenerator;
use Zend\Code\Generator\ClassGenerator;
Expand Down Expand Up @@ -66,21 +67,21 @@ class InputFilterGenerator extends AbstractGenerator
/**
* Returns file name for specifc generated type
*
* @param MetaData $metadata
* @param MetadataInfo $metadata
* @return string
*/
public function getName(MetaData $metadata)
public function getName(MetadataInfo $metadata)
{
return 'InputFilter/' . $this->convertName($metadata->getTable('name'));
}

/**
* Generate input filter init method which calls add functions.
*
* @param MetaData $metadataInfo
* @param MetadataInfo $metadataInfo
* @return MethodGenerator
*/
protected function getInitMethod(MetaData $metadataInfo)
protected function getInitMethod(MetadataInfo $metadataInfo)
{
$body = '';

Expand All @@ -91,13 +92,6 @@ protected function getInitMethod(MetaData $metadataInfo)
}
$body .= '$this->addElement' . $this->convertName($data['columnName']) . '();' . PHP_EOL;
}
foreach ($metadataInfo->getForeignKeys() as $name => $data) {
// dont add foreign key definition
if (8 === $data['type']) {
continue;
}
$body .= '$this->addElement' . $this->convertName($data['fieldName']) . '();' . PHP_EOL;
}

return new MethodGenerator(
'init',
Expand All @@ -111,10 +105,10 @@ protected function getInitMethod(MetaData $metadataInfo)
/**
* Generates input filter class
*
* @param MetaData $metadata
* @param MetadataInfo $metadata
* @return FileGenerator
*/
public function generateClass(MetaData $metadata)
public function generateClass(MetadataInfo $metadata)
{
$methods = array($this->getInitMethod($metadata));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license http://github.com/sandrokeil/CodeGenerator/blob/master/LICENSE.txt New BSD License
*/

namespace Sake\CodeGenerator\Code\Generator;
namespace Sake\CodeGenerator\Code\Metadata;

use Zend\Stdlib\AbstractOptions;

Expand All @@ -16,7 +16,7 @@
*
* Contains table/entity/class definitions to generate several classes
*/
class MetaData extends AbstractOptions
class MetadataInfo extends AbstractOptions
{
/**
* @var array
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/ORM/Tools/Console/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Sake\CodeGenerator\Doctrine\ORM\Tools\Console\Command;

use Doctrine\ORM\EntityManager;
use Sake\CodeGenerator\Code\Generator\MetaData;
use Sake\CodeGenerator\Code\Metadata\MetadataInfo;
use Sake\CodeGenerator\Hydrator\DoctrineMetadata;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -148,7 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$hydtrator = $this->getHydrator();

foreach ($doctrineMetaData as $data) {
$metaData[$data->name] = new MetaData($hydtrator->extract($data));
$metaData[$data->name] = new MetadataInfo($hydtrator->extract($data));
$output->writeln(
sprintf('Processing class "<info>%s</info>"', $data->name)
);
Expand Down
4 changes: 2 additions & 2 deletions src/Hydrator/DoctrineMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Sake\CodeGenerator\Hydrator;

use Doctrine\ORM\Mapping\MetaData;
use \Doctrine\ORM\Mapping\ClassMetadataInfo;
use Zend\Stdlib\Hydrator\HydratorInterface;
use Sake\CodeGenerator\Exception;

Expand All @@ -28,7 +28,7 @@ class DoctrineMetadata implements HydratorInterface
*/
public function extract($object)
{
if (!$object instanceof MetaData) {
if (!$object instanceof ClassMetadataInfo) {
return array();
}

Expand Down

0 comments on commit 8dc4d08

Please sign in to comment.