Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / lib / Doctrine / DBAL / Event / Listeners / MysqlSessionInit.php
1 <?php
2 /*
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license. For more information, see
17  * <http://www.doctrine-project.org>.
18 */
19
20 namespace Doctrine\DBAL\Event\Listeners;
21
22 use Doctrine\DBAL\Event\ConnectionEventArgs;
23 use Doctrine\DBAL\Events;
24 use Doctrine\Common\EventSubscriber;
25
26 /**
27  * MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection
28  *
29  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
30  * @link        www.doctrine-project.com
31  * @since       1.0
32  * @version     $Revision$
33  * @author      Benjamin Eberlei <kontakt@beberlei.de>
34  * @deprecated  Use "charset" option to PDO MySQL Connection instead.
35  */
36 class MysqlSessionInit implements EventSubscriber
37 {
38     /**
39      * @var string
40      */
41     private $_charset;
42
43     /**
44      * @var string
45      */
46     private $_collation;
47
48     /**
49      * Configure Charset and Collation options of MySQL Client for each Connection
50      *
51      * @param string $charset
52      * @param string $collation
53      */
54     public function __construct($charset = 'utf8', $collation = false)
55     {
56         $this->_charset = $charset;
57         $this->_collation = $collation;
58     }
59
60     /**
61      * @param ConnectionEventArgs $args
62      * @return void
63      */
64     public function postConnect(ConnectionEventArgs $args)
65     {
66         $collation = ($this->_collation) ? " COLLATE ".$this->_collation : "";
67         $args->getConnection()->executeUpdate("SET NAMES ".$this->_charset . $collation);
68     }
69
70     public function getSubscribedEvents()
71     {
72         return array(Events::postConnect);
73     }
74 }