Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / lib / Doctrine / DBAL / Driver / OCI8 / Driver.php
1 <?php
2 /*
3  *  $Id$
4  *
5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16  *
17  * This software consists of voluntary contributions made by many individuals
18  * and is licensed under the MIT license. For more information, see
19  * <http://www.doctrine-project.org>.
20  */
21
22 namespace Doctrine\DBAL\Driver\OCI8;
23
24 use Doctrine\DBAL\Platforms;
25
26 /**
27  * A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
28  *
29  * @author Roman Borschel <roman@code-factory.org>
30  * @since 2.0
31  */
32 class Driver implements \Doctrine\DBAL\Driver
33 {
34     public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
35     {
36         return new OCI8Connection(
37             $username,
38             $password,
39             $this->_constructDsn($params),
40             isset($params['charset']) ? $params['charset'] : null,
41             isset($params['sessionMode']) ? $params['sessionMode'] : OCI_DEFAULT,
42             isset($params['persistent']) ? $params['persistent'] : false
43         );
44     }
45
46     /**
47      * Constructs the Oracle DSN.
48      *
49      * @return string The DSN.
50      */
51     protected function _constructDsn(array $params)
52     {
53         $dsn = '';
54         if (isset($params['host']) && $params['host'] != '') {
55             $dsn .= '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
56                    '(HOST=' . $params['host'] . ')';
57
58             if (isset($params['port'])) {
59                 $dsn .= '(PORT=' . $params['port'] . ')';
60             } else {
61                 $dsn .= '(PORT=1521)';
62             }
63
64             if (isset($params['service']) && $params['service'] == true) {
65                 $dsn .= '))(CONNECT_DATA=(SERVICE_NAME=' . $params['dbname'] . '))';
66             } else {
67                 $dsn .= '))(CONNECT_DATA=(SID=' . $params['dbname'] . '))';
68             }
69             if (isset($params['pooled']) && $params['pooled'] == true) {
70                 $dsn .= '(SERVER=POOLED)';
71             }
72             $dsn .= ')';
73         } else {
74             $dsn .= $params['dbname'];
75         }
76         return $dsn;
77     }
78
79     public function getDatabasePlatform()
80     {
81         return new \Doctrine\DBAL\Platforms\OraclePlatform();
82     }
83
84     public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
85     {
86         return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn);
87     }
88
89     public function getName()
90     {
91         return 'oci8';
92     }
93
94     public function getDatabase(\Doctrine\DBAL\Connection $conn)
95     {
96         $params = $conn->getParams();
97         return $params['user'];
98     }
99 }