From da05347ced34aadfea28b7de435b033853ec7001 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:15:42 -0400 Subject: [PATCH 01/39] Implement templates for Attrauzi config building --- .../templates/atrauzzi/cache.blade.php | 4 ++ .../templates/atrauzzi/customTypes.blade.php | 7 ++ .../templates/atrauzzi/dql.blade.php | 21 ++++++ .../master.blade.php | 65 +++++++++++++++---- 4 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php rename src/Console/ConfigMigrations/templates/{mitchell => laraveldoctrine}/master.blade.php (56%) diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php new file mode 100644 index 00000000..73ca37c1 --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php @@ -0,0 +1,4 @@ +[ + 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'env(\'CACHE_DRIVER\','.$cacheProvider.')'}}}, + 'second_level' => false, +], diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php new file mode 100644 index 00000000..a81e3a38 --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php @@ -0,0 +1,7 @@ +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($sourceArray['custom_types']) !== null) + 'custom_types' => [ + @foreach($sourceArray['custom_Types'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif \ No newline at end of file diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php new file mode 100644 index 00000000..f02f69cf --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php @@ -0,0 +1,21 @@ +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_datetime_functions']) !== null) + 'custom_datetime_functions' => [ + @foreach($dql['custom_datetime_functions'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_numeric_functions']) !== null) + 'custom_numeric_functions' => [ + @foreach($dql['custom_numeric_functions'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_string_functions']) !== null) + 'custom_string_functions' => [ + @foreach($dql['custom_string_functions'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif diff --git a/src/Console/ConfigMigrations/templates/mitchell/master.blade.php b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php similarity index 56% rename from src/Console/ConfigMigrations/templates/mitchell/master.blade.php rename to src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php index 54deb948..de6089bd 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/master.blade.php +++ b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php @@ -1,17 +1,20 @@ return [ /* |-------------------------------------------------------------------------- - | Development state + | Entity Mangers |-------------------------------------------------------------------------- | - | If set to false, metadata caching will become active + | Configure your Entity Managers here. You can set a different connection + | and driver per manager and configure events and filters. Change the + | paths setting to the appropriate path and replace App namespace + | by your own namespace. | - */ - 'dev' => config('app.debug'), - /* - |-------------------------------------------------------------------------- - | Entity Mangers - |-------------------------------------------------------------------------- + | Available meta drivers: annotations|yaml|xml|config|static_php + | + | Available connections: mysql|oracle|pgsql|sqlite|sqlsrv + | (Connections can be configured in the database config) + | + | --> Warning: Proxy auto generation should only be enabled in dev! | */ 'managers' => [ @@ -59,37 +62,73 @@ | | Enable/disable Doctrine Extensions by adding or removing them from the list | + | If you want to require custom extensions you will have to require + | laravel-doctrine/extensions in your composer.json + | */ 'extensions' => [ - //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class, + //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class, + //LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class, + //LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class, + //LaravelDoctrine\Extensions\Sluggable\SluggableExtension::class, + //LaravelDoctrine\Extensions\Sortable\SortableExtension::class, + //LaravelDoctrine\Extensions\Tree\TreeExtension::class, + //LaravelDoctrine\Extensions\Loggable\LoggableExtension::class, + //LaravelDoctrine\Extensions\Blameable\BlameableExtension::class, + //LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class, + //LaravelDoctrine\Extensions\Translatable\TranslatableExtension::class ], /* |-------------------------------------------------------------------------- | Doctrine custom types |-------------------------------------------------------------------------- */ + @if(isset($customTypes)) + {{$customTypes}} + @else 'custom_types' => [ 'json' => LaravelDoctrine\ORM\Types\Json::class ], + @endif @if($dqls !== null) {{$dqls}} @endif /* |-------------------------------------------------------------------------- - | Enable Debugbar Doctrine query collection + | Enable query logging with laravel file logging, + | debugbar, clockwork or an own implementation. + | Setting it to false, will disable logging + | + | Available: + | - LaravelDoctrine\ORM\Loggers\LaravelDebugbarLogger + | - LaravelDoctrine\ORM\Loggers\ClockworkLogger + | - LaravelDoctrine\ORM\Loggers\FileLogger |-------------------------------------------------------------------------- */ - 'debugbar' => env('DOCTRINE_DEBUGBAR', false), + 'logger' => env('DOCTRINE_LOGGER', false), /* |-------------------------------------------------------------------------- | Cache |-------------------------------------------------------------------------- | - | By default the Laravel cache setting is used, - | but it's possible to overrule here + | Configure meta-data, query and result caching here. + | Optionally you can enable second level caching. | | Available: acp|array|file|memcached|redis | */ {{$cache}} + /* + |-------------------------------------------------------------------------- + | Gedmo extensions + |-------------------------------------------------------------------------- + | + | Settings for Gedmo extensions + | If you want to use this you will have to require + | laravel-doctrine/extensions in your composer.json + | + */ + 'gedmo' => [ + 'all_mappings' => false + ] ]; From 89b3b2b57f92a570654cfa78a9a1f6632e27f785 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:16:31 -0400 Subject: [PATCH 02/39] Refactor some templates to use escaped single quotes Prevents code from being evaluated when it should just be output as text --- .../ConfigMigrations/templates/mitchell/cache.blade.php | 4 ++-- .../templates/mitchell/manager.blade.php | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php b/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php index 8ec6d8a5..2d5f3a9c 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php +++ b/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php @@ -1,4 +1,4 @@ [ - 'default' => {{{is_null($cacheProvider) ? 'config("cache.default")' : 'config("cache.'.$cacheProvider.'")'}}}, + 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'config(\'cache.'.$cacheProvider.'\')'}}}, 'second_level' => false, -] +], diff --git a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php index 1f32c645..c7837313 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php +++ b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php @@ -1,12 +1,13 @@ [ - 'meta' => '{{{ $isFork ? $data['metadata']['driver'] : 'annotations' }}}', - 'connection' => {{{ $isFork ? '\''.$data['connection'].'\'' : 'config("database.default")' }}}, + 'dev' => env('APP_DEBUG'), + 'meta' => '{{{ $isFork ? $data['metadata']['driver'] : 'env(\'DOCTRINE_METADATA\', \'annotations\')' }}}', + 'connection' => {{{ $isFork ? '\''.$data['connection'].'\'' : 'config(\'database.default\')' }}}, 'paths' => {{ var_export(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['metadata']['paths'], $data['metadata']), true) }}, 'repository' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['repository'], \LaravelDoctrine\ORM\EntityRepository::class) }}}', 'proxies' => [ 'namespace' => {{{ isset($data['proxy']['namespace']) ? '\'' . $data['proxy']['namespace'] .'\'' : 'false' }}}, - 'path' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['directory'], storage_path('proxies')) }}}', - 'auto_generate' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['auto_generate'], env('DOCTRINE_PROXY_AUTOGENERATE', 'false')) }}}' + 'path' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['directory'], 'storage_path(\'proxies\')') }}}', + 'auto_generate' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['auto_generate'], 'env(\'DOCTRINE_PROXY_AUTOGENERATE\', \'false\')') }}}' ], 'events' => [ 'listeners' => [], From d2b539ea4d6ce7db79bd1d7ea66565733ae9a621 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:18:23 -0400 Subject: [PATCH 03/39] Refactor commands with right namespace (and for templates) * Use Console namespace for migrator classes * Refactor master tempalte into it's own namespace for better reuse --- .gitignore | 1 + src/Console/ConfigMigrations/ConfigurationMigrator.php | 2 +- src/Console/ConfigMigrations/MitchellMigrator.php | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ffe6ca2a..b65f6a06 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ composer.lock .DS_Store .php_cs.cache +/tests/Stubs/storage .idea laravel-doctrine-orm.iml \ No newline at end of file diff --git a/src/Console/ConfigMigrations/ConfigurationMigrator.php b/src/Console/ConfigMigrations/ConfigurationMigrator.php index a59cddcd..18e04281 100644 --- a/src/Console/ConfigMigrations/ConfigurationMigrator.php +++ b/src/Console/ConfigMigrations/ConfigurationMigrator.php @@ -1,6 +1,6 @@ viewFactory = $viewFactory; //add namespace for views $this->viewFactory->addNamespace('mitchell', realpath(__DIR__ . '/templates/mitchell')); + $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); } /** @@ -36,6 +37,7 @@ public function convertConfiguration($sourceArray) if ($isFork) { foreach ($sourceArray['entity_managers'] as $key => $manager) { + $manager['proxy'] = $sourceArray['proxy']; $managers[$key] = $this->convertManager($manager, $isFork); } } else { @@ -48,7 +50,7 @@ public function convertConfiguration($sourceArray) $cache = $this->convertCache($sourceArray); - $results = $this->viewFactory->make('mitchell.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls])->render(); + $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); return $unescaped; From 30cefd0d3ae00bb514e66cbc8f663dac6462184d Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:19:05 -0400 Subject: [PATCH 04/39] Implement Atrauzzi config migrator --- .../ConfigMigrations/AtrauzziMigrator.php | 131 ++++++++++++++++++ src/Console/ConvertConfigCommand.php | 73 ++++++++-- 2 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 src/Console/ConfigMigrations/AtrauzziMigrator.php diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php new file mode 100644 index 00000000..27f633bb --- /dev/null +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -0,0 +1,131 @@ +viewFactory = $viewFactory; + //add namespace for views + $this->viewFactory->addNamespace('atruazzi', realpath(__DIR__ . '/templates/atruazzi')); + $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); + } + + /** + * Convert a configuration array from another laravel-doctrine project in to a string representation of a php array configuration for this project + * + * @param array $sourceArray + * @return string + */ + public function convertConfiguration($sourceArray) + { + $dqls = $this->convertDQL($sourceArray['entity_managers']); + $cache = $this->convertCache($sourceArray); + $customTypes = $this->convertCustomTypes($sourceArray); + + $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls, 'customTypes' => $customTypes])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + + return $unescaped; + } + + public function convertManager($sourceArray) + { + $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']); + $defaultRepo = ArrayUtil::get($sourceArray['default_repository']); + + //non default configuration + if (count($sourceArray['metadata']) > 1) { + $isChained = false; + foreach ($sourceArray['metadata'] as $item) { + if (is_array($item)) { + $isChained = true; + } + } + //if it's chained we need to treat each chain as a separate EM + if ($isChained) { + foreach ($sourceArray['metadata'] as $item) { + //convert each chained metadata array EM + } + } //only specifying one non-default EM + else { + //convert metadata array to EM + } + } //one EM, default + else { + + } + } + + protected function getProxySettings($sourceArray) + { + if (isset($sourceArray['proxy_classes'])) { + return [ + 'auto_generate' => ArrayUtil::get($sourceArray['proxy_classes']['auto_generate']), + 'namespace' => ArrayUtil::get($sourceArray['proxy_classes']['namespace']), + 'path' => ArrayUtil::get($sourceArray['proxy_classes']['directory']) + ]; + } else { + return null; + } + } + + public function convertCustomTypes($sourceArray){ + $results = $this->viewFactory->make('atrauzzi.customTypes', ['sourceArray' => $sourceArray])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; + } + + /** + * Convert a cache section from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for a cache section for this project + * + * @param array $sourceArray + * @return string + */ + public function convertCache($sourceArray) + { + if (isset($sourceArray['cache']['provider'])) { + $cacheProvider = ArrayUtil::get($sourceArray['cache']['provider']); + $results = $this->viewFactory->make('atruazzi.cache', [ + 'cacheProvider' => $cacheProvider, + 'extras' => count($sourceArray['cache']) > 1 //if user is mimicking cache arrays here we need to tell them to move these to cache.php + ])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; + } + return null; + + } + + /** + * Convert the dql sections from the entity managers in a configuration from atruazzi/laravel-doctrine into a string representation of a php array configuration for custom string/numeric/datetime functions + * + * Returns null if no dql sections were found. + * + * @param $sourceArray + * @return null|string + */ + public function convertDQL($sourceArray) + { + $results = $this->viewFactory->make('atrauzzi.dql', ['dql' => $sourceArray])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; + } +} \ No newline at end of file diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index 5076cf93..a5b4537e 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -3,10 +3,22 @@ namespace LaravelDoctrine\ORM\Console; use Illuminate\Contracts\View\Factory; +use Illuminate\Filesystem\Filesystem as Filesystem; +use Illuminate\Events\Dispatcher; +use Illuminate\Container\Container as Container; +use Illuminate\Support\Facades\Input; +use Illuminate\View\Compilers\BladeCompiler; +use Illuminate\View\Engines\CompilerEngine; +use Illuminate\View\Engines\EngineResolver; +use Illuminate\View\FileViewFinder; use InvalidArgumentException; -use LaravelDoctrine\ORM\ConfigMigrations\MitchellMigrator; +use LaravelDoctrine\ORM\Console\ConfigMigrations\AtrauzziMigrator; +use LaravelDoctrine\ORM\Console\ConfigMigrations\MitchellMigrator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; class ConvertConfigCommand extends Command { @@ -14,20 +26,32 @@ class ConvertConfigCommand extends Command protected $description = 'Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM.'; - public function fire(Factory $viewFactory) + protected function configure(){ + $this->setName('doctrine:config:convert') + ->setAliases(['doctrine:config:convert']) + ->setDescription('Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM') + ->setDefinition([ + new InputArgument('author', InputArgument::REQUIRED, 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'), + new InputOption('dest-path', null, InputOption::VALUE_OPTIONAL, 'Where the generated configuration should be placed', 'config'), + new InputOption('source-file', null, InputOption::VALUE_OPTIONAL, 'Where the source configuration file is located.','config/doctrine.php') + ]); + } + + public function execute(InputInterface $input, OutputInterface $output) { + //add config templates directory to view locations - $viewFactory->addLocation(realpath(__DIR__ . '/ConfigMigrations/templates')); + //$viewFactory->addLocation(realpath(__DIR__ . '/ConfigMigrations/templates')); - if (($destPath = $this->option('dest-path')) === null) { + if (($destPath = $input->getOption('dest-path')) === null) { $destPath = 'config'; } - if (($author = $this->argument('author')) === null) { + if (($author = $input->getArgument('author')) === null) { throw new InvalidArgumentException('Missing author option'); } - if (($sourceFilePath = $this->option('source-file')) === null) { + if (($sourceFilePath = $input->getOption('source-file')) === null) { $sourceFilePath = 'config/doctrine.php'; } @@ -58,11 +82,13 @@ public function fire(Factory $viewFactory) $sourceArrayConfig = include $sourceFilePath; + $viewFactory = $this->createViewFactory(); + //TODO make this relative switch ($author) { case 'atrauzzi': - //$convertedConfigString = $this->convertAtrauzzi($sourceArrayConfig, $viewFactory); + $convertedConfigString = $this->convertAtrauzzi($sourceArrayConfig, $viewFactory); break; case 'mitchellvanw': $convertedConfigString = $this->convertMitchell($sourceArrayConfig, $viewFactory); @@ -72,7 +98,7 @@ public function fire(Factory $viewFactory) } file_put_contents($destFilePath, 'info('Conversion successful. File generated at ' . $destFilePath); + $output->writeln('Conversion successful. File generated at ' . $destFilePath); } /** @@ -98,7 +124,9 @@ private function convertMitchell($sourceConfig, $viewFactory) */ private function convertAtrauzzi($sourceConfig, $viewFactory) { - //TODO + $aMigrator = new AtrauzziMigrator($viewFactory); + + return $aMigrator->convertConfiguration($sourceConfig); } public function getArguments() @@ -116,4 +144,31 @@ protected function getOptions() ['source-file', null, InputOption::VALUE_OPTIONAL, 'Where the source configuration file is located. Default is config/doctrine.php', 'config/doctrine.php'] ]; } + + protected function createViewFactory(){ + $FileViewFinder = new FileViewFinder( + new Filesystem, + array(realpath(__DIR__ . '/ConfigMigrations/templates')) + ); + + $dispatcher = new Dispatcher(new Container); + + $compiler = new BladeCompiler(new Filesystem(), $this->getCachePath() . '/framework/views'); + $bladeEngine = new CompilerEngine($compiler); + $engineResolver = new EngineResolver(); + $engineResolver->register('blade', function() use(&$bladeEngine){ + return $bladeEngine; + }); + + $viewFactory = new \Illuminate\View\Factory($engineResolver, $FileViewFinder, $dispatcher); + return $viewFactory; + } + + protected function getCachePath(){ + if(!function_exists('storage_path')){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../tests/Stubs/storage'; + } else { + return storage_path(); + } + } } From fd8494b2c48d7d4fecd82d2ff69be0e93b7fc5ec Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:19:34 -0400 Subject: [PATCH 05/39] Implement tests for migrator commands * Include sample code files to run tests on --- .../Migrators/MitchellMigratorTest.php | 30 +++ tests/Stubs/atrauzzi-config-sample.php | 250 ++++++++++++++++++ tests/Stubs/mitchellvanw-config-sample.php | 39 +++ 3 files changed, 319 insertions(+) create mode 100644 tests/Configuration/Migrators/MitchellMigratorTest.php create mode 100644 tests/Stubs/atrauzzi-config-sample.php create mode 100644 tests/Stubs/mitchellvanw-config-sample.php diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Configuration/Migrators/MitchellMigratorTest.php new file mode 100644 index 00000000..d10df5b7 --- /dev/null +++ b/tests/Configuration/Migrators/MitchellMigratorTest.php @@ -0,0 +1,30 @@ +add($mitchellMigrator); + + $command = $application->find('doctrine:config:convert'); + + $commandTester = new CommandTester($command); + $commandTester->execute([ + 'command' => $command->getName(), + 'author' => 'mitchellvanw', + '--source-file' => realpath(__DIR__ . '/../../Stubs/mitchellvanw-config-sample.php'), + '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') + ]); + } +} \ No newline at end of file diff --git a/tests/Stubs/atrauzzi-config-sample.php b/tests/Stubs/atrauzzi-config-sample.php new file mode 100644 index 00000000..6805770a --- /dev/null +++ b/tests/Stubs/atrauzzi-config-sample.php @@ -0,0 +1,250 @@ + [ + + 'driver' => 'config', + + // + // Alternatively, if you want to use a chain, specify multiple drivers as nested arrays. + // + [ + 'driver' => 'config' + ], + [ + 'driver' => 'annotation', + // 'namespace' => 'App' + // 'alias' => 'DoctrineModel' + ], + [ + 'driver'=>'yaml', + ], + [ + 'driver'=>'xml' + ], + [ + 'driver'=>'static' + ] + // + // ...accepting PRs for more! + + ], + /* + + 'mappings' => [ + + 'App\MyModel' => [ + + 'table' => 'my_model', + + 'abstract' => false, + + 'repository' => 'App\Repository\MyModel', + + 'fields' => [ + + 'id' => [ + 'type' => 'integer', + 'strategy' => 'identity' + ], + + 'name' => [ + 'type' => 'string', + 'nullable' => false, + ] + + ], + + 'indexes' => [ + 'name' + ], + + ], + + ], +*/ + /* + * By default, this package mimics the database configuration from Laravel. + * + * You can override it in whole or in part here. The 'database' and 'username' + * laravel settings will be automatically converted to the proper doctrine 'dbname' + * and 'user' settings. Other custom laravel to doctrine mappings can be added on + * a per configuration basis by including a 'mappings' entry with 'laravel'=>'doctrine' + * mappings (see the sqlite configuration for an example). + * + * This array passes right through to the EntityManager factory. For + * example, here you can set additional connection details like "charset". + * + * http://doctrine-dbal.readthedocs.org/en/latest/reference/configuration.html#connection-details + */ + 'connections' => [ + // Override your laravel environment database selection here if desired + // 'default' => 'mysql', + + // Override your laravel values here if desired. + /*'mysql' => [ + 'driver' => 'mysqli', + 'host' => env('DB_HOST', 'localhost'), + 'dbname' => env('DB_DATABASE', 'forge'), + 'user' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'prefix' => '' + ],*/ + + // Some preset configurations to map laravel sqlite configs to doctrine + 'sqlite' => [ + 'driver' => 'pdo_sqlite', + 'mappings' => [ + 'database' => 'path' + ] + ] + + + ], + + /* + | --------------------------------- + | By default, this package mimics the cache configuration from Laravel. + | + | You can create your own cache provider by extending the + | Atrauzzi\LaravelDoctrine\CacheProvider\CacheProvider class. + | + | Each provider requires a like named section with an array of configuration options. + | ---------------------------------- + */ + 'cache' => [ + // Remove or set to null for no cache + 'provider' => env('CACHE_DRIVER', 'array'), + + 'file' => [ + 'directory' => storage_path('framework/cache'), + 'extension' => '.doctrinecache.data' + ], + + 'redis' => [ + 'host' => '127.0.0.1', + 'port' => 6379, + 'database' => 1 + ], + + 'memcache' => [ + 'host' => '127.0.0.1', + 'port' => 11211 + ], + + 'providers' => [ + 'memcache' => Atrauzzi\LaravelDoctrine\CacheProvider\MemcacheProvider::class, + 'memcached' => Atrauzzi\LaravelDoctrine\CacheProvider\MemcachedProvider::class, + 'couchbase' => Atrauzzi\LaravelDoctrine\CacheProvider\CouchbaseProvider::class, + 'redis' => Atrauzzi\LaravelDoctrine\CacheProvider\RedisProvider::class, + 'apc' => Atrauzzi\LaravelDoctrine\CacheProvider\ApcCacheProvider::class, + 'xcache' => Atrauzzi\LaravelDoctrine\CacheProvider\XcacheProvider::class, + 'array' => Atrauzzi\LaravelDoctrine\CacheProvider\ArrayCacheProvider::class, + 'file' => Atrauzzi\LaravelDoctrine\CacheProvider\FilesystemCacheProvider::class, + //'custom' => 'Path\To\Your\Class' + ] + ], + + + /* + |-------------------------------------------------------------------------- + | Sets the directory where Doctrine generates any proxy classes, including + | with which namespace. + |-------------------------------------------------------------------------- + | + | http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html + | + */ + /* + 'proxy_classes' => [ + 'auto_generate' => false, + 'directory' => null, + 'namespace' => null, + ], + */ + + + 'migrations' => [ + 'directory' => '/database/doctrine-migrations', + 'namespace' => 'DoctrineMigrations', + 'table_name' => 'doctrine_migration_versions' + ], + + /* + |-------------------------------------------------------------------------- + | Use to specify the default repository + | http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html#custom-repositories + |-------------------------------------------------------------------------- + */ + /* + 'default_repository' => '\Doctrine\ORM\EntityRepository', + */ + + /* + |-------------------------------------------------------------------------- + | Use to specify the SQL Logger + | To use with \Doctrine\DBAL\Logging\EchoSQLLogger, do: + | 'sqlLogger' => new \Doctrine\DBAL\Logging\EchoSQLLogger(); + | + | http://doctrine-orm.readthedocs.org/en/latest/reference/advanced-configuration.html#sql-logger-optional + |-------------------------------------------------------------------------- + */ + /* + 'sql_logger' => null, + */ + + /* + * In some circumstances, you may wish to diverge from what's configured in Laravel. + */ + //'debug' => false, + + /* + | --------------------------------- + | Add custom Doctrine types here + | For more information: http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types + | --------------------------------- + */ + 'custom_types' => [ + 'json' => 'Atrauzzi\LaravelDoctrine\Type\Json' + ], + + 'custom_datetime_functions' => [ + 'DATEADD' => 'DoctrineExtensions\Query\Mysql\DateAdd', + 'DATEDIFF' => 'DoctrineExtensions\Query\Mysql\DateDiff', + 'DATESUB' => 'DoctrineExtensions\Query\Mysql\DateSub', + 'FROM_UNIXTIME' => 'DoctrineExtensions\Query\Mysql\FromUnixtime' + ], + + 'custom_numeric_functions' => [ + 'ACOS' => 'DoctrineExtensions\Query\Mysql\Acos', + 'ASIN' => 'DoctrineExtensions\Query\Mysql\Asin', + 'ATAN' => 'DoctrineExtensions\Query\Mysql\Atan', + 'ATAN2' => 'DoctrineExtensions\Query\Mysql\Atan2', + 'COS' => 'DoctrineExtensions\Query\Mysql\Cos', + 'COT' => 'DoctrineExtensions\Query\Mysql\Cot', + 'DEGREES' => 'DoctrineExtensions\Query\Mysql\Degrees', + 'RADIANS' => 'DoctrineExtensions\Query\Mysql\Radians', + 'SIN' => 'DoctrineExtensions\Query\Mysql\Sin', + 'TAN' => 'DoctrineExtensions\Query\Mysql\Tan' + ], + + 'custom_string_functions' => [ + 'CHAR_LENGTH' => 'DoctrineExtensions\Query\Mysql\CharLength', + 'CONCAT_WS' => 'DoctrineExtensions\Query\Mysql\ConcatWs', + 'FIELD' => 'DoctrineExtensions\Query\Mysql\Field', + 'FIND_IN_SET' => 'DoctrineExtensions\Query\Mysql\FindInSet', + 'REPLACE' => 'DoctrineExtensions\Query\Mysql\Replace', + 'SOUNDEX' => 'DoctrineExtensions\Query\Mysql\Soundex', + 'STR_TO_DATE' => 'DoctrineExtensions\Query\Mysql\StrToDate', + 'SUBSTRING_INDEX' => 'DoctrineExtensions\Query\Mysql\SubstringIndex' + ], + + 'auth' => [ + //'authenticator' => 'Atrauzzi\LaravelDoctrine\DoctrineAuthenticator', + //'model' => 'App\Models\User', + ] + +]; diff --git a/tests/Stubs/mitchellvanw-config-sample.php b/tests/Stubs/mitchellvanw-config-sample.php new file mode 100644 index 00000000..fe67d882 --- /dev/null +++ b/tests/Stubs/mitchellvanw-config-sample.php @@ -0,0 +1,39 @@ + 'default', + 'entity_managers' => [ + 'default' => [ + 'connection' => 'sqlite', + 'cache_provider' => null, + 'repository' => 'Doctrine\ORM\EntityRepository', + 'simple_annotations' => false, + 'logger' => null, + 'metadata' => [ + 'simple' => false, + 'driver' => 'yaml', + 'paths' => 'app/Models/mappings', + 'extension' => '.dcm.yml' + ], + ], + 'production' => [ + 'connection' => 'mysql', + 'cache_provider' => 'file', + 'repository' => 'Doctrine\ORM\EntityRepository', + 'logger' => null, + 'metadata' => [ + 'simple' => false, + 'driver' => 'yaml', + 'paths' => 'app/Models/mappings', + 'extension' => '.dcm.yml' + ], + ], + ], + 'proxy' => [ + 'auto_generate' => true, + 'directory' => 'storage/proxies', + 'namespace' => null + ], + 'cache_provider' => null, +]; + From c60de73c4cd19f8939c23dc30504366b797a31c1 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:11:55 -0400 Subject: [PATCH 06/39] Modify config sample to include more options --- tests/Stubs/atrauzzi-config-sample.php | 57 +++++++++----------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/tests/Stubs/atrauzzi-config-sample.php b/tests/Stubs/atrauzzi-config-sample.php index 6805770a..6e0052b1 100644 --- a/tests/Stubs/atrauzzi-config-sample.php +++ b/tests/Stubs/atrauzzi-config-sample.php @@ -6,30 +6,26 @@ 'metadata' => [ - 'driver' => 'config', - - // - // Alternatively, if you want to use a chain, specify multiple drivers as nested arrays. - // - [ - 'driver' => 'config' - ], [ 'driver' => 'annotation', - // 'namespace' => 'App' - // 'alias' => 'DoctrineModel' + 'namespace' => 'SysPRO\\Model\\Controller\\Entity', + 'alias' => 'Controller' ], [ - 'driver'=>'yaml', + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Operacoes\\Entity', + 'alias' => 'Operacoes' ], [ - 'driver'=>'xml' + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Parametros\\Entity', + 'alias' => 'Parametros' ], [ - 'driver'=>'static' + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Sistema\\Entity', + 'alias' => 'Sistema' ] - // - // ...accepting PRs for more! ], /* @@ -66,20 +62,7 @@ ], */ - /* - * By default, this package mimics the database configuration from Laravel. - * - * You can override it in whole or in part here. The 'database' and 'username' - * laravel settings will be automatically converted to the proper doctrine 'dbname' - * and 'user' settings. Other custom laravel to doctrine mappings can be added on - * a per configuration basis by including a 'mappings' entry with 'laravel'=>'doctrine' - * mappings (see the sqlite configuration for an example). - * - * This array passes right through to the EntityManager factory. For - * example, here you can set additional connection details like "charset". - * - * http://doctrine-dbal.readthedocs.org/en/latest/reference/configuration.html#connection-details - */ + 'connections' => [ // Override your laravel environment database selection here if desired // 'default' => 'mysql', @@ -117,13 +100,13 @@ */ 'cache' => [ // Remove or set to null for no cache - 'provider' => env('CACHE_DRIVER', 'array'), + 'provider' => 'array', 'file' => [ - 'directory' => storage_path('framework/cache'), + 'directory' => 'framework/cache', 'extension' => '.doctrinecache.data' ], - + 'redis' => [ 'host' => '127.0.0.1', 'port' => 6379, @@ -158,13 +141,13 @@ | http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html | */ - /* + 'proxy_classes' => [ 'auto_generate' => false, 'directory' => null, 'namespace' => null, ], - */ + 'migrations' => [ @@ -179,9 +162,9 @@ | http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html#custom-repositories |-------------------------------------------------------------------------- */ - /* + 'default_repository' => '\Doctrine\ORM\EntityRepository', - */ + /* |-------------------------------------------------------------------------- @@ -199,7 +182,7 @@ /* * In some circumstances, you may wish to diverge from what's configured in Laravel. */ - //'debug' => false, + 'debug' => false, /* | --------------------------------- From 21b162b7a85ca27fee89f5745d6adf520c37d759 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:12:31 -0400 Subject: [PATCH 07/39] Bug fixes and manager section implementation for atrauzzi migrator --- .../ConfigMigrations/AtrauzziMigrator.php | 76 ++++++++++++------- .../templates/atrauzzi/cache.blade.php | 2 +- .../templates/atrauzzi/customTypes.blade.php | 4 +- .../templates/atrauzzi/dql.blade.php | 6 +- .../templates/atrauzzi/manager.blade.php | 28 +++++++ 5 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php index 27f633bb..c60cb4f2 100644 --- a/src/Console/ConfigMigrations/AtrauzziMigrator.php +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -24,7 +24,7 @@ public function __construct(Factory $viewFactory) { $this->viewFactory = $viewFactory; //add namespace for views - $this->viewFactory->addNamespace('atruazzi', realpath(__DIR__ . '/templates/atruazzi')); + $this->viewFactory->addNamespace('atrauzzi', realpath(__DIR__ . '/templates/atrauzzi')); $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); } @@ -36,9 +36,10 @@ public function __construct(Factory $viewFactory) */ public function convertConfiguration($sourceArray) { - $dqls = $this->convertDQL($sourceArray['entity_managers']); + $dqls = $this->convertDQL($sourceArray); $cache = $this->convertCache($sourceArray); $customTypes = $this->convertCustomTypes($sourceArray); + $managers = [$this->convertManager($sourceArray)]; $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls, 'customTypes' => $customTypes])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); @@ -50,41 +51,64 @@ public function convertManager($sourceArray) { $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']); $defaultRepo = ArrayUtil::get($sourceArray['default_repository']); + $namespaces = []; + $driver = null; + $connection = ArrayUtil::get($sourceArray['default']); //non default configuration if (count($sourceArray['metadata']) > 1) { - $isChained = false; - foreach ($sourceArray['metadata'] as $item) { - if (is_array($item)) { - $isChained = true; + $hasNamespaces = false; + $index = 0; + $driver = null; + $sameDriver = true; + + foreach ($sourceArray['metadata'] as $key => $item) { + //get first driver + if(is_null($driver)){ + if(is_array($item)){ + $driver = $item['driver']; + } else if($key == 'driver') { + $driver = $item; + } + + } else { + if(is_array($item) && $item['driver'] != $driver){ + $sameDriver = false; + } + } + if (is_array($item) && isset($item['namespace'])) { + $hasNamespaces = true; } } - //if it's chained we need to treat each chain as a separate EM - if ($isChained) { + //only do this if all the same driver + if ($hasNamespaces && $sameDriver) { + $driver = $sourceArray['metadata'][0]['driver']; + foreach ($sourceArray['metadata'] as $item) { - //convert each chained metadata array EM + //convert each metadata entry into a namespace entry + if(isset($item['alias'])){ + $namespaces[$item['alias']] = $item['namespace']; + } else{ + array_push($namespaces, $item['namespace']); + } } } //only specifying one non-default EM - else { - //convert metadata array to EM + else { + if(isset($sourceArray['metadata']['namespace'])){ + if(isset($sourceArray['metadata']['alias'])){ + $namespaces[$sourceArray['metadata']['alias']] = $sourceArray['metadata']['namespace']; + } else { + $namespaces[] = $sourceArray['metadata']['namespace']; + } + } } } //one EM, default else { - - } - } - - protected function getProxySettings($sourceArray) - { - if (isset($sourceArray['proxy_classes'])) { - return [ - 'auto_generate' => ArrayUtil::get($sourceArray['proxy_classes']['auto_generate']), - 'namespace' => ArrayUtil::get($sourceArray['proxy_classes']['namespace']), - 'path' => ArrayUtil::get($sourceArray['proxy_classes']['directory']) - ]; - } else { - return null; + $driver = $sourceArray['metadata']['driver']; } + $results = $this->viewFactory->make('atrauzzi.manager', ['namespaces' => $namespaces, 'proxySettings' => $proxySettings, 'defaultRepo' => $defaultRepo, 'driver' => $driver, 'connection' => $connection])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; } public function convertCustomTypes($sourceArray){ @@ -103,7 +127,7 @@ public function convertCache($sourceArray) { if (isset($sourceArray['cache']['provider'])) { $cacheProvider = ArrayUtil::get($sourceArray['cache']['provider']); - $results = $this->viewFactory->make('atruazzi.cache', [ + $results = $this->viewFactory->make('atrauzzi.cache', [ 'cacheProvider' => $cacheProvider, 'extras' => count($sourceArray['cache']) > 1 //if user is mimicking cache arrays here we need to tell them to move these to cache.php ])->render(); diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php index 73ca37c1..2f730ba1 100644 --- a/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php +++ b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php @@ -1,4 +1,4 @@ [ - 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'env(\'CACHE_DRIVER\','.$cacheProvider.')'}}}, + 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'env(\'CACHE_DRIVER\',\''.$cacheProvider.'\')'}}}, 'second_level' => false, ], diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php index a81e3a38..3022e8cd 100644 --- a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php +++ b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php @@ -1,6 +1,6 @@ -@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($sourceArray['custom_types']) !== null) +@if(isset($sourceArray['custom_types'])) 'custom_types' => [ - @foreach($sourceArray['custom_Types'] as $key => $val) + @foreach($sourceArray['custom_types'] as $key => $val) '{{$key}}' => '{{$val}}' @endforeach ], diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php index f02f69cf..07a759c5 100644 --- a/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php +++ b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php @@ -1,21 +1,21 @@ @if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_datetime_functions']) !== null) 'custom_datetime_functions' => [ @foreach($dql['custom_datetime_functions'] as $key => $val) - '{{$key}}' => '{{$val}}' + '{{$key}}' => '{{$val}}', @endforeach ], @endif @if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_numeric_functions']) !== null) 'custom_numeric_functions' => [ @foreach($dql['custom_numeric_functions'] as $key => $val) - '{{$key}}' => '{{$val}}' + '{{$key}}' => '{{$val}}', @endforeach ], @endif @if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_string_functions']) !== null) 'custom_string_functions' => [ @foreach($dql['custom_string_functions'] as $key => $val) - '{{$key}}' => '{{$val}}' + '{{$key}}' => '{{$val}}', @endforeach ], @endif diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php new file mode 100644 index 00000000..e03cd1af --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php @@ -0,0 +1,28 @@ +[ + 'dev' => env('APP_DEBUG'), + 'meta' => env('DOCTRINE_METADATA', '{{$driver}}'), + 'connection' => {{{ $connection != null ? $connection : 'config(\'database.default\')' }}}, + @if(!empty($namespaces)) + 'namespaces' => [ + @foreach($namespaces as $key => $val) + '{{$key}}' => '{{$val}}', + @endforeach + ], + @endif + 'paths' => [app_path()], + @if($defaultRepo != null) + 'repository' => {{$defaultRepo}}::class, + @endif + @if($proxySettings != null) + 'proxies' => [ + 'namespace' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($proxySettings['namespace'],'false') }}}, + 'path' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['directory'], 'storage_path(\'proxies\')') }}}, + 'auto_generate' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['auto_generate'], 'env(\'DOCTRINE_PROXY_AUTOGENERATE\', \'false\')') }}} + ], + @endif + 'events' => [ + 'listeners' => [], + 'subscribers' => [] + ], + 'filters' => [] +] From ed5b266b9408621c5392e3d2471873c8bb364378 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:13:27 -0400 Subject: [PATCH 08/39] Bug fix on mitchell migrator when specifying a repository --- .../templates/mitchell/manager.blade.php | 2 +- .../Migrators/AtrauzziMigratorTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/Configuration/Migrators/AtrauzziMigratorTest.php diff --git a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php index c7837313..55944e96 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php +++ b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php @@ -3,7 +3,7 @@ 'meta' => '{{{ $isFork ? $data['metadata']['driver'] : 'env(\'DOCTRINE_METADATA\', \'annotations\')' }}}', 'connection' => {{{ $isFork ? '\''.$data['connection'].'\'' : 'config(\'database.default\')' }}}, 'paths' => {{ var_export(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['metadata']['paths'], $data['metadata']), true) }}, - 'repository' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['repository'], \LaravelDoctrine\ORM\EntityRepository::class) }}}', + 'repository' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['repository'], '\LaravelDoctrine\ORM\EntityRepository') }}}::class, 'proxies' => [ 'namespace' => {{{ isset($data['proxy']['namespace']) ? '\'' . $data['proxy']['namespace'] .'\'' : 'false' }}}, 'path' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['directory'], 'storage_path(\'proxies\')') }}}', diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Configuration/Migrators/AtrauzziMigratorTest.php new file mode 100644 index 00000000..4fb7a2c3 --- /dev/null +++ b/tests/Configuration/Migrators/AtrauzziMigratorTest.php @@ -0,0 +1,30 @@ +add($mitchellMigrator); + + $command = $application->find('doctrine:config:convert'); + + $commandTester = new CommandTester($command); + $commandTester->execute([ + 'command' => $command->getName(), + 'author' => 'atrauzzi', + '--source-file' => realpath(__DIR__ . '/../../Stubs/atrauzzi-config-sample.php'), + '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') + ]); + } +} \ No newline at end of file From f665fe27445c6b7725002eb4b50198187c7987e3 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:22:47 -0400 Subject: [PATCH 09/39] Use storage_path variable included in tests --- src/Console/ConvertConfigCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index a5b4537e..d71d097c 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -168,7 +168,7 @@ protected function getCachePath(){ if(!function_exists('storage_path')){ return __DIR__ . DIRECTORY_SEPARATOR . '../../tests/Stubs/storage'; } else { - return storage_path(); + return storage_path(''); } } } From 12bca960d912c840dec6462cce81d1dade564c9a Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:36:37 -0400 Subject: [PATCH 10/39] Cleaner storage_path solution Thanks patrick --- src/Console/ConvertConfigCommand.php | 10 +--------- tests/Configuration/Migrators/AtrauzziMigratorTest.php | 4 ++++ tests/Configuration/Migrators/MitchellMigratorTest.php | 3 +++ tests/Stubs/mitchellvanw-config-sample.php | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index d71d097c..1db493b2 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -153,7 +153,7 @@ protected function createViewFactory(){ $dispatcher = new Dispatcher(new Container); - $compiler = new BladeCompiler(new Filesystem(), $this->getCachePath() . '/framework/views'); + $compiler = new BladeCompiler(new Filesystem(), storage_path() . '/framework/views'); $bladeEngine = new CompilerEngine($compiler); $engineResolver = new EngineResolver(); $engineResolver->register('blade', function() use(&$bladeEngine){ @@ -163,12 +163,4 @@ protected function createViewFactory(){ $viewFactory = new \Illuminate\View\Factory($engineResolver, $FileViewFinder, $dispatcher); return $viewFactory; } - - protected function getCachePath(){ - if(!function_exists('storage_path')){ - return __DIR__ . DIRECTORY_SEPARATOR . '../../tests/Stubs/storage'; - } else { - return storage_path(''); - } - } } diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Configuration/Migrators/AtrauzziMigratorTest.php index 4fb7a2c3..b438a96c 100644 --- a/tests/Configuration/Migrators/AtrauzziMigratorTest.php +++ b/tests/Configuration/Migrators/AtrauzziMigratorTest.php @@ -27,4 +27,8 @@ public function test_convert_atrauzzi_config(){ '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); } +} + +function storage_path(){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; } \ No newline at end of file diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Configuration/Migrators/MitchellMigratorTest.php index d10df5b7..5dc4c45e 100644 --- a/tests/Configuration/Migrators/MitchellMigratorTest.php +++ b/tests/Configuration/Migrators/MitchellMigratorTest.php @@ -27,4 +27,7 @@ public function test_convert_mitchell_config(){ '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); } +} +function storage_path(){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; } \ No newline at end of file diff --git a/tests/Stubs/mitchellvanw-config-sample.php b/tests/Stubs/mitchellvanw-config-sample.php index fe67d882..17780f3a 100644 --- a/tests/Stubs/mitchellvanw-config-sample.php +++ b/tests/Stubs/mitchellvanw-config-sample.php @@ -31,7 +31,7 @@ ], 'proxy' => [ 'auto_generate' => true, - 'directory' => 'storage/proxies', + 'directory' => storage_path() . '/proxies', 'namespace' => null ], 'cache_provider' => null, From 81f28f793fcd37ea1def9f564edd2ca7a91f7527 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:49:17 -0400 Subject: [PATCH 11/39] storage_path where everyone plays nicely --- tests/Configuration/Cache/FileCacheProviderTest.php | 5 +++-- tests/Configuration/Migrators/AtrauzziMigratorTest.php | 6 ++++-- tests/Configuration/Migrators/MitchellMigratorTest.php | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/Configuration/Cache/FileCacheProviderTest.php b/tests/Configuration/Cache/FileCacheProviderTest.php index 4ea93532..8f4f8036 100644 --- a/tests/Configuration/Cache/FileCacheProviderTest.php +++ b/tests/Configuration/Cache/FileCacheProviderTest.php @@ -26,7 +26,8 @@ public function getExpectedInstance() } } -function storage_path($path) +function storage_path($path = null) { - return $path; + $storage = __DIR__ . DIRECTORY_SEPARATOR . '../../Stubs/storage'; + return is_null($path) ? $storage : $storage . DIRECTORY_SEPARATOR . $path; } diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Configuration/Migrators/AtrauzziMigratorTest.php index b438a96c..825914a7 100644 --- a/tests/Configuration/Migrators/AtrauzziMigratorTest.php +++ b/tests/Configuration/Migrators/AtrauzziMigratorTest.php @@ -29,6 +29,8 @@ public function test_convert_atrauzzi_config(){ } } -function storage_path(){ - return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; +if(!function_exists('storage_path')){ + function storage_path($path = null){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + } } \ No newline at end of file diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Configuration/Migrators/MitchellMigratorTest.php index 5dc4c45e..ae504a1c 100644 --- a/tests/Configuration/Migrators/MitchellMigratorTest.php +++ b/tests/Configuration/Migrators/MitchellMigratorTest.php @@ -28,6 +28,9 @@ public function test_convert_mitchell_config(){ ]); } } -function storage_path(){ - return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + +if(!function_exists('storage_path')){ + function storage_path($path = null){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + } } \ No newline at end of file From 05bcfa2abce382e1c538ce24d091d1354305f065 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:57:58 -0400 Subject: [PATCH 12/39] Update gitignore for cached files directory during tests --- .gitignore | 4 +++- tests/Stubs/storage/framework/views/.gitkeep | 0 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/Stubs/storage/framework/views/.gitkeep diff --git a/.gitignore b/.gitignore index b65f6a06..46624afd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ composer.lock .DS_Store .php_cs.cache -/tests/Stubs/storage +/tests/Stubs/storage/framework/views/* +!/tests/Stubs/storage/framework/views/.gitkeep +/tests/Stubs/storage/doctrine.generated.php .idea laravel-doctrine-orm.iml \ No newline at end of file diff --git a/tests/Stubs/storage/framework/views/.gitkeep b/tests/Stubs/storage/framework/views/.gitkeep new file mode 100644 index 00000000..e69de29b From 466db27bf8f814bee03284d978e990332cee7371 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Mon, 14 Sep 2015 23:36:55 +0200 Subject: [PATCH 13/39] Move migrator tests into Console folder --- .../{Configuration => Console}/Migrators/AtrauzziMigratorTest.php | 0 .../{Configuration => Console}/Migrators/MitchellMigratorTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/{Configuration => Console}/Migrators/AtrauzziMigratorTest.php (100%) rename tests/{Configuration => Console}/Migrators/MitchellMigratorTest.php (100%) diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Console/Migrators/AtrauzziMigratorTest.php similarity index 100% rename from tests/Configuration/Migrators/AtrauzziMigratorTest.php rename to tests/Console/Migrators/AtrauzziMigratorTest.php diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php similarity index 100% rename from tests/Configuration/Migrators/MitchellMigratorTest.php rename to tests/Console/Migrators/MitchellMigratorTest.php From 3c4365cf59c5b872e4cc3f490d7453349c5df322 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 11:38:38 +0200 Subject: [PATCH 14/39] Fix Cannot use Symfony\Component\Console\Command\Command as Command + PSR2 fixes --- .../ConfigMigrations/AtrauzziMigrator.php | 60 ++-- .../ConfigMigrations/MitchellMigrator.php | 2 +- .../templates/atrauzzi/customTypes.blade.php | 2 +- src/Console/ConvertConfigCommand.php | 100 ++++-- .../Cache/FileCacheProviderTest.php | 1 + .../Migrators/AtrauzziMigratorTest.php | 25 +- .../Migrators/MitchellMigratorTest.php | 25 +- tests/Stubs/atrauzzi-config-sample.php | 319 +++++++++--------- tests/Stubs/mitchellvanw-config-sample.php | 37 +- 9 files changed, 303 insertions(+), 268 deletions(-) diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php index c60cb4f2..45e68f12 100644 --- a/src/Console/ConfigMigrations/AtrauzziMigrator.php +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -1,20 +1,18 @@ convertDQL($sourceArray); - $cache = $this->convertCache($sourceArray); + $dqls = $this->convertDQL($sourceArray); + $cache = $this->convertCache($sourceArray); $customTypes = $this->convertCustomTypes($sourceArray); - $managers = [$this->convertManager($sourceArray)]; + $managers = [$this->convertManager($sourceArray)]; $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls, 'customTypes' => $customTypes])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); @@ -51,29 +49,28 @@ public function convertManager($sourceArray) { $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']); $defaultRepo = ArrayUtil::get($sourceArray['default_repository']); - $namespaces = []; - $driver = null; - $connection = ArrayUtil::get($sourceArray['default']); + $namespaces = []; + $driver = null; + $connection = ArrayUtil::get($sourceArray['default']); //non default configuration if (count($sourceArray['metadata']) > 1) { $hasNamespaces = false; - $index = 0; - $driver = null; - $sameDriver = true; + $index = 0; + $driver = null; + $sameDriver = true; foreach ($sourceArray['metadata'] as $key => $item) { //get first driver - if(is_null($driver)){ - if(is_array($item)){ + if (is_null($driver)) { + if (is_array($item)) { $driver = $item['driver']; - } else if($key == 'driver') { + } elseif ($key == 'driver') { $driver = $item; } - } else { - if(is_array($item) && $item['driver'] != $driver){ - $sameDriver = false; + if (is_array($item) && $item['driver'] != $driver) { + $sameDriver = false; } } if (is_array($item) && isset($item['namespace'])) { @@ -86,16 +83,16 @@ public function convertManager($sourceArray) foreach ($sourceArray['metadata'] as $item) { //convert each metadata entry into a namespace entry - if(isset($item['alias'])){ + if (isset($item['alias'])) { $namespaces[$item['alias']] = $item['namespace']; - } else{ + } else { array_push($namespaces, $item['namespace']); } } } //only specifying one non-default EM - else { - if(isset($sourceArray['metadata']['namespace'])){ - if(isset($sourceArray['metadata']['alias'])){ + else { + if (isset($sourceArray['metadata']['namespace'])) { + if (isset($sourceArray['metadata']['alias'])) { $namespaces[$sourceArray['metadata']['alias']] = $sourceArray['metadata']['namespace']; } else { $namespaces[] = $sourceArray['metadata']['namespace']; @@ -108,19 +105,22 @@ public function convertManager($sourceArray) } $results = $this->viewFactory->make('atrauzzi.manager', ['namespaces' => $namespaces, 'proxySettings' => $proxySettings, 'defaultRepo' => $defaultRepo, 'driver' => $driver, 'connection' => $connection])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; } - public function convertCustomTypes($sourceArray){ + public function convertCustomTypes($sourceArray) + { $results = $this->viewFactory->make('atrauzzi.customTypes', ['sourceArray' => $sourceArray])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; } /** * Convert a cache section from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for a cache section for this project * - * @param array $sourceArray + * @param array $sourceArray * @return string */ public function convertCache($sourceArray) @@ -129,13 +129,14 @@ public function convertCache($sourceArray) $cacheProvider = ArrayUtil::get($sourceArray['cache']['provider']); $results = $this->viewFactory->make('atrauzzi.cache', [ 'cacheProvider' => $cacheProvider, - 'extras' => count($sourceArray['cache']) > 1 //if user is mimicking cache arrays here we need to tell them to move these to cache.php + 'extras' => count($sourceArray['cache']) > 1 //if user is mimicking cache arrays here we need to tell them to move these to cache.php ])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; } - return null; + return null; } /** @@ -150,6 +151,7 @@ public function convertDQL($sourceArray) { $results = $this->viewFactory->make('atrauzzi.dql', ['dql' => $sourceArray])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; } -} \ No newline at end of file +} diff --git a/src/Console/ConfigMigrations/MitchellMigrator.php b/src/Console/ConfigMigrations/MitchellMigrator.php index ae636421..293d4ebb 100644 --- a/src/Console/ConfigMigrations/MitchellMigrator.php +++ b/src/Console/ConfigMigrations/MitchellMigrator.php @@ -38,7 +38,7 @@ public function convertConfiguration($sourceArray) if ($isFork) { foreach ($sourceArray['entity_managers'] as $key => $manager) { $manager['proxy'] = $sourceArray['proxy']; - $managers[$key] = $this->convertManager($manager, $isFork); + $managers[$key] = $this->convertManager($manager, $isFork); } } else { $managers['default'] = $this->convertManager($sourceArray, $isFork); diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php index 3022e8cd..90003f00 100644 --- a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php +++ b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php @@ -4,4 +4,4 @@ '{{$key}}' => '{{$val}}' @endforeach ], -@endif \ No newline at end of file +@endif diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index 1db493b2..acfed244 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -2,11 +2,10 @@ namespace LaravelDoctrine\ORM\Console; +use Illuminate\Container\Container as Container; use Illuminate\Contracts\View\Factory; -use Illuminate\Filesystem\Filesystem as Filesystem; use Illuminate\Events\Dispatcher; -use Illuminate\Container\Container as Container; -use Illuminate\Support\Facades\Input; +use Illuminate\Filesystem\Filesystem as Filesystem; use Illuminate\View\Compilers\BladeCompiler; use Illuminate\View\Engines\CompilerEngine; use Illuminate\View\Engines\EngineResolver; @@ -14,32 +13,50 @@ use InvalidArgumentException; use LaravelDoctrine\ORM\Console\ConfigMigrations\AtrauzziMigrator; use LaravelDoctrine\ORM\Console\ConfigMigrations\MitchellMigrator; -use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -class ConvertConfigCommand extends Command +class ConvertConfigCommand extends SymfonyCommand { + /** + * @var string + */ protected $name = 'doctrine:config:convert'; + /** + * @var string + */ protected $description = 'Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM.'; - protected function configure(){ + /** + * Configure the command + */ + protected function configure() + { $this->setName('doctrine:config:convert') - ->setAliases(['doctrine:config:convert']) - ->setDescription('Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM') - ->setDefinition([ - new InputArgument('author', InputArgument::REQUIRED, 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'), - new InputOption('dest-path', null, InputOption::VALUE_OPTIONAL, 'Where the generated configuration should be placed', 'config'), - new InputOption('source-file', null, InputOption::VALUE_OPTIONAL, 'Where the source configuration file is located.','config/doctrine.php') - ]); + ->setAliases(['doctrine:config:convert']) + ->setDescription('Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM') + ->setDefinition([ + new InputArgument('author', InputArgument::REQUIRED, + 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'), + new InputOption('dest-path', null, InputOption::VALUE_OPTIONAL, + 'Where the generated configuration should be placed', 'config'), + new InputOption('source-file', null, InputOption::VALUE_OPTIONAL, + 'Where the source configuration file is located.', 'config/doctrine.php') + ]); } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int|null|void + */ public function execute(InputInterface $input, OutputInterface $output) { - //add config templates directory to view locations //$viewFactory->addLocation(realpath(__DIR__ . '/ConfigMigrations/templates')); @@ -104,8 +121,9 @@ public function execute(InputInterface $input, OutputInterface $output) /** * Convert a configuration file from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for this project * - * @param array $sourceConfig - * @param Factory $viewFactory + * @param array $sourceConfig + * @param Factory $viewFactory + * * @return string */ private function convertMitchell($sourceConfig, $viewFactory) @@ -118,49 +136,77 @@ private function convertMitchell($sourceConfig, $viewFactory) /** * Convert a configuration file from atrauzzi/laravel-doctrine to a string representation of a php array configuration for this project * - * @param array $sourceConfig - * @param Factory $viewFactory + * @param array $sourceConfig + * @param Factory $viewFactory + * * @return string */ private function convertAtrauzzi($sourceConfig, $viewFactory) { - $aMigrator = new AtrauzziMigrator($viewFactory); + $aMigrator = new AtrauzziMigrator($viewFactory); return $aMigrator->convertConfiguration($sourceConfig); } + /** + * @return array + */ public function getArguments() { return [ - ['author', InputArgument::REQUIRED, 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'], + [ + 'author', + InputArgument::REQUIRED, + 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"' + ], ]; } + /** + * @return array + */ protected function getOptions() { return [ - ['dest-path', null, InputOption::VALUE_OPTIONAL, 'Where the generated configuration should be placed. Default is config.', 'config'], - ['source-file', null, InputOption::VALUE_OPTIONAL, 'Where the source configuration file is located. Default is config/doctrine.php', 'config/doctrine.php'] + [ + 'dest-path', + null, + InputOption::VALUE_OPTIONAL, + 'Where the generated configuration should be placed. Default is config.', + 'config' + ], + [ + 'source-file', + null, + InputOption::VALUE_OPTIONAL, + 'Where the source configuration file is located. Default is config/doctrine.php', + 'config/doctrine.php' + ] ]; } - protected function createViewFactory(){ + /** + * @return \Illuminate\View\Factory + */ + protected function createViewFactory() + { $FileViewFinder = new FileViewFinder( new Filesystem, - array(realpath(__DIR__ . '/ConfigMigrations/templates')) + [realpath(__DIR__ . '/ConfigMigrations/templates')] ); $dispatcher = new Dispatcher(new Container); - $compiler = new BladeCompiler(new Filesystem(), storage_path() . '/framework/views'); - $bladeEngine = new CompilerEngine($compiler); + $compiler = new BladeCompiler(new Filesystem(), storage_path() . '/framework/views'); + $bladeEngine = new CompilerEngine($compiler); $engineResolver = new EngineResolver(); - $engineResolver->register('blade', function() use(&$bladeEngine){ + $engineResolver->register('blade', function () use (&$bladeEngine) { return $bladeEngine; }); $viewFactory = new \Illuminate\View\Factory($engineResolver, $FileViewFinder, $dispatcher); + return $viewFactory; } } diff --git a/tests/Configuration/Cache/FileCacheProviderTest.php b/tests/Configuration/Cache/FileCacheProviderTest.php index 8f4f8036..bff84632 100644 --- a/tests/Configuration/Cache/FileCacheProviderTest.php +++ b/tests/Configuration/Cache/FileCacheProviderTest.php @@ -29,5 +29,6 @@ public function getExpectedInstance() function storage_path($path = null) { $storage = __DIR__ . DIRECTORY_SEPARATOR . '../../Stubs/storage'; + return is_null($path) ? $storage : $storage . DIRECTORY_SEPARATOR . $path; } diff --git a/tests/Console/Migrators/AtrauzziMigratorTest.php b/tests/Console/Migrators/AtrauzziMigratorTest.php index 825914a7..8d5c8f0d 100644 --- a/tests/Console/Migrators/AtrauzziMigratorTest.php +++ b/tests/Console/Migrators/AtrauzziMigratorTest.php @@ -1,36 +1,31 @@ add($mitchellMigrator); $command = $application->find('doctrine:config:convert'); $commandTester = new CommandTester($command); $commandTester->execute([ - 'command' => $command->getName(), - 'author' => 'atrauzzi', + 'command' => $command->getName(), + 'author' => 'atrauzzi', '--source-file' => realpath(__DIR__ . '/../../Stubs/atrauzzi-config-sample.php'), - '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') + '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); } } -if(!function_exists('storage_path')){ - function storage_path($path = null){ +if (!function_exists('storage_path')) { + function storage_path($path = null) + { return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; } -} \ No newline at end of file +} diff --git a/tests/Console/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php index ae504a1c..c6448607 100644 --- a/tests/Console/Migrators/MitchellMigratorTest.php +++ b/tests/Console/Migrators/MitchellMigratorTest.php @@ -1,36 +1,31 @@ add($mitchellMigrator); $command = $application->find('doctrine:config:convert'); $commandTester = new CommandTester($command); $commandTester->execute([ - 'command' => $command->getName(), - 'author' => 'mitchellvanw', + 'command' => $command->getName(), + 'author' => 'mitchellvanw', '--source-file' => realpath(__DIR__ . '/../../Stubs/mitchellvanw-config-sample.php'), - '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') + '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); } } -if(!function_exists('storage_path')){ - function storage_path($path = null){ +if (!function_exists('storage_path')) { + function storage_path($path = null) + { return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; } -} \ No newline at end of file +} diff --git a/tests/Stubs/atrauzzi-config-sample.php b/tests/Stubs/atrauzzi-config-sample.php index 6e0052b1..13522571 100644 --- a/tests/Stubs/atrauzzi-config-sample.php +++ b/tests/Stubs/atrauzzi-config-sample.php @@ -1,69 +1,71 @@ - [ - - [ - 'driver' => 'annotation', - 'namespace' => 'SysPRO\\Model\\Controller\\Entity', - 'alias' => 'Controller' - ], - [ - 'driver' => 'annotation', - 'namespace' => 'SysPRO\\Model\\Operacoes\\Entity', - 'alias' => 'Operacoes' - ], - [ - 'driver' => 'annotation', - 'namespace' => 'SysPRO\\Model\\Parametros\\Entity', - 'alias' => 'Parametros' - ], - [ - 'driver' => 'annotation', - 'namespace' => 'SysPRO\\Model\\Sistema\\Entity', - 'alias' => 'Sistema' - ] + /* + * Metadata Driver Configuration + */ + + 'metadata' => [ + + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Controller\\Entity', + 'alias' => 'Controller' + ], + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Operacoes\\Entity', + 'alias' => 'Operacoes' + ], + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Parametros\\Entity', + 'alias' => 'Parametros' + ], + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Sistema\\Entity', + 'alias' => 'Sistema' + ] - ], - /* + ], + /* - 'mappings' => [ + 'mappings' => [ - 'App\MyModel' => [ + 'App\MyModel' => [ - 'table' => 'my_model', + 'table' => 'my_model', - 'abstract' => false, + 'abstract' => false, - 'repository' => 'App\Repository\MyModel', + 'repository' => 'App\Repository\MyModel', - 'fields' => [ + 'fields' => [ - 'id' => [ - 'type' => 'integer', - 'strategy' => 'identity' - ], + 'id' => [ + 'type' => 'integer', + 'strategy' => 'identity' + ], - 'name' => [ - 'type' => 'string', - 'nullable' => false, - ] + 'name' => [ + 'type' => 'string', + 'nullable' => false, + ] - ], + ], - 'indexes' => [ - 'name' - ], + 'indexes' => [ + 'name' + ], - ], + ], - ], + ], */ - 'connections' => [ + 'connections' => [ // Override your laravel environment database selection here if desired // 'default' => 'mysql', @@ -79,110 +81,105 @@ // Some preset configurations to map laravel sqlite configs to doctrine 'sqlite' => [ - 'driver' => 'pdo_sqlite', + 'driver' => 'pdo_sqlite', 'mappings' => [ 'database' => 'path' ] ] + ], - ], - - /* - | --------------------------------- - | By default, this package mimics the cache configuration from Laravel. - | - | You can create your own cache provider by extending the - | Atrauzzi\LaravelDoctrine\CacheProvider\CacheProvider class. - | - | Each provider requires a like named section with an array of configuration options. - | ---------------------------------- - */ - 'cache' => [ + /* + | --------------------------------- + | By default, this package mimics the cache configuration from Laravel. + | + | You can create your own cache provider by extending the + | Atrauzzi\LaravelDoctrine\CacheProvider\CacheProvider class. + | + | Each provider requires a like named section with an array of configuration options. + | ---------------------------------- + */ + 'cache' => [ // Remove or set to null for no cache - 'provider' => 'array', + 'provider' => 'array', 'file' => [ 'directory' => 'framework/cache', 'extension' => '.doctrinecache.data' ], - 'redis' => [ - 'host' => '127.0.0.1', - 'port' => 6379, - 'database' => 1 - ], + 'redis' => [ + 'host' => '127.0.0.1', + 'port' => 6379, + 'database' => 1 + ], - 'memcache' => [ - 'host' => '127.0.0.1', - 'port' => 11211 - ], + 'memcache' => [ + 'host' => '127.0.0.1', + 'port' => 11211 + ], 'providers' => [ - 'memcache' => Atrauzzi\LaravelDoctrine\CacheProvider\MemcacheProvider::class, + 'memcache' => Atrauzzi\LaravelDoctrine\CacheProvider\MemcacheProvider::class, 'memcached' => Atrauzzi\LaravelDoctrine\CacheProvider\MemcachedProvider::class, 'couchbase' => Atrauzzi\LaravelDoctrine\CacheProvider\CouchbaseProvider::class, - 'redis' => Atrauzzi\LaravelDoctrine\CacheProvider\RedisProvider::class, - 'apc' => Atrauzzi\LaravelDoctrine\CacheProvider\ApcCacheProvider::class, - 'xcache' => Atrauzzi\LaravelDoctrine\CacheProvider\XcacheProvider::class, - 'array' => Atrauzzi\LaravelDoctrine\CacheProvider\ArrayCacheProvider::class, - 'file' => Atrauzzi\LaravelDoctrine\CacheProvider\FilesystemCacheProvider::class, + 'redis' => Atrauzzi\LaravelDoctrine\CacheProvider\RedisProvider::class, + 'apc' => Atrauzzi\LaravelDoctrine\CacheProvider\ApcCacheProvider::class, + 'xcache' => Atrauzzi\LaravelDoctrine\CacheProvider\XcacheProvider::class, + 'array' => Atrauzzi\LaravelDoctrine\CacheProvider\ArrayCacheProvider::class, + 'file' => Atrauzzi\LaravelDoctrine\CacheProvider\FilesystemCacheProvider::class, //'custom' => 'Path\To\Your\Class' ] - ], - - - /* - |-------------------------------------------------------------------------- - | Sets the directory where Doctrine generates any proxy classes, including - | with which namespace. - |-------------------------------------------------------------------------- - | - | http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html - | - */ - - 'proxy_classes' => [ - 'auto_generate' => false, - 'directory' => null, - 'namespace' => null, - ], - - - - 'migrations' => [ - 'directory' => '/database/doctrine-migrations', - 'namespace' => 'DoctrineMigrations', - 'table_name' => 'doctrine_migration_versions' - ], - - /* - |-------------------------------------------------------------------------- - | Use to specify the default repository - | http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html#custom-repositories - |-------------------------------------------------------------------------- - */ - - 'default_repository' => '\Doctrine\ORM\EntityRepository', - - - /* - |-------------------------------------------------------------------------- - | Use to specify the SQL Logger - | To use with \Doctrine\DBAL\Logging\EchoSQLLogger, do: - | 'sqlLogger' => new \Doctrine\DBAL\Logging\EchoSQLLogger(); - | - | http://doctrine-orm.readthedocs.org/en/latest/reference/advanced-configuration.html#sql-logger-optional - |-------------------------------------------------------------------------- - */ - /* - 'sql_logger' => null, - */ - - /* - * In some circumstances, you may wish to diverge from what's configured in Laravel. - */ - 'debug' => false, + ], + + /* + |-------------------------------------------------------------------------- + | Sets the directory where Doctrine generates any proxy classes, including + | with which namespace. + |-------------------------------------------------------------------------- + | + | http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html + | + */ + + 'proxy_classes' => [ + 'auto_generate' => false, + 'directory' => null, + 'namespace' => null, + ], + + 'migrations' => [ + 'directory' => '/database/doctrine-migrations', + 'namespace' => 'DoctrineMigrations', + 'table_name' => 'doctrine_migration_versions' + ], + + /* + |-------------------------------------------------------------------------- + | Use to specify the default repository + | http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html#custom-repositories + |-------------------------------------------------------------------------- + */ + + 'default_repository' => '\Doctrine\ORM\EntityRepository', + + /* + |-------------------------------------------------------------------------- + | Use to specify the SQL Logger + | To use with \Doctrine\DBAL\Logging\EchoSQLLogger, do: + | 'sqlLogger' => new \Doctrine\DBAL\Logging\EchoSQLLogger(); + | + | http://doctrine-orm.readthedocs.org/en/latest/reference/advanced-configuration.html#sql-logger-optional + |-------------------------------------------------------------------------- + */ + /* + 'sql_logger' => null, + */ + + /* + * In some circumstances, you may wish to diverge from what's configured in Laravel. + */ + 'debug' => false, /* | --------------------------------- @@ -194,36 +191,36 @@ 'json' => 'Atrauzzi\LaravelDoctrine\Type\Json' ], - 'custom_datetime_functions' => [ - 'DATEADD' => 'DoctrineExtensions\Query\Mysql\DateAdd', - 'DATEDIFF' => 'DoctrineExtensions\Query\Mysql\DateDiff', - 'DATESUB' => 'DoctrineExtensions\Query\Mysql\DateSub', - 'FROM_UNIXTIME' => 'DoctrineExtensions\Query\Mysql\FromUnixtime' + 'custom_datetime_functions' => [ + 'DATEADD' => 'DoctrineExtensions\Query\Mysql\DateAdd', + 'DATEDIFF' => 'DoctrineExtensions\Query\Mysql\DateDiff', + 'DATESUB' => 'DoctrineExtensions\Query\Mysql\DateSub', + 'FROM_UNIXTIME' => 'DoctrineExtensions\Query\Mysql\FromUnixtime' + ], + + 'custom_numeric_functions' => [ + 'ACOS' => 'DoctrineExtensions\Query\Mysql\Acos', + 'ASIN' => 'DoctrineExtensions\Query\Mysql\Asin', + 'ATAN' => 'DoctrineExtensions\Query\Mysql\Atan', + 'ATAN2' => 'DoctrineExtensions\Query\Mysql\Atan2', + 'COS' => 'DoctrineExtensions\Query\Mysql\Cos', + 'COT' => 'DoctrineExtensions\Query\Mysql\Cot', + 'DEGREES' => 'DoctrineExtensions\Query\Mysql\Degrees', + 'RADIANS' => 'DoctrineExtensions\Query\Mysql\Radians', + 'SIN' => 'DoctrineExtensions\Query\Mysql\Sin', + 'TAN' => 'DoctrineExtensions\Query\Mysql\Tan' ], - 'custom_numeric_functions' => [ - 'ACOS' => 'DoctrineExtensions\Query\Mysql\Acos', - 'ASIN' => 'DoctrineExtensions\Query\Mysql\Asin', - 'ATAN' => 'DoctrineExtensions\Query\Mysql\Atan', - 'ATAN2' => 'DoctrineExtensions\Query\Mysql\Atan2', - 'COS' => 'DoctrineExtensions\Query\Mysql\Cos', - 'COT' => 'DoctrineExtensions\Query\Mysql\Cot', - 'DEGREES' => 'DoctrineExtensions\Query\Mysql\Degrees', - 'RADIANS' => 'DoctrineExtensions\Query\Mysql\Radians', - 'SIN' => 'DoctrineExtensions\Query\Mysql\Sin', - 'TAN' => 'DoctrineExtensions\Query\Mysql\Tan' - ], - - 'custom_string_functions' => [ - 'CHAR_LENGTH' => 'DoctrineExtensions\Query\Mysql\CharLength', - 'CONCAT_WS' => 'DoctrineExtensions\Query\Mysql\ConcatWs', - 'FIELD' => 'DoctrineExtensions\Query\Mysql\Field', - 'FIND_IN_SET' => 'DoctrineExtensions\Query\Mysql\FindInSet', - 'REPLACE' => 'DoctrineExtensions\Query\Mysql\Replace', - 'SOUNDEX' => 'DoctrineExtensions\Query\Mysql\Soundex', - 'STR_TO_DATE' => 'DoctrineExtensions\Query\Mysql\StrToDate', - 'SUBSTRING_INDEX' => 'DoctrineExtensions\Query\Mysql\SubstringIndex' - ], + 'custom_string_functions' => [ + 'CHAR_LENGTH' => 'DoctrineExtensions\Query\Mysql\CharLength', + 'CONCAT_WS' => 'DoctrineExtensions\Query\Mysql\ConcatWs', + 'FIELD' => 'DoctrineExtensions\Query\Mysql\Field', + 'FIND_IN_SET' => 'DoctrineExtensions\Query\Mysql\FindInSet', + 'REPLACE' => 'DoctrineExtensions\Query\Mysql\Replace', + 'SOUNDEX' => 'DoctrineExtensions\Query\Mysql\Soundex', + 'STR_TO_DATE' => 'DoctrineExtensions\Query\Mysql\StrToDate', + 'SUBSTRING_INDEX' => 'DoctrineExtensions\Query\Mysql\SubstringIndex' + ], 'auth' => [ //'authenticator' => 'Atrauzzi\LaravelDoctrine\DoctrineAuthenticator', diff --git a/tests/Stubs/mitchellvanw-config-sample.php b/tests/Stubs/mitchellvanw-config-sample.php index 17780f3a..5d8c2761 100644 --- a/tests/Stubs/mitchellvanw-config-sample.php +++ b/tests/Stubs/mitchellvanw-config-sample.php @@ -2,38 +2,37 @@ return [ 'default_connection' => 'default', - 'entity_managers' => [ + 'entity_managers' => [ 'default' => [ - 'connection' => 'sqlite', - 'cache_provider' => null, - 'repository' => 'Doctrine\ORM\EntityRepository', + 'connection' => 'sqlite', + 'cache_provider' => null, + 'repository' => 'Doctrine\ORM\EntityRepository', 'simple_annotations' => false, - 'logger' => null, - 'metadata' => [ - 'simple' => false, - 'driver' => 'yaml', - 'paths' => 'app/Models/mappings', + 'logger' => null, + 'metadata' => [ + 'simple' => false, + 'driver' => 'yaml', + 'paths' => 'app/Models/mappings', 'extension' => '.dcm.yml' ], ], 'production' => [ - 'connection' => 'mysql', + 'connection' => 'mysql', 'cache_provider' => 'file', - 'repository' => 'Doctrine\ORM\EntityRepository', - 'logger' => null, - 'metadata' => [ - 'simple' => false, - 'driver' => 'yaml', - 'paths' => 'app/Models/mappings', + 'repository' => 'Doctrine\ORM\EntityRepository', + 'logger' => null, + 'metadata' => [ + 'simple' => false, + 'driver' => 'yaml', + 'paths' => 'app/Models/mappings', 'extension' => '.dcm.yml' ], ], ], 'proxy' => [ 'auto_generate' => true, - 'directory' => storage_path() . '/proxies', - 'namespace' => null + 'directory' => storage_path() . '/proxies', + 'namespace' => null ], 'cache_provider' => null, ]; - From 0dd657da6041256b5182bb8302ffc9896f0320d8 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 11:49:27 +0200 Subject: [PATCH 15/39] Docblock + CS --- .../ConfigMigrations/AtrauzziMigrator.php | 96 ++++++++++++------- .../ConfigMigrations/MitchellMigrator.php | 81 +++++++++++----- src/Console/ConvertConfigCommand.php | 6 +- 3 files changed, 120 insertions(+), 63 deletions(-) diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php index 45e68f12..0f1e11fd 100644 --- a/src/Console/ConfigMigrations/AtrauzziMigrator.php +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -1,11 +1,5 @@ viewFactory = $viewFactory; - //add namespace for views $this->viewFactory->addNamespace('atrauzzi', realpath(__DIR__ . '/templates/atrauzzi')); $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); } @@ -29,7 +25,8 @@ public function __construct(Factory $viewFactory) /** * Convert a configuration array from another laravel-doctrine project in to a string representation of a php array configuration for this project * - * @param array $sourceArray + * @param array $sourceArray + * * @return string */ public function convertConfiguration($sourceArray) @@ -39,12 +36,21 @@ public function convertConfiguration($sourceArray) $customTypes = $this->convertCustomTypes($sourceArray); $managers = [$this->convertManager($sourceArray)]; - $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls, 'customTypes' => $customTypes])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); + $results = $this->viewFactory->make('laraveldoctrine.master', [ + 'managers' => $managers, + 'cache' => $cache, + 'dqls' => $dqls, + 'customTypes' => $customTypes + ])->render(); - return $unescaped; + return $this->unescape($results); } + /** + * @param $sourceArray + * + * @return string + */ public function convertManager($sourceArray) { $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']); @@ -53,15 +59,13 @@ public function convertManager($sourceArray) $driver = null; $connection = ArrayUtil::get($sourceArray['default']); - //non default configuration + // Non default configuration if (count($sourceArray['metadata']) > 1) { $hasNamespaces = false; - $index = 0; $driver = null; $sameDriver = true; foreach ($sourceArray['metadata'] as $key => $item) { - //get first driver if (is_null($driver)) { if (is_array($item)) { $driver = $item['driver']; @@ -77,20 +81,20 @@ public function convertManager($sourceArray) $hasNamespaces = true; } } - //only do this if all the same driver + // Only do this if all the same driver if ($hasNamespaces && $sameDriver) { $driver = $sourceArray['metadata'][0]['driver']; + // Convert each metadata entry into a namespace entry foreach ($sourceArray['metadata'] as $item) { - //convert each metadata entry into a namespace entry if (isset($item['alias'])) { $namespaces[$item['alias']] = $item['namespace']; } else { array_push($namespaces, $item['namespace']); } } - } //only specifying one non-default EM - else { + // Only specifying one non-default EM + } else { if (isset($sourceArray['metadata']['namespace'])) { if (isset($sourceArray['metadata']['alias'])) { $namespaces[$sourceArray['metadata']['alias']] = $sourceArray['metadata']['namespace']; @@ -99,28 +103,41 @@ public function convertManager($sourceArray) } } } - } //one EM, default - else { + // One EM, default + } else { $driver = $sourceArray['metadata']['driver']; } - $results = $this->viewFactory->make('atrauzzi.manager', ['namespaces' => $namespaces, 'proxySettings' => $proxySettings, 'defaultRepo' => $defaultRepo, 'driver' => $driver, 'connection' => $connection])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); - return $unescaped; + $results = $this->viewFactory->make('atrauzzi.manager', [ + 'namespaces' => $namespaces, + 'proxySettings' => $proxySettings, + 'defaultRepo' => $defaultRepo, + 'driver' => $driver, + 'connection' => $connection + ])->render(); + + return $this->unescape($results); } + /** + * @param $sourceArray + * + * @return string + */ public function convertCustomTypes($sourceArray) { - $results = $this->viewFactory->make('atrauzzi.customTypes', ['sourceArray' => $sourceArray])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); + $results = $this->viewFactory->make('atrauzzi.customTypes', [ + 'sourceArray' => $sourceArray + ])->render(); - return $unescaped; + return $this->unescape($results); } /** * Convert a cache section from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for a cache section for this project * - * @param array $sourceArray + * @param array $sourceArray + * * @return string */ public function convertCache($sourceArray) @@ -129,11 +146,11 @@ public function convertCache($sourceArray) $cacheProvider = ArrayUtil::get($sourceArray['cache']['provider']); $results = $this->viewFactory->make('atrauzzi.cache', [ 'cacheProvider' => $cacheProvider, - 'extras' => count($sourceArray['cache']) > 1 //if user is mimicking cache arrays here we need to tell them to move these to cache.php + 'extras' => count($sourceArray['cache']) > 1 + //if user is mimicking cache arrays here we need to tell them to move these to cache.php ])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); - return $unescaped; + return $this->unescape($results); } return null; @@ -141,17 +158,26 @@ public function convertCache($sourceArray) /** * Convert the dql sections from the entity managers in a configuration from atruazzi/laravel-doctrine into a string representation of a php array configuration for custom string/numeric/datetime functions - * * Returns null if no dql sections were found. * * @param $sourceArray + * * @return null|string */ public function convertDQL($sourceArray) { - $results = $this->viewFactory->make('atrauzzi.dql', ['dql' => $sourceArray])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); + $results = $this->viewFactory->make('atrauzzi.dql', ['dql' => $sourceArray])->render(); + + return $this->unescape($results); + } - return $unescaped; + /** + * @param $results + * + * @return string + */ + protected function unescape($results) + { + return html_entity_decode($results, ENT_QUOTES); } } diff --git a/src/Console/ConfigMigrations/MitchellMigrator.php b/src/Console/ConfigMigrations/MitchellMigrator.php index 293d4ebb..995113dd 100644 --- a/src/Console/ConfigMigrations/MitchellMigrator.php +++ b/src/Console/ConfigMigrations/MitchellMigrator.php @@ -7,7 +7,10 @@ class MitchellMigrator implements ConfigurationMigrator { - private $viewFactory; + /** + * @var FactoryFactory + */ + protected $viewFactory; /** * @param Factory $viewFactory @@ -15,7 +18,6 @@ class MitchellMigrator implements ConfigurationMigrator public function __construct(Factory $viewFactory) { $this->viewFactory = $viewFactory; - //add namespace for views $this->viewFactory->addNamespace('mitchell', realpath(__DIR__ . '/templates/mitchell')); $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); } @@ -23,16 +25,15 @@ public function __construct(Factory $viewFactory) /** * Convert a configuration array from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for this project * - * @param array $sourceArray + * @param array $sourceArray + * * @return string */ public function convertConfiguration($sourceArray) { - //determine if configuration is from FoxxMD fork or original Mitchell repo - $isFork = ArrayUtil::get($sourceArray['entity_managers']) !== null; + $isFork = $this->isFork($sourceArray); $managers = []; - $cache = ''; $dqls = null; if ($isFork) { @@ -48,10 +49,15 @@ public function convertConfiguration($sourceArray) $dqls = $this->convertDQL($sourceArray['entity_managers']); } - $cache = $this->convertCache($sourceArray); + $cache = $this->convertCache($sourceArray); + + $results = $this->viewFactory->make('laraveldoctrine.master', [ + 'managers' => $managers, + 'cache' => $cache, + 'dqls' => $dqls + ])->render(); - $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); + $unescaped = $this->unescape($results); return $unescaped; } @@ -59,14 +65,19 @@ public function convertConfiguration($sourceArray) /** * Convert an entity manager section from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for an entity manager for this project * - * @param array $sourceArray - * @param bool $isFork + * @param array $sourceArray + * @param bool $isFork + * * @return string */ public function convertManager($sourceArray, $isFork) { - $results = $this->viewFactory->make('mitchell.manager', ['data' => $sourceArray, 'isFork' => $isFork])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); + $results = $this->viewFactory->make('mitchell.manager', [ + 'data' => $sourceArray, + 'isFork' => $isFork + ])->render(); + + $unescaped = $this->unescape($results); return $unescaped; } @@ -74,24 +85,27 @@ public function convertManager($sourceArray, $isFork) /** * Convert a cache section from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for a cache section for this project * - * @param array $sourceArray + * @param array $sourceArray + * * @return string */ public function convertCache($sourceArray) { $cacheProvider = ArrayUtil::get($sourceArray['cache_provider']); - $results = $this->viewFactory->make('mitchell.cache', ['cacheProvider' => $cacheProvider])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); - return $unescaped; + $results = $this->viewFactory->make('mitchell.cache', [ + 'cacheProvider' => $cacheProvider + ])->render(); + + return $this->unescape($results); } /** * Convert the dql sections from the entity managers in a configuration from foxxmd/laravel-doctrine into a string representation of a php array configuration for custom string/numeric/datetime functions - * * Returns null if no dql sections were found. * * @param $sourceManagers + * * @return null|string */ public function convertDQL($sourceManagers) @@ -112,12 +126,33 @@ public function convertDQL($sourceManagers) } if (!empty($dqls)) { - $results = $this->viewFactory->make('mitchel.dql', ['dql' => $dqls])->render(); - $unescaped = html_entity_decode($results, ENT_QUOTES); + $results = $this->viewFactory->make('mitchel.dql', [ + 'dql' => $dqls + ])->render(); - return $unescaped; - } else { - return null; + return $this->unescape($results); } } + + /** + * @param $results + * + * @return string + */ + protected function unescape($results) + { + return html_entity_decode($results, ENT_QUOTES); + } + + /** + * Determine if configuration is from FoxxMD fork or original Mitchell repo + * + * @param $sourceArray + * + * @return bool + */ + protected function isFork($sourceArray) + { + return ArrayUtil::get($sourceArray['entity_managers']) !== null; + } } diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index acfed244..10cbcdbc 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -57,9 +57,6 @@ protected function configure() */ public function execute(InputInterface $input, OutputInterface $output) { - //add config templates directory to view locations - //$viewFactory->addLocation(realpath(__DIR__ . '/ConfigMigrations/templates')); - if (($destPath = $input->getOption('dest-path')) === null) { $destPath = 'config'; } @@ -101,8 +98,6 @@ public function execute(InputInterface $input, OutputInterface $output) $viewFactory = $this->createViewFactory(); - //TODO make this relative - switch ($author) { case 'atrauzzi': $convertedConfigString = $this->convertAtrauzzi($sourceArrayConfig, $viewFactory); @@ -115,6 +110,7 @@ public function execute(InputInterface $input, OutputInterface $output) } file_put_contents($destFilePath, 'writeln('Conversion successful. File generated at ' . $destFilePath); } From 6975434d49e71ec9ee6683ed95f64845d68319cf Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 10:19:59 -0400 Subject: [PATCH 16/39] Fix missing cache index on master template --- .../ConfigMigrations/templates/laraveldoctrine/master.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php index de6089bd..54079320 100644 --- a/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php +++ b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php @@ -117,7 +117,7 @@ | Available: acp|array|file|memcached|redis | */ - {{$cache}} + 'cache' => {{$cache}} /* |-------------------------------------------------------------------------- | Gedmo extensions From 23db950a8a8f0b4e7945b77e9db3ddd203048866 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 10:21:15 -0400 Subject: [PATCH 17/39] Cleanup config migrator tests * Run assertions for file existence and sanity check for a manager * Refactor into abstract class for reusability * Polyfill missing laravel helper functions --- .../Migrators/AtrauzziMigratorTest.php | 12 +++--- tests/Console/Migrators/MigratorBase.php | 43 +++++++++++++++++++ .../Migrators/MitchellMigratorTest.php | 10 ++--- 3 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 tests/Console/Migrators/MigratorBase.php diff --git a/tests/Console/Migrators/AtrauzziMigratorTest.php b/tests/Console/Migrators/AtrauzziMigratorTest.php index 8d5c8f0d..c674ed49 100644 --- a/tests/Console/Migrators/AtrauzziMigratorTest.php +++ b/tests/Console/Migrators/AtrauzziMigratorTest.php @@ -3,10 +3,13 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -class AtrauzziMigratorTest extends PHPUnit_Framework_TestCase + + +class AtrauzziMigratorTest extends MigratorBase { public function test_convert_atrauzzi_config() { + $mitchellMigrator = new \LaravelDoctrine\ORM\Console\ConvertConfigCommand(); $application = new Application(); $application->add($mitchellMigrator); @@ -20,12 +23,7 @@ public function test_convert_atrauzzi_config() '--source-file' => realpath(__DIR__ . '/../../Stubs/atrauzzi-config-sample.php'), '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); - } -} -if (!function_exists('storage_path')) { - function storage_path($path = null) - { - return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + $this->sanityCheck(); } } diff --git a/tests/Console/Migrators/MigratorBase.php b/tests/Console/Migrators/MigratorBase.php new file mode 100644 index 00000000..76980a19 --- /dev/null +++ b/tests/Console/Migrators/MigratorBase.php @@ -0,0 +1,43 @@ +assertFileExists(__DIR__ . '/../../Stubs/storage/doctrine.generated.php'); + + $generatedConfig = include __DIR__ . '/../../Stubs/storage/doctrine.generated.php'; + + //assert at least one manager is present + $this->assertArrayHasKey('managers', $generatedConfig); + $this->assertTrue(count($generatedConfig['managers']) > 0); + } +} \ No newline at end of file diff --git a/tests/Console/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php index c6448607..9a3e64c1 100644 --- a/tests/Console/Migrators/MitchellMigratorTest.php +++ b/tests/Console/Migrators/MitchellMigratorTest.php @@ -3,7 +3,7 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -class MitchellMigratorTest extends PHPUnit_Framework_TestCase +class MitchellMigratorTest extends MigratorBase { public function test_convert_mitchell_config() { @@ -20,12 +20,8 @@ public function test_convert_mitchell_config() '--source-file' => realpath(__DIR__ . '/../../Stubs/mitchellvanw-config-sample.php'), '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); - } -} -if (!function_exists('storage_path')) { - function storage_path($path = null) - { - return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + $this->sanityCheck(); } + } From 33c4efe75acb3db644ae3d8a55956c0e0440e077 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 10:44:23 -0400 Subject: [PATCH 18/39] Dynamically instantiate config migrator class --- src/Console/ConvertConfigCommand.php | 106 +++++---------------------- 1 file changed, 18 insertions(+), 88 deletions(-) diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index 10cbcdbc..012f4b31 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -37,20 +37,20 @@ class ConvertConfigCommand extends SymfonyCommand protected function configure() { $this->setName('doctrine:config:convert') - ->setAliases(['doctrine:config:convert']) - ->setDescription('Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM') - ->setDefinition([ - new InputArgument('author', InputArgument::REQUIRED, - 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'), - new InputOption('dest-path', null, InputOption::VALUE_OPTIONAL, - 'Where the generated configuration should be placed', 'config'), - new InputOption('source-file', null, InputOption::VALUE_OPTIONAL, - 'Where the source configuration file is located.', 'config/doctrine.php') - ]); + ->setAliases(['doctrine:config:convert']) + ->setDescription('Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM') + ->setDefinition([ + new InputArgument('author', InputArgument::REQUIRED, + 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'), + new InputOption('dest-path', null, InputOption::VALUE_OPTIONAL, + 'Where the generated configuration should be placed', 'config'), + new InputOption('source-file', null, InputOption::VALUE_OPTIONAL, + 'Where the source configuration file is located.', 'config/doctrine.php') + ]); } /** - * @param InputInterface $input + * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void @@ -98,15 +98,13 @@ public function execute(InputInterface $input, OutputInterface $output) $viewFactory = $this->createViewFactory(); - switch ($author) { - case 'atrauzzi': - $convertedConfigString = $this->convertAtrauzzi($sourceArrayConfig, $viewFactory); - break; - case 'mitchellvanw': - $convertedConfigString = $this->convertMitchell($sourceArrayConfig, $viewFactory); - break; - default: - throw new InvalidArgumentException('Author provided was not a valid choice.'); + $className = __NAMESPACE__ . '\ConfigMigrations\\' . ucfirst($author) . 'Migrator'; + + if (!class_exists($className)) { + throw new InvalidArgumentException('Author provided was not a valid choice.'); + } else { + $configMigrator = new $className($viewFactory); + $convertedConfigString = $configMigrator->convertConfiguration($sourceArrayConfig); } file_put_contents($destFilePath, 'writeln('Conversion successful. File generated at ' . $destFilePath); } - /** - * Convert a configuration file from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for this project - * - * @param array $sourceConfig - * @param Factory $viewFactory - * - * @return string - */ - private function convertMitchell($sourceConfig, $viewFactory) - { - $mMigrator = new MitchellMigrator($viewFactory); - - return $mMigrator->convertConfiguration($sourceConfig); - } - - /** - * Convert a configuration file from atrauzzi/laravel-doctrine to a string representation of a php array configuration for this project - * - * @param array $sourceConfig - * @param Factory $viewFactory - * - * @return string - */ - private function convertAtrauzzi($sourceConfig, $viewFactory) - { - $aMigrator = new AtrauzziMigrator($viewFactory); - - return $aMigrator->convertConfiguration($sourceConfig); - } - - /** - * @return array - */ - public function getArguments() - { - return [ - [ - 'author', - InputArgument::REQUIRED, - 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"' - ], - - ]; - } - - /** - * @return array - */ - protected function getOptions() - { - return [ - [ - 'dest-path', - null, - InputOption::VALUE_OPTIONAL, - 'Where the generated configuration should be placed. Default is config.', - 'config' - ], - [ - 'source-file', - null, - InputOption::VALUE_OPTIONAL, - 'Where the source configuration file is located. Default is config/doctrine.php', - 'config/doctrine.php' - ] - ]; - } - /** * @return \Illuminate\View\Factory */ From f642bc0da240d80138dd2c6aa59ab5cb7d83a009 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 10:48:21 -0400 Subject: [PATCH 19/39] Typo in test parameter --- tests/Console/Migrators/MitchellMigratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Console/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php index 9a3e64c1..61e91a42 100644 --- a/tests/Console/Migrators/MitchellMigratorTest.php +++ b/tests/Console/Migrators/MitchellMigratorTest.php @@ -16,7 +16,7 @@ public function test_convert_mitchell_config() $commandTester = new CommandTester($command); $commandTester->execute([ 'command' => $command->getName(), - 'author' => 'mitchellvanw', + 'author' => 'mitchell', '--source-file' => realpath(__DIR__ . '/../../Stubs/mitchellvanw-config-sample.php'), '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); From f7694f62e0d326d369238d424bb47cc18ae7af44 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 11:22:43 -0400 Subject: [PATCH 20/39] Remove meta block from master template --- .../laraveldoctrine/master.blade.php | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php index 54079320..bf26bb47 100644 --- a/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php +++ b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php @@ -25,38 +25,6 @@ ], /* |-------------------------------------------------------------------------- - | Doctrine Meta Data - |-------------------------------------------------------------------------- - | - | Available: annotations|yaml|xml - | - */ - 'meta' => [ - 'namespaces' => [ - 'App' - ], - 'drivers' => [ - 'annotations' => [ - 'driver' => 'annotations', - 'simple' => false - ], - 'yaml' => [ - 'driver' => 'yaml' - ], - 'xml' => [ - 'driver' => 'xml' - ], - 'config' => [ - 'driver' => 'config', - 'mapping_file' => 'mappings' - ], - 'static_php' => [ - 'driver' => 'static_php' - ] - ] - ], - /* - |-------------------------------------------------------------------------- | Doctrine Extensions |-------------------------------------------------------------------------- | From ee3d14959e1cad9318eb8aa77dc9c98199d2bea6 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 11:23:09 -0400 Subject: [PATCH 21/39] php-cs-fixer cleanup --- src/Console/ConvertConfigCommand.php | 5 +--- .../Migrators/AtrauzziMigratorTest.php | 3 --- tests/Console/Migrators/MigratorBase.php | 25 +++++++++++-------- .../Migrators/MitchellMigratorTest.php | 1 - 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index 012f4b31..e7336a16 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -3,7 +3,6 @@ namespace LaravelDoctrine\ORM\Console; use Illuminate\Container\Container as Container; -use Illuminate\Contracts\View\Factory; use Illuminate\Events\Dispatcher; use Illuminate\Filesystem\Filesystem as Filesystem; use Illuminate\View\Compilers\BladeCompiler; @@ -11,8 +10,6 @@ use Illuminate\View\Engines\EngineResolver; use Illuminate\View\FileViewFinder; use InvalidArgumentException; -use LaravelDoctrine\ORM\Console\ConfigMigrations\AtrauzziMigrator; -use LaravelDoctrine\ORM\Console\ConfigMigrations\MitchellMigrator; use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -50,7 +47,7 @@ protected function configure() } /** - * @param InputInterface $input + * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void diff --git a/tests/Console/Migrators/AtrauzziMigratorTest.php b/tests/Console/Migrators/AtrauzziMigratorTest.php index c674ed49..b7f3d50e 100644 --- a/tests/Console/Migrators/AtrauzziMigratorTest.php +++ b/tests/Console/Migrators/AtrauzziMigratorTest.php @@ -3,13 +3,10 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; - - class AtrauzziMigratorTest extends MigratorBase { public function test_convert_atrauzzi_config() { - $mitchellMigrator = new \LaravelDoctrine\ORM\Console\ConvertConfigCommand(); $application = new Application(); $application->add($mitchellMigrator); diff --git a/tests/Console/Migrators/MigratorBase.php b/tests/Console/Migrators/MigratorBase.php index 76980a19..ee502199 100644 --- a/tests/Console/Migrators/MigratorBase.php +++ b/tests/Console/Migrators/MigratorBase.php @@ -6,31 +6,36 @@ function storage_path($path = null) return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; } } -if(!function_exists('env')){ - function env($var, $default = null){ +if (!function_exists('env')) { + function env($var, $default = null) + { return $default; } } -if(!function_exists('config')){ - function config($var){ +if (!function_exists('config')) { + function config($var) + { return $var; } } -if(!function_exists('app_path')){ - function app_path($path = null){ +if (!function_exists('app_path')) { + function app_path($path = null) + { return __DIR__ . $path; } } abstract class MigratorBase extends PHPUnit_Framework_TestCase { - protected function setUp(){ - if(file_exists(__DIR__ . '/../../Stubs/storage/doctrine.generated.php')){ + protected function setUp() + { + if (file_exists(__DIR__ . '/../../Stubs/storage/doctrine.generated.php')) { unlink(__DIR__ . '/../../Stubs/storage/doctrine.generated.php'); } } - protected function sanityCheck(){ + protected function sanityCheck() + { //make sure file was generated $this->assertFileExists(__DIR__ . '/../../Stubs/storage/doctrine.generated.php'); @@ -40,4 +45,4 @@ protected function sanityCheck(){ $this->assertArrayHasKey('managers', $generatedConfig); $this->assertTrue(count($generatedConfig['managers']) > 0); } -} \ No newline at end of file +} diff --git a/tests/Console/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php index 61e91a42..7db917f9 100644 --- a/tests/Console/Migrators/MitchellMigratorTest.php +++ b/tests/Console/Migrators/MitchellMigratorTest.php @@ -23,5 +23,4 @@ public function test_convert_mitchell_config() $this->sanityCheck(); } - } From 7c17d182d6686b9a42637b166118f5b6d8365c1b Mon Sep 17 00:00:00 2001 From: "Amrit G.C." Date: Tue, 15 Sep 2015 22:00:06 +0545 Subject: [PATCH 22/39] Updating config as Laravel does --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e76343f1..8d532654 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,13 @@ Require this package After adding the package, add the ServiceProvider to the providers array in `config/app.php` ```php -'LaravelDoctrine\ORM\DoctrineServiceProvider', +LaravelDoctrine\ORM\DoctrineServiceProvider::class, ``` Optionally you can register the EntityManager facade: ```php -'EntityManager' => 'LaravelDoctrine\ORM\Facades\EntityManager' +'EntityManager' => LaravelDoctrine\ORM\Facades\EntityManager::class ``` To publish the config use: From 6f5c2ef70f6763d8dc074984dca55c775489cf88 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 19:27:15 +0200 Subject: [PATCH 23/39] Jsonable and Arrayable for Entities --- composer.json | 3 +- src/Serializers/ArrayEncoder.php | 46 ++++++++++++++++++++ src/Serializers/ArraySerializer.php | 51 +++++++++++++++++++++++ src/Serializers/Arrayable.php | 14 +++++++ src/Serializers/JsonSerializer.php | 51 +++++++++++++++++++++++ src/Serializers/Jsonable.php | 26 ++++++++++++ tests/Serializers/ArraySerializerTest.php | 46 ++++++++++++++++++++ tests/Serializers/JsonSerializerTest.php | 43 +++++++++++++++++++ 8 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 src/Serializers/ArrayEncoder.php create mode 100644 src/Serializers/ArraySerializer.php create mode 100644 src/Serializers/Arrayable.php create mode 100644 src/Serializers/JsonSerializer.php create mode 100644 src/Serializers/Jsonable.php create mode 100644 tests/Serializers/ArraySerializerTest.php create mode 100644 tests/Serializers/JsonSerializerTest.php diff --git a/composer.json b/composer.json index 58248450..0c27927a 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "illuminate/pagination": "~5.1", "illuminate/support": "~5.1", "illuminate/validation": "~5.1", - "illuminate/view": "~5.1" + "illuminate/view": "~5.1", + "symfony/serializer": "^2.7" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/src/Serializers/ArrayEncoder.php b/src/Serializers/ArrayEncoder.php new file mode 100644 index 00000000..a6231e79 --- /dev/null +++ b/src/Serializers/ArrayEncoder.php @@ -0,0 +1,46 @@ +serializer = new Serializer([$this->getNormalizer()], [ + 'array' => $this->getEncoder(), + ]); + } + + /** + * @param $entity + * + * @return string + */ + public function serialize($entity) + { + return $this->serializer->serialize($entity, 'array'); + } + + /** + * @return GetSetMethodNormalizer + */ + protected function getNormalizer() + { + return new GetSetMethodNormalizer; + } + + /** + * @return JsonEncoder + */ + protected function getEncoder() + { + return new ArrayEncoder; + } +} diff --git a/src/Serializers/Arrayable.php b/src/Serializers/Arrayable.php new file mode 100644 index 00000000..4200cd7c --- /dev/null +++ b/src/Serializers/Arrayable.php @@ -0,0 +1,14 @@ +serialize($this); + } +} diff --git a/src/Serializers/JsonSerializer.php b/src/Serializers/JsonSerializer.php new file mode 100644 index 00000000..05c7ce6b --- /dev/null +++ b/src/Serializers/JsonSerializer.php @@ -0,0 +1,51 @@ +serializer = new Serializer([$this->getNormalizer()], [ + 'json' => $this->getEncoder(), + ]); + } + + /** + * @param $entity + * + * @return string + */ + public function serialize($entity) + { + return $this->serializer->serialize($entity, 'json'); + } + + /** + * @return GetSetMethodNormalizer + */ + protected function getNormalizer() + { + return new GetSetMethodNormalizer; + } + + /** + * @return JsonEncoder + */ + protected function getEncoder() + { + return new JsonEncoder; + } +} diff --git a/src/Serializers/Jsonable.php b/src/Serializers/Jsonable.php new file mode 100644 index 00000000..aa50729f --- /dev/null +++ b/src/Serializers/Jsonable.php @@ -0,0 +1,26 @@ +serialize($this); + } + + /** + * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + public function jsonSerialize() + { + return (new ArraySerializer)->serialize($this); + } +} diff --git a/tests/Serializers/ArraySerializerTest.php b/tests/Serializers/ArraySerializerTest.php new file mode 100644 index 00000000..a4a287e2 --- /dev/null +++ b/tests/Serializers/ArraySerializerTest.php @@ -0,0 +1,46 @@ +serializer = new ArraySerializer; + } + + public function test_can_serialize_to_array() + { + $array = $this->serializer->serialize(new ArrayableEntity); + + $this->assertEquals([ + 'id' => 'IDVALUE', + 'name' => 'NAMEVALUE' + ], $array); + } +} + +class ArrayableEntity +{ + use Arrayable; + + protected $id = 'IDVALUE'; + + protected $name = 'NAMEVALUE'; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } +} diff --git a/tests/Serializers/JsonSerializerTest.php b/tests/Serializers/JsonSerializerTest.php new file mode 100644 index 00000000..972ef751 --- /dev/null +++ b/tests/Serializers/JsonSerializerTest.php @@ -0,0 +1,43 @@ +serializer = new JsonSerializer; + } + + public function test_can_serialize_to_array() + { + $array = $this->serializer->serialize(new JsonableEntity); + + $this->assertEquals('{"id":"IDVALUE","name":"NAMEVALUE"}', $array); + } +} + +class JsonableEntity +{ + use Jsonable; + + protected $id = 'IDVALUE'; + + protected $name = 'NAMEVALUE'; + + public function getId() + { + return $this->id; + } + + public function getName() + { + return $this->name; + } +} From f4a7672d84ebb336923e3a92aa3304e20a14e2ce Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 19:32:58 +0200 Subject: [PATCH 24/39] Add other packages to suggest --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 0c27927a..3a0f77bd 100644 --- a/composer.json +++ b/composer.json @@ -47,6 +47,9 @@ ] }, "suggest": { + "laravel-doctrine/acl": "to integrate Doctrine roles & permissions with Laravel's Authorization system (~1.0)", + "laravel-doctrine/extensions": "to add Behavioral and Query/Type Extensions for Laravel Doctrine (~1.0)", + "laravel-doctrine/migrations": "to add support for migrations in Laravel Doctrine (~1.0)", "yajra/laravel-oci8": "Support for Laravel native queue and session database drivers in Oracle (~2.0)." } } From b7342f2535101e69981184774b5a79a9ccdae5b8 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 19:43:43 +0200 Subject: [PATCH 25/39] Add HHVM and PHP7.0 to travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index f6aa7e5e..0b545901 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ language: php php: - 5.5 - 5.6 + - 7.0 + - hhvm before_script: - travis_retry composer self-update @@ -12,6 +14,8 @@ after_script: - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.clover +sudo: false + script: phpunit --coverage-clover=coverage.clover matrix: From 764b76d4de2d6005f67f07986e26d26661dc1f5d Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 19:47:04 +0200 Subject: [PATCH 26/39] Fix tests for PHP7.0 --- tests/Loggers/Formatters/ReplaceQueryParamsTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Loggers/Formatters/ReplaceQueryParamsTest.php b/tests/Loggers/Formatters/ReplaceQueryParamsTest.php index e2bde351..93356427 100644 --- a/tests/Loggers/Formatters/ReplaceQueryParamsTest.php +++ b/tests/Loggers/Formatters/ReplaceQueryParamsTest.php @@ -41,11 +41,11 @@ public function test_cannot_replace_object_params_without__toString() { $this->setExpectedException( Exception::class, - 'Given query param is an instance of Object and could not be converted to a string' + 'Given query param is an instance of ObjectClass and could not be converted to a string' ); $sql = 'SELECT * FROM table WHERE column = ?'; - $params = [new Object]; + $params = [new ObjectClass]; $this->formatter->format($sql, $params); } @@ -53,7 +53,7 @@ public function test_cannot_replace_object_params_without__toString() public function test_can_replace_object_params_with__toString() { $sql = 'SELECT * FROM table WHERE column = ?'; - $params = [new String]; + $params = [new StringClass]; $this->assertEquals( 'SELECT * FROM table WHERE column = "string"', @@ -79,11 +79,11 @@ protected function tearDown() } } -class Object +class ObjectClass { } -class String +class StringClass { public function __toString() { From 3b2a602d021cb32a43b6097a78e3f6c73e575cfb Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 14:12:47 -0400 Subject: [PATCH 27/39] Add ConnectionManager to service provider This way it can be used to extend(replace) and add custom connection drivers --- src/DoctrineServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php index cc6406bc..fac26bce 100644 --- a/src/DoctrineServiceProvider.php +++ b/src/DoctrineServiceProvider.php @@ -263,6 +263,7 @@ public function provides() AuthManager::class, EntityManager::class, DoctrineManager::class, + ConnectionManager::class, ClassMetadataFactory::class, EntityManagerInterface::class, ExtensionManager::class, From 91f9b9783359285d882198c5e7ffc7757bf03b85 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 15 Sep 2015 14:30:32 -0400 Subject: [PATCH 28/39] Add Metadata and Cache Manager to service provider --- src/DoctrineServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php index fac26bce..8c521956 100644 --- a/src/DoctrineServiceProvider.php +++ b/src/DoctrineServiceProvider.php @@ -264,6 +264,8 @@ public function provides() EntityManager::class, DoctrineManager::class, ConnectionManager::class, + CacheManager::class, + MetaDataManager::class, ClassMetadataFactory::class, EntityManagerInterface::class, ExtensionManager::class, From 4e0537fc9e36a70981412fc7e070fb2cfda7017c Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 20:56:30 +0200 Subject: [PATCH 29/39] Fix LaravelDebugbarLogger --- src/Loggers/LaravelDebugbarLogger.php | 13 ++++++++----- tests/Loggers/LaravelDebugbarLoggerTest.php | 6 ++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Loggers/LaravelDebugbarLogger.php b/src/Loggers/LaravelDebugbarLogger.php index 6e47aea7..f91501c3 100644 --- a/src/Loggers/LaravelDebugbarLogger.php +++ b/src/Loggers/LaravelDebugbarLogger.php @@ -29,10 +29,13 @@ public function __construct(LaravelDebugbar $debugbar) */ public function register(EntityManagerInterface $em, Configuration $configuration) { - $debugStack = new DebugStack; - $configuration->setSQLLogger($debugStack); - $this->debugbar->addCollector( - new DoctrineCollector($debugStack) - ); + if (!$this->debugbar->hasCollector('doctrine')) { + $debugStack = new DebugStack; + $configuration->setSQLLogger($debugStack); + + $this->debugbar->addCollector( + new DoctrineCollector($debugStack) + ); + } } } diff --git a/tests/Loggers/LaravelDebugbarLoggerTest.php b/tests/Loggers/LaravelDebugbarLoggerTest.php index 54c9d5dc..8cd63e3b 100644 --- a/tests/Loggers/LaravelDebugbarLoggerTest.php +++ b/tests/Loggers/LaravelDebugbarLoggerTest.php @@ -17,10 +17,16 @@ public function test_can_register() $configuration->shouldReceive('setSQLLogger') ->once(); + $debugbar->shouldReceive('hasCollector')->with('doctrine')->once()->andReturn(false); $debugbar->shouldReceive('addCollector')->once(); $logger = new LaravelDebugbarLogger($debugbar); $logger->register($em, $configuration); } + + protected function tearDown() + { + m::close(); + } } From f0e9693cc77aa0be80c95c9831612020778bdc8d Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 23:20:59 +0200 Subject: [PATCH 30/39] Cant' create and bind the same manager twice --- src/IlluminateRegistry.php | 20 ++++++++++++-------- tests/IlluminateRegistryTest.php | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/IlluminateRegistry.php b/src/IlluminateRegistry.php index 3fd53c81..2b89e427 100644 --- a/src/IlluminateRegistry.php +++ b/src/IlluminateRegistry.php @@ -67,11 +67,13 @@ public function __construct(Container $container, EntityManagerFactory $factory) */ public function addManager($manager, array $settings = []) { - $this->container->singleton($this->getManagerBindingName($manager), function () use ($settings) { - return $this->factory->create($settings); - }); + if (!$this->container->bound($this->getManagerBindingName($manager))) { + $this->container->singleton($this->getManagerBindingName($manager), function () use ($settings) { + return $this->factory->create($settings); + }); - $this->managers[$manager] = $manager; + $this->managers[$manager] = $manager; + } } /** @@ -79,11 +81,13 @@ public function addManager($manager, array $settings = []) */ public function addConnection($connection) { - $this->container->singleton($this->getConnectionBindingName($connection), function () use ($connection) { - return $this->getManager($connection)->getConnection(); - }); + if (!$this->container->bound($this->getManagerBindingName($connection))) { + $this->container->singleton($this->getConnectionBindingName($connection), function () use ($connection) { + return $this->getManager($connection)->getConnection(); + }); - $this->connections[$connection] = $connection; + $this->connections[$connection] = $connection; + } } /** diff --git a/tests/IlluminateRegistryTest.php b/tests/IlluminateRegistryTest.php index d53e27f4..a365538f 100644 --- a/tests/IlluminateRegistryTest.php +++ b/tests/IlluminateRegistryTest.php @@ -29,6 +29,7 @@ class IlluminateRegistryTest extends PHPUnit_Framework_TestCase protected function setUp() { $this->container = m::mock(Container::class); + $this->container->shouldReceive('bound')->andReturn(false); $this->factory = m::mock(EntityManagerFactory::class); $this->registry = new IlluminateRegistry( From 8bcd2a970250695f2868ba59d21a31972b767269 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Tue, 15 Sep 2015 23:31:11 +0200 Subject: [PATCH 31/39] Share debugstack through connections, to support multiple connections in Laravel debugbar --- src/Loggers/Debugbar/DoctrineCollector.php | 22 ++++++++++++++++++++++ src/Loggers/LaravelDebugbarLogger.php | 9 ++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/Loggers/Debugbar/DoctrineCollector.php diff --git a/src/Loggers/Debugbar/DoctrineCollector.php b/src/Loggers/Debugbar/DoctrineCollector.php new file mode 100644 index 00000000..42e6b208 --- /dev/null +++ b/src/Loggers/Debugbar/DoctrineCollector.php @@ -0,0 +1,22 @@ +debugStack; + } +} diff --git a/src/Loggers/LaravelDebugbarLogger.php b/src/Loggers/LaravelDebugbarLogger.php index f91501c3..d6655ed8 100644 --- a/src/Loggers/LaravelDebugbarLogger.php +++ b/src/Loggers/LaravelDebugbarLogger.php @@ -3,10 +3,10 @@ namespace LaravelDoctrine\ORM\Loggers; use Barryvdh\Debugbar\LaravelDebugbar; -use DebugBar\Bridge\DoctrineCollector; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManagerInterface; +use LaravelDoctrine\ORM\Loggers\Debugbar\DoctrineCollector; class LaravelDebugbarLogger implements Logger { @@ -29,13 +29,16 @@ public function __construct(LaravelDebugbar $debugbar) */ public function register(EntityManagerInterface $em, Configuration $configuration) { - if (!$this->debugbar->hasCollector('doctrine')) { + if ($this->debugbar->hasCollector('doctrine')) { + $debugStack = $this->debugbar->getCollector('doctrine')->getDebugStack(); + } else { $debugStack = new DebugStack; - $configuration->setSQLLogger($debugStack); $this->debugbar->addCollector( new DoctrineCollector($debugStack) ); } + + $configuration->setSQLLogger($debugStack); } } From 51d1757bfcc4a87c6eb4513b0dccadda3e990152 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Wed, 16 Sep 2015 11:14:16 +0200 Subject: [PATCH 32/39] Fix default manager binding --- src/DoctrineServiceProvider.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php index 8c521956..ab85c968 100644 --- a/src/DoctrineServiceProvider.php +++ b/src/DoctrineServiceProvider.php @@ -93,17 +93,9 @@ protected function mergeConfig() */ protected function registerEntityManager() { - $registry = $this->app->make('registry'); - - // Add all managers into the registry - foreach ($this->app->make('config')->get('doctrine.managers', []) as $manager => $settings) { - $registry->addManager($manager, $settings); - $registry->addConnection($manager); - } - // Bind the default Entity Manager - $this->app->singleton('em', function () use ($registry) { - return $registry->getManager(); + $this->app->singleton('em', function ($app) { + return $app->make('registry')->getManager(); }); $this->app->alias('em', EntityManager::class); @@ -115,9 +107,21 @@ protected function registerEntityManager() */ protected function registerManagerRegistry() { - $this->app->singleton('registry', IlluminateRegistry::class); - $this->app->alias('registry', ManagerRegistry::class); + $this->app->singleton('registry', function($app) { + + $registry = new IlluminateRegistry($app, $app->make(EntityManagerFactory::class)); + + // Add all managers into the registry + foreach ($app->make('config')->get('doctrine.managers', []) as $manager => $settings) { + $registry->addManager($manager, $settings); + $registry->addConnection($manager); + } + + return $registry; + }); + $this->app->alias('registry', ManagerRegistry::class); + $this->app->alias('registry', IlluminateRegistry::class); } /** From 002df8e6448053a40bc989c21c01401cd14d93f0 Mon Sep 17 00:00:00 2001 From: Daniel Withams Date: Wed, 16 Sep 2015 11:16:21 +0100 Subject: [PATCH 33/39] Fixing incorrect function name Correcting the function name used to determine if a new connection should be created. Was checking for Manager being Bound, rather than Connection being bound. --- src/IlluminateRegistry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IlluminateRegistry.php b/src/IlluminateRegistry.php index 2b89e427..76e65393 100644 --- a/src/IlluminateRegistry.php +++ b/src/IlluminateRegistry.php @@ -81,7 +81,7 @@ public function addManager($manager, array $settings = []) */ public function addConnection($connection) { - if (!$this->container->bound($this->getManagerBindingName($connection))) { + if (!$this->container->bound($this->getConnectionBindingName($connection))) { $this->container->singleton($this->getConnectionBindingName($connection), function () use ($connection) { return $this->getManager($connection)->getConnection(); }); From 7f23089312de09acaac587cefb242240bc066df4 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Wed, 16 Sep 2015 20:09:40 +0200 Subject: [PATCH 34/39] CS --- src/Console/ConfigMigrations/AtrauzziMigrator.php | 1 - src/Console/ConfigMigrations/MitchellMigrator.php | 2 +- src/DoctrineServiceProvider.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php index 0f1e11fd..5703a4b8 100644 --- a/src/Console/ConfigMigrations/AtrauzziMigrator.php +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -56,7 +56,6 @@ public function convertManager($sourceArray) $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']); $defaultRepo = ArrayUtil::get($sourceArray['default_repository']); $namespaces = []; - $driver = null; $connection = ArrayUtil::get($sourceArray['default']); // Non default configuration diff --git a/src/Console/ConfigMigrations/MitchellMigrator.php b/src/Console/ConfigMigrations/MitchellMigrator.php index 995113dd..1b89d2b2 100644 --- a/src/Console/ConfigMigrations/MitchellMigrator.php +++ b/src/Console/ConfigMigrations/MitchellMigrator.php @@ -8,7 +8,7 @@ class MitchellMigrator implements ConfigurationMigrator { /** - * @var FactoryFactory + * @var Factory */ protected $viewFactory; diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php index ab85c968..9a1dbf8c 100644 --- a/src/DoctrineServiceProvider.php +++ b/src/DoctrineServiceProvider.php @@ -107,7 +107,7 @@ protected function registerEntityManager() */ protected function registerManagerRegistry() { - $this->app->singleton('registry', function($app) { + $this->app->singleton('registry', function ($app) { $registry = new IlluminateRegistry($app, $app->make(EntityManagerFactory::class)); From 987bfa55ee62a124e08abdcc24b8a6cf27e6ea59 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Thu, 17 Sep 2015 12:13:53 +0200 Subject: [PATCH 35/39] Fix expire in PasswordResets --- src/Auth/Passwords/PasswordResetServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/Passwords/PasswordResetServiceProvider.php b/src/Auth/Passwords/PasswordResetServiceProvider.php index 41f2c904..02db3131 100644 --- a/src/Auth/Passwords/PasswordResetServiceProvider.php +++ b/src/Auth/Passwords/PasswordResetServiceProvider.php @@ -72,7 +72,7 @@ protected function registerTokenRepository() return new DoctrineTokenRepository( $this->app->make(ManagerRegistry::class)->getManagerForClass(PasswordReminder::class), $app['config']['app.key'], - $app['config']->get('auth.reminder.expire', 60) + $app['config']->get('auth.password.expire', 60) ); }); } From a55653d86f05ed9ec59cf31b8d38289e984a8c94 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Thu, 17 Sep 2015 17:21:10 +0200 Subject: [PATCH 36/39] Match php-cs-fixer with StyleCI --- .php_cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.php_cs b/.php_cs index 3d34b8e3..c2489d19 100644 --- a/.php_cs +++ b/.php_cs @@ -8,7 +8,7 @@ return Symfony\CS\Config\Config::create() ->setUsingCache(true) ->level(Symfony\CS\FixerInterface::PSR2_LEVEL) ->fixers(array( - 'psr0', + 'psr4', 'encoding', 'short_tag', 'blankline_after_open_tag', From 3dec2a998ccc1decc88b8c9d0206535a37f4ffd4 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Thu, 17 Sep 2015 11:22:00 -0400 Subject: [PATCH 37/39] Applied fixes from StyleCI --- .../Connections/MysqlConnectionTest.php | 18 +++++++++--------- .../Connections/OracleConnectionTest.php | 16 ++++++++-------- .../Connections/PgsqlConnectionTest.php | 18 +++++++++--------- .../Connections/SqlsrvConnectionTest.php | 14 +++++++------- tests/Extensions/MappingDriverChainTest.php | 8 ++++---- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/tests/Configuration/Connections/MysqlConnectionTest.php b/tests/Configuration/Connections/MysqlConnectionTest.php index bc1e8ba4..b2835c03 100644 --- a/tests/Configuration/Connections/MysqlConnectionTest.php +++ b/tests/Configuration/Connections/MysqlConnectionTest.php @@ -37,15 +37,15 @@ public function test_can_resolve() $resolved = $this->connection->resolve(); - $this->assertEquals('pdo_mysql', $resolved['driver']); - $this->assertEquals('host', $resolved['host']); - $this->assertEquals('database', $resolved['dbname']); - $this->assertEquals('username', $resolved['user']); - $this->assertEquals('password', $resolved['password']); - $this->assertEquals('charset', $resolved['charset']); - $this->assertEquals('port', $resolved['port']); - $this->assertEquals('unix_socket', $resolved['unix_socket']); - $this->assertEquals('prefix', $resolved['prefix']); + $this->assertEquals('pdo_mysql', $resolved['driver']); + $this->assertEquals('host', $resolved['host']); + $this->assertEquals('database', $resolved['dbname']); + $this->assertEquals('username', $resolved['user']); + $this->assertEquals('password', $resolved['password']); + $this->assertEquals('charset', $resolved['charset']); + $this->assertEquals('port', $resolved['port']); + $this->assertEquals('unix_socket', $resolved['unix_socket']); + $this->assertEquals('prefix', $resolved['prefix']); } protected function tearDown() diff --git a/tests/Configuration/Connections/OracleConnectionTest.php b/tests/Configuration/Connections/OracleConnectionTest.php index 99b26c70..895f8c2a 100644 --- a/tests/Configuration/Connections/OracleConnectionTest.php +++ b/tests/Configuration/Connections/OracleConnectionTest.php @@ -36,14 +36,14 @@ public function test_can_resolve() $resolved = $this->connection->resolve(); - $this->assertEquals('oci8', $resolved['driver']); - $this->assertEquals('host', $resolved['host']); - $this->assertEquals('database', $resolved['dbname']); - $this->assertEquals('username', $resolved['user']); - $this->assertEquals('password', $resolved['password']); - $this->assertEquals('charset', $resolved['charset']); - $this->assertEquals('port', $resolved['port']); - $this->assertEquals('prefix', $resolved['prefix']); + $this->assertEquals('oci8', $resolved['driver']); + $this->assertEquals('host', $resolved['host']); + $this->assertEquals('database', $resolved['dbname']); + $this->assertEquals('username', $resolved['user']); + $this->assertEquals('password', $resolved['password']); + $this->assertEquals('charset', $resolved['charset']); + $this->assertEquals('port', $resolved['port']); + $this->assertEquals('prefix', $resolved['prefix']); } protected function tearDown() diff --git a/tests/Configuration/Connections/PgsqlConnectionTest.php b/tests/Configuration/Connections/PgsqlConnectionTest.php index a3ffae4a..30d77c00 100644 --- a/tests/Configuration/Connections/PgsqlConnectionTest.php +++ b/tests/Configuration/Connections/PgsqlConnectionTest.php @@ -37,15 +37,15 @@ public function test_can_resolve() $resolved = $this->connection->resolve(); - $this->assertEquals('pdo_pgsql', $resolved['driver']); - $this->assertEquals('host', $resolved['host']); - $this->assertEquals('database', $resolved['dbname']); - $this->assertEquals('username', $resolved['user']); - $this->assertEquals('password', $resolved['password']); - $this->assertEquals('charset', $resolved['charset']); - $this->assertEquals('port', $resolved['port']); - $this->assertEquals('sslmode', $resolved['sslmode']); - $this->assertEquals('prefix', $resolved['prefix']); + $this->assertEquals('pdo_pgsql', $resolved['driver']); + $this->assertEquals('host', $resolved['host']); + $this->assertEquals('database', $resolved['dbname']); + $this->assertEquals('username', $resolved['user']); + $this->assertEquals('password', $resolved['password']); + $this->assertEquals('charset', $resolved['charset']); + $this->assertEquals('port', $resolved['port']); + $this->assertEquals('sslmode', $resolved['sslmode']); + $this->assertEquals('prefix', $resolved['prefix']); } protected function tearDown() diff --git a/tests/Configuration/Connections/SqlsrvConnectionTest.php b/tests/Configuration/Connections/SqlsrvConnectionTest.php index e8ac2cb8..796d1c6c 100644 --- a/tests/Configuration/Connections/SqlsrvConnectionTest.php +++ b/tests/Configuration/Connections/SqlsrvConnectionTest.php @@ -35,13 +35,13 @@ public function test_can_resolve() $resolved = $this->connection->resolve(); - $this->assertEquals('pdo_sqlsrv', $resolved['driver']); - $this->assertEquals('host', $resolved['host']); - $this->assertEquals('database', $resolved['dbname']); - $this->assertEquals('username', $resolved['user']); - $this->assertEquals('password', $resolved['password']); - $this->assertEquals('port', $resolved['port']); - $this->assertEquals('prefix', $resolved['prefix']); + $this->assertEquals('pdo_sqlsrv', $resolved['driver']); + $this->assertEquals('host', $resolved['host']); + $this->assertEquals('database', $resolved['dbname']); + $this->assertEquals('username', $resolved['user']); + $this->assertEquals('password', $resolved['password']); + $this->assertEquals('port', $resolved['port']); + $this->assertEquals('prefix', $resolved['prefix']); } protected function tearDown() diff --git a/tests/Extensions/MappingDriverChainTest.php b/tests/Extensions/MappingDriverChainTest.php index 83e3990f..5b0341ea 100644 --- a/tests/Extensions/MappingDriverChainTest.php +++ b/tests/Extensions/MappingDriverChainTest.php @@ -34,10 +34,10 @@ public function test_can_add_namespace() $this->chain->addNamespace('NewNamespace2'); $this->chain->addNamespace('NewNamespace3'); - $this->assertArrayHasKey('Namespace', $this->chain->getDrivers()); - $this->assertArrayHasKey('NewNamespace', $this->chain->getDrivers()); - $this->assertArrayHasKey('NewNamespace2', $this->chain->getDrivers()); - $this->assertArrayHasKey('NewNamespace3', $this->chain->getDrivers()); + $this->assertArrayHasKey('Namespace', $this->chain->getDrivers()); + $this->assertArrayHasKey('NewNamespace', $this->chain->getDrivers()); + $this->assertArrayHasKey('NewNamespace2', $this->chain->getDrivers()); + $this->assertArrayHasKey('NewNamespace3', $this->chain->getDrivers()); $this->assertArrayNotHasKey('NonExisting', $this->chain->getDrivers()); } From c177e374fbabaed24b07587e115d9fdeb52e2706 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Thu, 17 Sep 2015 17:33:25 +0200 Subject: [PATCH 38/39] Add StyleCI badge --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8d532654..8efed8f1 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ -[![GitHub release](https://img.shields.io/github/release/laravel-doctrine/orm.svg?style=flat)](https://packagist.org/packages/laravel-doctrine/orm) -[![Travis](https://img.shields.io/travis/laravel-doctrine/orm.svg?style=flat)](https://travis-ci.org/laravel-doctrine/orm) -[![Scrutinizer](https://img.shields.io/scrutinizer/g/laravel-doctrine/orm.svg?style=flat)](https://github.com/laravel-doctrine/orm) -[![Packagist](https://img.shields.io/packagist/dd/laravel-doctrine/orm.svg?style=flat)](https://packagist.org/packages/laravel-doctrine/orm) -[![Packagist](https://img.shields.io/packagist/dm/laravel-doctrine/orm.svg?style=flat)](https://packagist.org/packages/laravel-doctrine/orm) -[![Packagist](https://img.shields.io/packagist/dt/laravel-doctrine/orm.svg?style=flat)](https://packagist.org/packages/laravel-doctrine/orm) +[![GitHub release](https://img.shields.io/github/release/laravel-doctrine/orm.svg?style=flat-square)](https://packagist.org/packages/laravel-doctrine/orm) +[![Travis](https://img.shields.io/travis/laravel-doctrine/orm.svg?style=flat-square)](https://travis-ci.org/laravel-doctrine/orm) +[![StyleCI](https://styleci.io/repos/39036008/shield)](https://styleci.io/repos/39036008) +[![Scrutinizer](https://img.shields.io/scrutinizer/g/laravel-doctrine/orm.svg?style=flat-square)](https://github.com/laravel-doctrine/orm) +[![Packagist](https://img.shields.io/packagist/dm/laravel-doctrine/orm.svg?style=flat-square)](https://packagist.org/packages/laravel-doctrine/orm) +[![Packagist](https://img.shields.io/packagist/dt/laravel-doctrine/orm.svg?style=flat-square)](https://packagist.org/packages/laravel-doctrine/orm) *A drop-in Doctrine ORM 2 implementation for Laravel 5+* From 4d4cf8f8c7ea6cb5de830692529c8e00db29b461 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Thu, 17 Sep 2015 18:56:57 +0200 Subject: [PATCH 39/39] Remove the CanResetPassword trait because this is a exact duplicate of the one in Laravel --- src/Auth/Authenticatable.php | 18 +++++++++--------- src/Auth/CanResetPassword.php | 15 --------------- 2 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 src/Auth/CanResetPassword.php diff --git a/src/Auth/Authenticatable.php b/src/Auth/Authenticatable.php index f077ceac..34a93d4d 100644 --- a/src/Auth/Authenticatable.php +++ b/src/Auth/Authenticatable.php @@ -14,6 +14,15 @@ trait Authenticatable */ protected $rememberToken; + /** + * Get the column name for the primary key + * @return string + */ + public function getAuthIdentifierName() + { + return 'id'; + } + /** * Get the unique identifier for the user. * @return mixed @@ -25,15 +34,6 @@ public function getAuthIdentifier() return $this->{$name}; } - /** - * Get the column name for the primary key - * @return string - */ - public function getAuthIdentifierName() - { - return 'id'; - } - /** * @return string */ diff --git a/src/Auth/CanResetPassword.php b/src/Auth/CanResetPassword.php deleted file mode 100644 index b78efa84..00000000 --- a/src/Auth/CanResetPassword.php +++ /dev/null @@ -1,15 +0,0 @@ -email; - } -}