Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Liscare/820f622fa8ca1d866e8dfcec038551f0 to your computer and use it in GitHub Desktop.
Save Liscare/820f622fa8ca1d866e8dfcec038551f0 to your computer and use it in GitHub Desktop.
Symfony4 - Doctrine2 - Oracle
<?php
// src/EventListener/OracleDoctrineTypeMappingListener.php
namespace App\EventListener;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
/**
* Changes Doctrine's default Oracle-specific column type mapping to Doctrine
* mapping types. This listener modifies doctrine type mapping for
* OraclePlatform.
*/
class OracleDoctrineTypeMappingListener implements EventSubscriber
{
public function getSubscribedEvents()
{
return array(Events::postConnect);
}
/**
* Doctrine defines its primary database abstraction information in what it
* calls "Platform" classes (e.g. Doctrine\DBAL\Platforms\AbstractPlatform).
* Each database Doctrine supports implements a Platform file
* (e.g. OraclePlatform or MySqlPlatform).
*/
public function postConnect(ConnectionEventArgs $args)
{
if ($args->getConnection()->getDatabasePlatform()->getName() == 'oracle') {
$args
->getConnection()
->getDatabasePlatform()
->registerDoctrineTypeMapping('date', 'date');
}
}
}
<?php
// src/EventListener/OracleSessionInitListener.php
namespace App\EventListener;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Event\Listeners\OracleSessionInit;
/**
* Should be used when Oracle Server default environment does not match the Doctrine requirements.
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class OracleSessionInitListener extends OracleSessionInit
{
public function postConnect(ConnectionEventArgs $args)
{
if ($args->getConnection()->getDatabasePlatform()->getName() == 'oracle') {
parent::postConnect($args);
}
}
}
#config/services.yaml
services:
app.doctrine.dbal.events.oracle_session_init.listener:
class: App\EventListener\OracleSessionInitListener
tags:
- { name: doctrine.event_listener, event: postConnect }
app.doctrine.dbal.oracle_platform.type_mapping.listener:
class: App\EventListener\OracleDoctrineTypeMappingListener
tags:
- { name: doctrine.event_listener, event: postConnect }
<!-- public/web.config-->
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.php" />
</files>
</defaultDocument>
<rewrite>
<rules>
<rule name="Silex Front Controller" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
@Liscare
Copy link
Author

Liscare commented Jul 23, 2020

Adapted from phpfour's code to Symfony 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment