1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Cli\Connection\ConnectionFactory |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Cli\Connection; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\ConfigurationInterface; |
24
|
|
|
use TechDivision\Import\Connection\PDOConnectionWrapper; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The connection factory implementation. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/techdivision/import-cli-simple |
33
|
|
|
* @link http://www.techdivision.com |
34
|
|
|
*/ |
35
|
|
|
class ConnectionFactory |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create's and return's the connection to use. |
40
|
|
|
* |
41
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration with the data to create the connection with |
42
|
|
|
* |
43
|
|
|
* @return \TechDivision\Import\Connection\PDOConnectionWrapper The initialized connection |
44
|
|
|
*/ |
45
|
|
|
public static function createConnection(ConfigurationInterface $configuration) |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
// initialize the PDO connection |
49
|
|
|
$dsn = $configuration->getDatabase()->getDsn(); |
50
|
|
|
$username = $configuration->getDatabase()->getUsername(); |
51
|
|
|
$password = $configuration->getDatabase()->getPassword(); |
52
|
|
|
$connection = new \PDO($dsn, $username, $password); |
53
|
|
|
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
54
|
|
|
|
55
|
|
|
// reurn the wrapped PDO connection |
56
|
|
|
return new PDOConnectionWrapper($connection); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|