Skip to content
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
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"doctrine/migrations": "1.*"
},
"require-dev": {
"illuminate/container": "4.*|5.*",
"illuminate/console": "4.*|5.*",
"mockery/mockery": "dev-master",
"phpunit/phpunit": "3.7.*"
},
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
<testsuite name="all">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
<testsuite name="multiple_configurations">
<directory suffix="Test.php">./tests/MultipleEntityManagersAndConnections/</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 4 additions & 4 deletions src/Console/DqlCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace Mitch\LaravelDoctrine\Console;

use Doctrine\Common\Util\Debug;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

Expand All @@ -28,11 +28,11 @@ class DqlCommand extends Command
*/
private $entityManager;

public function __construct(EntityManagerInterface $entityManager)
public function __construct(ManagerRegistry $registry)
{
parent::__construct();

$this->entityManager = $entityManager;
$this->entityManager = $registry->getManager();
}

public function fire()
Expand All @@ -53,4 +53,4 @@ protected function getOptions()
['hydrate', null, InputOption::VALUE_OPTIONAL, 'Hydrate type. Available: object, array, scalar, single_scalar, simpleobject']
];
}
}
}
37 changes: 26 additions & 11 deletions src/Console/GenerateProxiesCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php namespace Mitch\LaravelDoctrine\Console;

use Illuminate\Console\Command;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\Console\Input\InputOption;

class GenerateProxiesCommand extends Command
{
Expand All @@ -20,37 +21,51 @@ class GenerateProxiesCommand extends Command
protected $description = 'Generate proxies for entities.';

/**
* The Entity Manager
* The ManagerRegistry
*
* @var \Doctrine\ORM\EntityManagerInterface
* @var \Doctrine\Common\Persistence\ManagerRegistry
*/
private $entityManager;
private $registry;

public function __construct(EntityManagerInterface $entityManager)
public function __construct(ManagerRegistry $registry)
{
parent::__construct();

$this->entityManager = $entityManager;
$this->registry = $registry;
}

public function fire()
{
$this->info('Starting proxy generation....');
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();

if ($this->option('em')) {
$manager = $this->registry->getManager($this->option('em'));
} else {
$manager = $this->registry->getManager();
}

$metadata = $manager->getMetadataFactory()->getAllMetadata();
if (empty($metadata)) {
$this->error('No metadata found to generate any entities.');
exit;
}
$directory = $this->laravel['config']['doctrine::doctrine.proxy.directory'];
if ( ! $directory) {
$directory = $manager->getConfiguration()->getProxyDir();
if (! $directory) {
$this->error('The proxy directory has not been set.');
exit;
}
$this->info('Processing entities:');
foreach ($metadata as $item) {
$this->line($item->name);
}
$this->entityManager->getProxyFactory()->generateProxyClasses($metadata, $directory);
$manager->getProxyFactory()->generateProxyClasses($metadata, $directory);
$this->info('Proxies have been created.');
}
}

protected function getOptions()
{
return [
['em', false, InputOption::VALUE_REQUIRED, 'Sets the entity manager when the default is not desired.'],
];
}
}
37 changes: 19 additions & 18 deletions src/Console/SchemaCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Illuminate\Console\Command;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\Console\Input\InputOption;

class SchemaCreateCommand extends Command
Expand All @@ -22,25 +22,17 @@ class SchemaCreateCommand extends Command
protected $description = 'Create database schema from models';

/**
* The schema tool.
* The ManagerRegistry
*
* @var \Doctrine\ORM\Tools\SchemaTool
* @var \Doctrine\Common\Persistence\ManagerRegistry
*/
private $tool;
private $registry;

/**
* The class metadata factory
*
* @var \Doctrine\ORM\Tools\SchemaTool
*/
private $metadata;

public function __construct(SchemaTool $tool, ClassMetadataFactory $metadata)
public function __construct(ManagerRegistry $registry)
{
parent::__construct();

$this->tool = $tool;
$this->metadata = $metadata;
$this->registry = $registry;
}

/**
Expand All @@ -50,21 +42,30 @@ public function __construct(SchemaTool $tool, ClassMetadataFactory $metadata)
*/
public function fire()
{
if ($this->option('em')) {
$manager = $this->registry->getManager($this->option('em'));
} else {
$manager = $this->registry->getManager();
}

$tool = new SchemaTool($manager);

if ($this->option('sql')) {
$this->info('Outputting create query:'.PHP_EOL);
$sql = $this->tool->getCreateSchemaSql($this->metadata->getAllMetadata());
$sql = $tool->getCreateSchemaSql($manager->getMetadataFactory()->getAllMetadata());
$this->info(implode(';'.PHP_EOL, $sql));
} else {
$this->info('Creating database schema...');
$this->tool->createSchema($this->metadata->getAllMetadata());
$tool->createSchema($manager->getMetadataFactory()->getAllMetadata());
$this->info('Schema has been created!');
}
}

protected function getOptions()
{
return [
['sql', false, InputOption::VALUE_NONE, 'Dumps SQL query and does not execute creation.']
['sql', false, InputOption::VALUE_NONE, 'Dumps SQL query and does not execute creation.'],
['em', false, InputOption::VALUE_REQUIRED, 'Sets the entity manager when the default is not desired.'],
];
}
}
}
43 changes: 22 additions & 21 deletions src/Console/SchemaDropCommand.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php namespace Mitch\LaravelDoctrine\Console;
<?php namespace Mitch\LaravelDoctrine\Console;

use Illuminate\Console\Command;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\Console\Input\InputOption;

class SchemaDropCommand extends Command
Expand All @@ -22,25 +22,17 @@ class SchemaDropCommand extends Command
protected $description = 'Drop database schema';

/**
* The schema tool.
*
* @var \Doctrine\ORM\Tools\SchemaTool
*/
private $tool;

/**
* The class metadata factory
*
* @var \Doctrine\ORM\Tools\SchemaTool
*/
private $metadata;
* The ManagerRegistry
*
* @var \Doctrine\Common\Persistence\ManagerRegistry
*/
private $registry;

public function __construct(SchemaTool $tool, ClassMetadataFactory $metadata)
public function __construct(ManagerRegistry $registry)
{
parent::__construct();

$this->tool = $tool;
$this->metadata = $metadata;
$this->registry = $registry;
}

/**
Expand All @@ -50,17 +42,26 @@ public function __construct(SchemaTool $tool, ClassMetadataFactory $metadata)
*/
public function fire()
{
$sql = $this->tool->getDropSchemaSQL($this->metadata->getAllMetadata());
if ($this->option('em')) {
$manager = $this->registry->getManager($this->option('em'));
} else {
$manager = $this->registry->getManager();
}

$tool = new SchemaTool($manager);

$sql = $tool->getDropSchemaSQL($manager->getMetadataFactory()->getAllMetadata());
if (empty($sql)) {
$this->info('Current models do not exist in schema.');
return;
exit;
}
if ($this->option('sql')) {
$this->info('Outputting drop query:');
$sql = $tool->getDropSchemaSQL($manager->getMetadataFactory()->getAllMetadata());
$this->info(implode(';' . PHP_EOL, $sql));
} else {
$this->info('Dropping database schema....');
$this->tool->dropSchema($this->metadata->getAllMetadata());
$tool->dropSchema($manager->getMetadataFactory()->getAllMetadata());
$this->info('Schema has been dropped!');
}
}
Expand All @@ -69,7 +70,7 @@ protected function getOptions()
{
return [
['sql', false, InputOption::VALUE_NONE, 'Dumps SQL query and does not execute drop.'],
['em', false, InputOption::VALUE_REQUIRED, 'Sets the entity manager when the default is not desired.'],
];
}
}

39 changes: 24 additions & 15 deletions src/Console/SchemaUpdateCommand.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php namespace Mitch\LaravelDoctrine\Console;
<?php namespace Mitch\LaravelDoctrine\Console;

use Illuminate\Console\Command;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\Console\Input\InputOption;

class SchemaUpdateCommand extends Command
Expand All @@ -29,18 +29,17 @@ class SchemaUpdateCommand extends Command
private $tool;

/**
* The class metadata factory
*
* @var \Doctrine\ORM\Tools\SchemaTool
*/
private $metadata;
* The ManagerRegistry
*
* @var \Doctrine\Common\Persistence\ManagerRegistry
*/
private $registry;

public function __construct(SchemaTool $tool, ClassMetadataFactory $metadata)
public function __construct(ManagerRegistry $registry)
{
parent::__construct();

$this->tool = $tool;
$this->metadata = $metadata;
$this->registry = $registry;
}

/**
Expand All @@ -52,17 +51,27 @@ public function fire()
{
$this->info('Checking if database needs updating....');
$clean = $this->option('clean');
$sql = $this->tool->getUpdateSchemaSql($this->metadata->getAllMetadata(), $clean);

if ($this->option('em')) {
$manager = $this->registry->getManager($this->option('em'));
} else {
$manager = $this->registry->getManager();
}

$tool = new SchemaTool($manager);

$sql = $tool->getUpdateSchemaSql($manager->getMetadataFactory()->getAllMetadata(), $clean);

if (empty($sql)) {
$this->info('No updates found.');
return;
exit;
}
if ($this->option('sql')) {
$this->info('Outputting update query:');
$this->info(implode(';' . PHP_EOL, $sql));
} else {
$this->info('Updating database schema....');
$this->tool->updateSchema($this->metadata->getAllMetadata());
$tool->updateSchema($manager->getMetadataFactory()->getAllMetadata());
$this->info('Schema has been updated!');
}
}
Expand All @@ -71,8 +80,8 @@ protected function getOptions()
{
return [
['sql', false, InputOption::VALUE_NONE, 'Dumps SQL query and does not execute update.'],
['clean', null, InputOption::VALUE_OPTIONAL, 'When using clean model all non-relevant to this metadata assets will be cleared.']
['clean', null, InputOption::VALUE_OPTIONAL, 'When using clean model all non-relevant to this metadata assets will be cleared.'],
['em', false, InputOption::VALUE_REQUIRED, 'Sets the entity manager when the default is not desired.'],
];
}
}

10 changes: 5 additions & 5 deletions src/DoctrineUserProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace Mitch\LaravelDoctrine;

use Doctrine\ORM\EntityManager;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityRepository;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\UserProviderInterface;
Expand All @@ -13,7 +13,7 @@ class DoctrineUserProvider implements UserProviderInterface
*/
private $hasher;
/**
* @var EntityManager
* @var \Doctrine\ORM\EntityManager
*/
private $entityManager;
/**
Expand All @@ -23,13 +23,13 @@ class DoctrineUserProvider implements UserProviderInterface

/**
* @param HasherInterface $hasher
* @param EntityManager $entityManager
* @param ManagerRegistry $registry
* @param $entity
*/
public function __construct(HasherInterface $hasher, EntityManager $entityManager, $entity)
public function __construct(HasherInterface $hasher, ManagerRegistry $registry, $entity)
{
$this->hasher = $hasher;
$this->entityManager = $entityManager;
$this->entityManager = $registry->getManager();
$this->entity = $entity;
}
/**
Expand Down
Loading