Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Issue 429 #764

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
"ext-tokenizer": "*",
"ext-ctype": "*",
"ext-mbstring": "*",
"container-interop/service-provider": "^0.4",
"cache/array-adapter": "^1.0.0",
"cache/void-adapter": "^1.0.0",
"cakephp/chronos": "^1.1.4",
"container-interop/service-provider": "^0.4",
"danielstjules/stringy": "^3.0.0",
"doctrine/inflector": "^1.3.0",
"dragonmantank/cron-expression": "^2.1.0",
"egulias/email-validator": "^2.1.0",
"enqueue/null": "^0.8.0",
"jdorn/sql-formatter": "^1.2.17",
"league/flysystem": "^1.0.44",
"monolog/monolog": "^1.24.0",
"narrowspark/arr": "^2.1.0",
Expand Down Expand Up @@ -89,6 +90,10 @@
"viserio/contract": "self.version",
"viserio/cookie": "self.version",
"viserio/cron": "self.version",
"viserio/doctrine-doctrine-provider": "self.version",
"viserio/doctrine-extensions-bridge": "self.version",
"viserio/doctrine-migration-bridge": "self.version",
"viserio/doctrine-testing-bridge": "self.version",
"viserio/events": "self.version",
"viserio/exception": "self.version",
"viserio/filesystem": "self.version",
Expand Down Expand Up @@ -131,6 +136,9 @@
"cache/namespaced-cache": "^1.0",
"cache/session-handler": "^1.0",
"doctrine/dbal": "^2.5",
"doctrine/data-fixtures": "^1.3.1",
"doctrine/migrations": "^2.0.0-beta2",
"doctrine/orm": "^2.6.3",
"enqueue/dbal": "^0.8",
"enqueue/fs": "^0.8",
"enqueue/pheanstalk": "^0.8",
Expand All @@ -139,7 +147,10 @@
"erusev/parsedown": "^1.7",
"erusev/parsedown-extra": "^0.7",
"filp/whoops": "^2.2.0",
"fzaninotto/faker": "^1.8.0",
"gedmo/doctrine-extensions": "^2.4.36",
"guzzlehttp/guzzle": "^6.3.0",
"http-interop/http-factory-tests": "^0.5.0",
"league/flysystem-aws-s3-v3": "^1.0.19",
"league/flysystem-cached-adapter": "^1.0.6",
"league/flysystem-sftp": "^1.0",
Expand All @@ -150,16 +161,16 @@
"mockery/mockery": "^1.2.0",
"mouf/picotainer": "^1.1.0",
"narrowspark/automatic-common": "^0.9.0",
"narrowspark/coding-standard": "^1.4.0",
"narrowspark/testing-helper": "^7.0.0",
"nyholm/nsa": "^1.1",
"pda/pheanstalk": "^3.1",
"php-amqplib/php-amqplib": "^2.6",
"phpstan/phpstan-php-parser": "^0.10.0",
"phpunit/phpunit": "^7.5.0",
"http-interop/http-factory-tests": "^0.5.0",
"predis/predis": "^1.0",
"roave/security-advisories": "dev-master",
"spatie/flysystem-dropbox": "^1.0",
"ocramius/proxy-manager": "^2.2.2",
"symfony/phpunit-bridge": "^4.2.0",
"symfony/var-dumper": "^4.2.0",
"symfony/yaml": "^4.2.0",
Expand All @@ -179,7 +190,7 @@
"Viserio\\Provider\\": "src/Viserio/Provider/"
},
"files": [
"src/Viserio/Component/Support/helper.php"
"src/Viserio/Component/Support/helper.php"
],
"exclude-from-classmap": [
"src/Viserio/Component/**/Tests/",
Expand All @@ -196,11 +207,11 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"changelog": "./build/changelog.sh",
"coverage": "phpunit --coverage-html=\"build/logs\"",
"cs": "php-cs-fixer fix",
"phpstan": "phpstan analyse -c phpstan.neon -l 7 src/Viserio --memory-limit=-1",
"test": "phpunit",
"changelog": "./build/changelog.sh"
"test": "phpunit"
},
"support": {
"issues": "https://github.com/narrowspark/framework/issues",
Expand Down
16 changes: 16 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
</php>

<testsuites>
<testsuite name="Narrowspark Bridge Doctrine DBAL Test Suite">
<directory>./src/Viserio/Bridge/Doctrine/DBAL/Tests</directory>
</testsuite>
<testsuite name="Narrowspark Bridge Doctrine Extensions Test Suite">
<directory>./src/Viserio/Bridge/Doctrine/Extensions/Tests</directory>
</testsuite>
<testsuite name="Narrowspark Bridge Doctrine Migration Test Suite">
<directory>./src/Viserio/Bridge/Doctrine/Migration/Tests</directory>
</testsuite>
<testsuite name="Narrowspark Bridge Doctrine ORM Test Suite">
<directory>./src/Viserio/Bridge/Doctrine/ORM/Tests</directory>
</testsuite>
<testsuite name="Narrowspark Bridge Doctrine Testing Test Suite">
<directory>./src/Viserio/Bridge/Doctrine/Testing/Tests</directory>
</testsuite>

<testsuite name="Narrowspark Monolog Bridge Test Suite">
<directory>./src/Viserio/Bridge/Monolog/Tests</directory>
</testsuite>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\Contract\Migration\Exception;

/**
* Exception interface for all exceptions thrown by the component.
*/
interface Exception
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\Contract\Migration\Exception;

use Exception as BaseException;

class ExecutedUnavailableMigrationsException extends BaseException implements Exception
{
/**
* List of unavailable migrations.
*
* @var array
*/
protected $migrations;

/**
* Create a new ExecutedUnavailableMigrationsException instance.
*
* @param array $migrations
*/
public function __construct(array $migrations = [])
{
$this->migrations = $migrations;
}

/**
* Get all unavailable migrations.
*
* @return array
*/
public function getMigrations(): array
{
return $this->migrations;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\Contract\Migration\Exception;

use InvalidArgumentException as BaseInvalidArgumentException;

class InvalidArgumentException extends BaseInvalidArgumentException implements Exception
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\Contract\Migration\Exception;

class MigrationVersionException extends InvalidArgumentException
{
}
27 changes: 27 additions & 0 deletions src/Viserio/Bridge/Doctrine/Contract/Migration/NamingStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\Contract\Migration;

use Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface;

interface NamingStrategy
{
/**
* @param null|string $version
*
* @return string
*/
public function getFilename(?string $version = null): string;

/**
* @param null|string $version
*
* @return string
*/
public function getClassName(?string $version = null): string;

/**
* @return \Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface
*/
public function getFinder(): MigrationFinderInterface;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This is a READ ONLY repository.

Please make your pull request to https://github.com/narrowspark/framework

Thank you for contributing.
82 changes: 82 additions & 0 deletions src/Viserio/Bridge/Doctrine/ORM/AbstractTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\ORM;

use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Type;

abstract class AbstractTable
{
/**
* The name of a table.
*
* @var string
*/
protected $table;

/**
* Create a new table instance.
*
* @param string $table
*/
public function __construct(string $table)
{
$this->table = $table;
}

/**
* Build a new table.
*
* @return \Doctrine\DBAL\Schema\Table
*/
public function build(): Table
{
return new Table(
$this->table,
$this->getColumns(),
$this->getIndices()
);
}

/**
* Create a new table column.
*
* @param string $name
* @param string $type
* @param bool $autoincrement
*
* @return \Doctrine\DBAL\Schema\Column
*/
protected function createColumn(string $name, string $type, bool $autoincrement = false): Column
{
$column = new Column($name, Type::getType($type));
$column->setAutoincrement($autoincrement);

return $column;
}

/**
* @param string $name
* @param array $columns
* @param bool $unique
* @param bool $primary
*
* @return \Doctrine\DBAL\Schema\Index
*/
protected function index(string $name, array $columns, bool $unique = false, bool $primary = false): Index
{
return new Index($name, $columns, $unique, $primary);
}

/**
* @return \Doctrine\DBAL\Schema\Column[]
*/
abstract protected function getColumns(): array;

/**
* @return \Doctrine\DBAL\Schema\Index[]
*/
abstract protected function getIndices(): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\ORM\Commands;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\EntityGenerator;
use LogicException;
use Viserio\Component\Console\Command\Command;

abstract class AbstractDoctrineCommand extends Command
{
/**
* Get a doctrine entity generator.
*
* @return \Doctrine\ORM\Tools\EntityGenerator
*/
protected function getEntityGenerator(): EntityGenerator
{
$entityGenerator = new EntityGenerator();
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->setNumSpaces(4);
$entityGenerator->setAnnotationPrefix('ORM\\');

return $entityGenerator;
}

/**
* Get a doctrine entity manager by symfony name.
*
* @param string $name
* @param null|int $shardId
*
* @return \Doctrine\ORM\EntityManager
*/
protected function getEntityManager(string $name, ?int $shardId = null): EntityManager
{
$manager = $this->container->get('doctrine')->getManager($name);

if ($shardId) {
if (! $manager->getConnection() instanceof PoolingShardConnection) {
throw new LogicException(\sprintf("Connection of EntityManager '%s' must implement shards configuration.", $name));
}

$manager->getConnection()->connect($shardId);
}

return $manager;
}

/**
* Get a doctrine dbal connection by symfony name.
*
* @param string $name
*
* @return \Doctrine\DBAL\Connection
*/
protected function getDoctrineConnection(string $name): Connection
{
return $this->container->get('doctrine')->getConnection($name);
}
}
32 changes: 32 additions & 0 deletions src/Viserio/Bridge/Doctrine/ORM/Configuration/CacheManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Viserio\Bridge\Doctrine\ORM\Configuration;

use Cache\Bridge\Doctrine\DoctrineCacheBridge;
use Doctrine\Common\Cache\Cache;
use Viserio\Component\Cache\CacheManager as BaseCacheManager;

class CacheManager extends BaseCacheManager
{
/**
* {@inheritdoc}
*/
public static function getDimensions(): array
{
return ['viserio', 'doctrine', self::getConfigName()];
}

/**
* {@inheritdoc}
*/
public function createDriver(array $config)
{
$driver = parent::createDriver($config);

if ($driver instanceof Cache) {
return $driver;
}

return new DoctrineCacheBridge($driver);
}
}
Loading