. */ namespace Doctrine\DBAL\Event\Listeners; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; use Doctrine\Common\EventSubscriber; /** * Should be used when Oracle Server default enviroment does not match the Doctrine requirements. * * The following enviroment variables are required for the Doctrine default date format: * * NLS_TIME_FORMAT="HH24:MI:SS" * NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" * NLS_TIMESTAMP_FORMAT="YYYY-MM-DD HH24:MI:SS" * NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM" * * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.com * @since 2.0 * @author Benjamin Eberlei */ class OracleSessionInit implements EventSubscriber { protected $_defaultSessionVars = array( 'NLS_TIME_FORMAT' => "HH24:MI:SS", 'NLS_DATE_FORMAT' => "YYYY-MM-DD HH24:MI:SS", 'NLS_TIMESTAMP_FORMAT' => "YYYY-MM-DD HH24:MI:SS", 'NLS_TIMESTAMP_TZ_FORMAT' => "YYYY-MM-DD HH24:MI:SS TZH:TZM", 'NLS_NUMERIC_CHARACTERS' => ".,", ); /** * @param array $oracleSessionVars */ public function __construct(array $oracleSessionVars = array()) { $this->_defaultSessionVars = array_merge($this->_defaultSessionVars, $oracleSessionVars); } /** * @param ConnectionEventArgs $args * @return void */ public function postConnect(ConnectionEventArgs $args) { if (count($this->_defaultSessionVars)) { array_change_key_case($this->_defaultSessionVars, \CASE_UPPER); $vars = array(); foreach ($this->_defaultSessionVars as $option => $value) { $vars[] = $option." = '".$value."'"; } $sql = "ALTER SESSION SET ".implode(" ", $vars); $args->getConnection()->executeUpdate($sql); } } public function getSubscribedEvents() { return array(Events::postConnect); } }