Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-30057: Implemented Schema Exporter, Importer and Builder (#1)
* EZP-30057: Implemented Schema Exporter for custom Doctrine Schema format * EZP-30057: [Tests] Implemented SchemaImporter tests * EZP-30057: Implemented Schema Importer for custom Doctrine Schema format * EZP-30057: [Tests] Implemented SchemaExporter tests * EZP-30057: [Tests] Implemented SchemaBuilder test * EZP-30057: Created DbPlatform Factory of AbstractPlatform instances * EZP-30057: Created EventSubscriber for SQLite session init * EZP-30057: [Bundle] Defined Extension alias and configuration * EZP-30057: Implemented SchemaBuilder extensibility point * [Doc] Updated README.md with brief description of available APIs * Updated type-hinting for DbPlatformFactory * Updated src/lib/Database/DbPlatformFactory.php * Updated type-hinting for SchemaBuilder and impl. of DbPlatform * Updated src/lib/API/Builder/SchemaBuilder.php * Updated src/lib/Database/DbPlatform/PostgreSqlDbPlatform.php * Updated src/lib/Database/DbPlatform/SqliteDbPlatform.php
- Loading branch information
Showing
49 changed files
with
1,809 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
<?php | |||
|
|||
/** | |||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | |||
* @license For full copyright and license information view LICENSE file distributed with this source code. | |||
*/ | |||
declare(strict_types=1); | |||
|
|||
namespace EzSystems\DoctrineSchemaBundle\DependencyInjection; | |||
|
|||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | |||
use Symfony\Component\Config\Definition\ConfigurationInterface; | |||
|
|||
/** | |||
* Symfony extension configuration definition for ez_doctrine_schema extension. | |||
*/ | |||
class Configuration implements ConfigurationInterface | |||
{ | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function getConfigTreeBuilder(): TreeBuilder | |||
{ | |||
$treeBuilder = new TreeBuilder(); | |||
$rootNode = $treeBuilder->root('ez_doctrine_schema'); | |||
|
|||
$rootNode | |||
->children() | |||
->arrayNode('tables') | |||
->children() | |||
->arrayNode('options') | |||
->scalarPrototype() | |||
->end() | |||
->end() | |||
->end() | |||
->end() | |||
->end() | |||
; | |||
|
|||
return $treeBuilder; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,30 @@ | |||
parameters: | |||
ez_doctrine_schema.default_table_options: [] | |||
|
|||
services: | services: | ||
_defaults: | _defaults: | ||
autowire: true | autowire: true | ||
autoconfigure: true | autoconfigure: true | ||
public: false | public: false | ||
_instanceof: | |||
EzSystems\DoctrineSchema\Database\DbPlatform\DbPlatform: | |||
tags: ['doctrine.dbplatform'] | |||
|
|||
EzSystems\DoctrineSchema\Exporter\: | |||
resource: '../../../lib/Exporter/*' | |||
|
|||
EzSystems\DoctrineSchema\Importer\: | |||
resource: '../../../lib/Importer/*' | |||
|
|||
EzSystems\DoctrineSchema\Database\DbPlatformFactory: | |||
arguments: | |||
$dbPlatforms: !tagged doctrine.dbplatform | |||
|
|||
EzSystems\DoctrineSchema\Database\DbPlatform\: | |||
resource: '../../../lib/Database/DbPlatform/*' | |||
|
|||
EzSystems\DoctrineSchema\Builder\SchemaBuilder: | |||
arguments: | |||
$defaultTableOptions: '%ez_doctrine_schema.default_table_options%' | |||
|
|||
Doctrine\Common\EventManager: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,39 @@ | |||
<?php | |||
|
|||
/** | |||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | |||
* @license For full copyright and license information view LICENSE file distributed with this source code. | |||
*/ | |||
declare(strict_types=1); | |||
|
|||
namespace EzSystems\DoctrineSchema\API\Builder; | |||
|
|||
use Doctrine\DBAL\Schema\Schema; | |||
|
|||
/** | |||
* Doctrine\DBAL\Schema event-driven builder. | |||
*/ | |||
interface SchemaBuilder | |||
{ | |||
/** | |||
* Build schema by dispatching the SchemaBuilderEvent event. | |||
* | |||
* To build schema you should implement EventSubscriber subscribing to SchemaBuilderEvents::BUILD_SCHEMA. | |||
* The method handling this event accepts single argument of SchemaBuilderEvent type | |||
* | |||
* @see \EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvent | |||
* @see \EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvents::BUILD_SCHEMA | |||
* | |||
* @return \Doctrine\DBAL\Schema\Schema | |||
*/ | |||
public function buildSchema(): Schema; | |||
|
|||
/** | |||
* Import Schema from Yaml schema definition file into Schema object. | |||
* | |||
* @param string $schemaFilePath | |||
* | |||
* @return \Doctrine\DBAL\Schema\Schema | |||
*/ | |||
public function importSchemaFromFile(string $schemaFilePath): Schema; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
<?php | |||
|
|||
/** | |||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | |||
* @license For full copyright and license information view LICENSE file distributed with this source code. | |||
*/ | |||
declare(strict_types=1); | |||
|
|||
namespace EzSystems\DoctrineSchema\API; | |||
|
|||
use Doctrine\DBAL\Platforms\AbstractPlatform; | |||
|
|||
interface DbPlatformFactory | |||
{ | |||
/** | |||
* Create instance of Doctrine AbstractPlatform for the given driver name. | |||
* | |||
* Factory can return null, which means that the Driver should decide. | |||
* | |||
* @see \Doctrine\DBAL\Platforms\AbstractPlatform | |||
* @see \Doctrine\DBAL\Driver | |||
* | |||
* @param string $driverName (e.g. 'pdo_mysql', 'pdo_pgsql', 'pdo_sqlite'). | |||
* | |||
* @return \Doctrine\DBAL\Platforms\AbstractPlatform|null if null - let the Driver decide | |||
*/ | |||
public function createDatabasePlatformFromDriverName(string $driverName): ?AbstractPlatform; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
<?php | |||
|
|||
/** | |||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | |||
* @license For full copyright and license information view LICENSE file distributed with this source code. | |||
*/ | |||
declare(strict_types=1); | |||
|
|||
namespace EzSystems\DoctrineSchema\API\Event; | |||
|
|||
use Doctrine\DBAL\Schema\Schema; | |||
use EzSystems\DoctrineSchema\API\Builder\SchemaBuilder; | |||
use Symfony\Component\EventDispatcher\Event; | |||
|
|||
class SchemaBuilderEvent extends Event | |||
{ | |||
/** | |||
* @var \EzSystems\DoctrineSchema\API\Builder\SchemaBuilder | |||
*/ | |||
private $schemaBuilder; | |||
|
|||
/** | |||
* @var \Doctrine\DBAL\Schema\Schema | |||
*/ | |||
private $schema; | |||
|
|||
/** | |||
* @param \EzSystems\DoctrineSchema\API\Builder\SchemaBuilder $schemaBuilder | |||
* @param \Doctrine\DBAL\Schema\Schema $schema | |||
*/ | |||
public function __construct(SchemaBuilder $schemaBuilder, Schema $schema) | |||
{ | |||
$this->schemaBuilder = $schemaBuilder; | |||
$this->schema = $schema; | |||
} | |||
|
|||
public function getSchema(): Schema | |||
{ | |||
return $this->schema; | |||
} | |||
|
|||
public function getSchemaBuilder(): SchemaBuilder | |||
{ | |||
return $this->schemaBuilder; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
<?php | |||
|
|||
/** | |||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | |||
* @license For full copyright and license information view LICENSE file distributed with this source code. | |||
*/ | |||
declare(strict_types=1); | |||
|
|||
namespace EzSystems\DoctrineSchema\API\Event; | |||
|
|||
use Symfony\Component\EventDispatcher\Event; | |||
|
|||
class SchemaBuilderEvents extends Event | |||
{ | |||
const BUILD_SCHEMA = 'ez.schema.build_schema'; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
<?php | |||
|
|||
/** | |||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | |||
* @license For full copyright and license information view LICENSE file distributed with this source code. | |||
*/ | |||
declare(strict_types=1); | |||
|
|||
namespace EzSystems\DoctrineSchema\API\Exception; | |||
|
|||
use Exception; | |||
use Throwable; | |||
|
|||
class InvalidConfigurationException extends Exception | |||
{ | |||
public function __construct(string $message = '', int $code = 1, Throwable $previous = null) | |||
{ | |||
parent::__construct("Invalid schema configuration: {$message}", $code, $previous); | |||
} | |||
} |
Oops, something went wrong.