-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:kirkbushell/laravel-doctrine into…
… kirkbushell-master Conflicts: src/Filters/TrashedFilter.php src/LaravelDoctrineServiceProvider.php
- Loading branch information
Showing
13 changed files
with
448 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
composer.phar | ||
composer.lock | ||
.DS_Store | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="all"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php namespace Mitch\LaravelDoctrine\Configuration; | ||
|
||
class DriverMapper | ||
{ | ||
/** | ||
* An array of mappers that can be cycled through to determine which mapper | ||
* is appropriate for a given configuration arrangement. | ||
* | ||
* @var array | ||
*/ | ||
private $configurationMappers = []; | ||
|
||
/** | ||
* Register a new driver configuration mapper. | ||
* | ||
* @param Mapper $mapper | ||
*/ | ||
public function registerMapper(Mapper $mapper) | ||
{ | ||
$this->configurationMappers[] = $mapper; | ||
} | ||
|
||
/** | ||
* Map the Laravel configuration to a configuration driver, return the result. | ||
* | ||
* @param $configuration | ||
* @return array | ||
* @throws \Exception | ||
*/ | ||
public function map($configuration) | ||
{ | ||
foreach ($this->configurationMappers as $mapper) { | ||
if ($mapper->isAppropriate($configuration)) { | ||
return $mapper->map($configuration); | ||
} | ||
} | ||
|
||
throw new \Exception("Driver {$configuration['driver']} unsupported by package at this time."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php namespace Mitch\LaravelDoctrine\Configuration; | ||
|
||
interface Mapper | ||
{ | ||
/** | ||
* Handles the mapping of configuration. | ||
* | ||
* @param array $configuration | ||
* @return mixed | ||
*/ | ||
public function map(array $configuration); | ||
|
||
/** | ||
* Determines whether the configuration array is appropriate for the mapper. | ||
* | ||
* @param array $configuration | ||
* @return mixed | ||
*/ | ||
public function isAppropriate(array $configuration); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php namespace Mitch\LaravelDoctrine\Configuration; | ||
|
||
class SqlConfigurationMapper implements Mapper | ||
{ | ||
/** | ||
* Creates the configuration mapping for SQL database engines, including SQL server, MySQL and PostgreSQL. | ||
* | ||
* @param array $configuration | ||
* @return array | ||
*/ | ||
public function map(array $configuration) | ||
{ | ||
return [ | ||
'driver' => $this->driver($configuration['driver']), | ||
'host' => $configuration['host'], | ||
'dbname' => $configuration['database'], | ||
'user' => $configuration['username'], | ||
'password' => $configuration['password'], | ||
'charset' => $configuration['charset'] | ||
]; | ||
} | ||
|
||
/** | ||
* Is suitable for mapping configurations that use a mysql, postgres or sqlserv setup. | ||
* | ||
* @param array $configuration | ||
* @return boolean | ||
*/ | ||
public function isAppropriate(array $configuration) | ||
{ | ||
return in_array($configuration['driver'], ['sqlsrv', 'mysql', 'pgsql']); | ||
} | ||
|
||
/** | ||
* Maps the Laravel driver syntax to an Sql doctrine format. | ||
* | ||
* @param $l4Driver | ||
* @return string | ||
*/ | ||
public function driver($l4Driver) | ||
{ | ||
$doctrineDrivers = ['mysql' => 'pdo_mysql', 'sqlsrv' => 'pdo_sqlsrv', 'pgsql' => 'pdo_pgsql']; | ||
|
||
return $doctrineDrivers[$l4Driver]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php namespace Mitch\LaravelDoctrine\Configuration; | ||
|
||
class SqliteConfigurationMapper implements Mapper | ||
{ | ||
/** | ||
* Map the L4 configuration array to a sqlite-friendly doctrine configuration. | ||
* | ||
* @param array $configuration | ||
* @return array | ||
*/ | ||
public function map(array $configuration) | ||
{ | ||
$sqliteConfig = [ | ||
'driver' => 'pdo_sqlite', | ||
'user' => @$configuration['username'], | ||
'password' => @$configuration['password'] | ||
]; | ||
|
||
$this->databaseLocation($configuration, $sqliteConfig); | ||
|
||
return $sqliteConfig; | ||
} | ||
|
||
/** | ||
* Is only suitable for sqlite configuration mapping. | ||
* | ||
* @param array $configuration | ||
* @return bool | ||
*/ | ||
public function isAppropriate(array $configuration) | ||
{ | ||
return $configuration['driver'] == 'sqlite'; | ||
} | ||
|
||
/** | ||
* Determines the location of the database and appends this to the sqlite configuration. | ||
* | ||
* @param $configuration | ||
* @param $sqliteConfig | ||
*/ | ||
private function databaseLocation($configuration, &$sqliteConfig) | ||
{ | ||
if ($configuration['database'] == ':memory:') { | ||
$sqliteConfig['memory'] = true; | ||
} | ||
else { | ||
$sqliteConfig['path'] = app_path('database').'/'.$configuration['database'].'.sqlite'; | ||
} | ||
} | ||
} |
Oops, something went wrong.