Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ composer.lock
.DS_Store
.php_cs.cache

/tests/Stubs/storage/framework/views/*
!/tests/Stubs/storage/framework/views/.gitkeep
/tests/Stubs/storage/doctrine.generated.php
.idea
laravel-doctrine-orm.iml
155 changes: 155 additions & 0 deletions src/Console/ConfigMigrations/AtrauzziMigrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: mduncan
* Date: 9/14/15
* Time: 11:25 AM
*/

namespace LaravelDoctrine\ORM\Console\ConfigMigrations;


use Illuminate\Contracts\View\Factory;
use LaravelDoctrine\ORM\Utilities\ArrayUtil;

class AtrauzziMigrator implements ConfigurationMigrator
{

private $viewFactory;

/**
* @param Factory $viewFactory
*/
public function __construct(Factory $viewFactory)
{
$this->viewFactory = $viewFactory;
//add namespace for views
$this->viewFactory->addNamespace('atrauzzi', realpath(__DIR__ . '/templates/atrauzzi'));
$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);
$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);

return $unescaped;
}

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) {
$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;
}
}
//only do this if all the same driver
if ($hasNamespaces && $sameDriver) {
$driver = $sourceArray['metadata'][0]['driver'];

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 {
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 {
$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){
$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('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();
$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;
}
}
2 changes: 1 addition & 1 deletion src/Console/ConfigMigrations/ConfigurationMigrator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace LaravelDoctrine\ORM\ConfigMigrations;
namespace LaravelDoctrine\ORM\Console\ConfigMigrations;

use Illuminate\Contracts\View\Factory;

Expand Down
6 changes: 4 additions & 2 deletions src/Console/ConfigMigrations/MitchellMigrator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace LaravelDoctrine\ORM\ConfigMigrations;
namespace LaravelDoctrine\ORM\Console\ConfigMigrations;

use Illuminate\Contracts\View\Factory;
use LaravelDoctrine\ORM\Utilities\ArrayUtil;
Expand All @@ -17,6 +17,7 @@ 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'));
}

/**
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'env(\'CACHE_DRIVER\',\''.$cacheProvider.'\')'}}},
'second_level' => false,
],
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@if(isset($sourceArray['custom_types']))
'custom_types' => [
@foreach($sourceArray['custom_types'] as $key => $val)
'{{$key}}' => '{{$val}}'
@endforeach
],
@endif
21 changes: 21 additions & 0 deletions src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php
Original file line number Diff line number Diff line change
@@ -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' => []
]
Original file line number Diff line number Diff line change
@@ -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' => [
Expand Down Expand Up @@ -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
]
];
Original file line number Diff line number Diff line change
@@ -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,
]
],
Loading