Skip to content

Commit

Permalink
Merge branch '1.5' into 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
eigan committed Jul 23, 2020
2 parents 3902b4a + ed08f53 commit 5441be7
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
| Configure meta-data, query and result caching here.
| Optionally you can enable second level caching.
|
| Available: apc|array|file|memcached|php_file|redis|void
| Available: apc|array|file|illuminate|memcached|php_file|redis|void
|
*/
'cache' => [
Expand Down
5 changes: 4 additions & 1 deletion src/Configuration/Cache/FileCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\Common\Cache\FilesystemCache;
use Illuminate\Contracts\Config\Repository;
use LaravelDoctrine\ORM\Configuration\Driver;
use function storage_path;

class FileCacheProvider implements Driver
{
Expand All @@ -28,8 +29,10 @@ public function __construct(Repository $config)
*/
public function resolve(array $settings = [])
{
$path = $settings['path'] ?? $this->config->get('cache.stores.file.path', storage_path('framework/cache'));

return new FilesystemCache(
$this->config->get('cache.stores.file.path', storage_path('framework/cache'))
$path
);
}
}
16 changes: 14 additions & 2 deletions src/Configuration/Cache/IlluminateCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace LaravelDoctrine\ORM\Configuration\Cache;

use const E_USER_DEPRECATED;
use Illuminate\Contracts\Cache\Factory;
use InvalidArgumentException;
use LaravelDoctrine\ORM\Configuration\Driver;

abstract class IlluminateCacheProvider implements Driver
class IlluminateCacheProvider implements Driver
{
/**
* @var Factory
Expand All @@ -32,8 +34,18 @@ public function __construct(Factory $cache)
*/
public function resolve(array $settings = [])
{
$store = $this->store ?? $settings['store'] ?? null;

if ($store === null) {
throw new InvalidArgumentException('Please specify the `store` when using the "illuminate" cache driver.');
}

if ($this->store && isset($settings['store'])) {
trigger_error('Using driver "' . $this->store . '" with a custom store is deprecated. Please use the "illuminate" driver.', E_USER_DEPRECATED);
}

return new IlluminateCacheAdapter(
$this->cache->store($this->store)
$this->cache->store($store)
);
}
}
4 changes: 3 additions & 1 deletion src/Configuration/Cache/PhpFileCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public function __construct(Repository $config)
*/
public function resolve(array $settings = [])
{
$path = $settings['path'] ?? $this->config->get('cache.stores.file.path', storage_path('framework/cache'));

return new PhpFileCache(
$this->config->get('cache.stores.file.path', storage_path('framework/cache'))
$path
);
}
}
4 changes: 4 additions & 0 deletions src/Configuration/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function resolve(array $settings = [])
$resolvedSettings['serverVersion'] = $settings['serverVersion'];
}

if (!empty($settings['defaultTableOptions'])) {
$resolvedSettings['defaultTableOptions'] = $settings['defaultTableOptions'];
}

return $resolvedSettings;
}

Expand Down
5 changes: 3 additions & 2 deletions src/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ private function applyNamedCacheConfiguration($cacheName)
$defaultDriver = $this->config->get('doctrine.cache.default', 'array');
$defaultNamespace = $this->config->get('doctrine.cache.namespace');

$driver = $this->config->get('doctrine.cache.' . $cacheName . '.driver', $defaultDriver);
$settings = $this->config->get('doctrine.cache.' . $cacheName, []);
$driver = $settings['driver'] ?? $defaultDriver;

$cache = $this->cache->driver($driver);
$cache = $this->cache->driver($driver, $settings);

if ($namespace = $this->config->get('doctrine.cache.' . $cacheName . '.namespace', $defaultNamespace)) {
$cache->setNamespace($namespace);
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @method static \Doctrine\ORM\Cache|null getCache()
* @method static \Doctrine\DBAL\Connection getConnection()
* @method static \Doctrine\ORM\Query\Expr getExpressionBuilder()
* @method statuc \Doctrine\ORM\Utility\IdentifierFlattener getIdentifierFlattener()
* @method static \Doctrine\ORM\Utility\IdentifierFlattener getIdentifierFlattener()
* @method static void beginTransaction()
* @method static mixed transactional(callable $func)
* @method static void commit()
Expand Down
3 changes: 2 additions & 1 deletion src/Testing/ConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LaravelDoctrine\ORM\Testing;

use Illuminate\Contracts\Config\Repository;
use Illuminate\Support\Arr;

class ConfigRepository implements Repository
{
Expand All @@ -23,7 +24,7 @@ public function all()

public function get($key, $default = null)
{
return $this->items[$key] ?? $default;
return Arr::get($this->items, $key, $default);
}

public function set($key, $value = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/FactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function create(array $attributes = [])

if ($this->amount === 1) {
$manager->persist($results);
$this->callAfterCreating(collect($results));
$this->callAfterCreating(collect([$results]));
} else {
foreach ($results as $result) {
$manager->persist($result);
Expand Down
26 changes: 24 additions & 2 deletions tests/Configuration/Connections/MasterSlaveConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ private function getInputConfig()
'port' => 3309
],
],
'serverVersion' => '5.8',
'serverVersion' => '5.8',
'defaultTableOptions' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
]
];
}

Expand Down Expand Up @@ -136,6 +140,10 @@ private function getExpectedConfig()
'unix_socket' => 'unix_socket',
'prefix' => 'prefix'
],
'defaultTableOptions' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
],
];
}

Expand Down Expand Up @@ -221,6 +229,11 @@ private function getOracleExpectedConfig()
$expectedConfigOracle['master']['user'] = 'homestead1';
$expectedConfigOracle['serverVersion'] = '5.8';

$expectedConfigOracle['defaultTableOptions'] = [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
];

return $expectedConfigOracle;
}

Expand All @@ -239,6 +252,11 @@ private function getPgsqlExpectedConfig()
$expectedConfigPgsql['slaves'][1]['sslmode'] = 'sslmode';
$expectedConfigPgsql['serverVersion'] = '5.8';

$expectedConfigPgsql['defaultTableOptions'] = [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
];

return $expectedConfigPgsql;
}

Expand Down Expand Up @@ -276,7 +294,11 @@ private function getSqliteExpectedConfig()
'memory' => true,
'path' => ':memory',
],
'serverVersion' => '5.8',
'serverVersion' => '5.8',
'defaultTableOptions' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
]
];
}

Expand Down
Loading

0 comments on commit 5441be7

Please sign in to comment.