<?xml version="1.0" encoding="UTF-8" ?>

<xsd:schema xmlns="http://symfony.com/schema/dic/doctrine"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://symfony.com/schema/dic/doctrine"
    elementFormDefault="qualified">

    <xsd:element name="config">
        <xsd:complexType>
            <xsd:all>
                <xsd:element name="dbal" type="dbal" minOccurs="0" maxOccurs="1" />
                <xsd:element name="orm" type="orm" minOccurs="0" maxOccurs="1" />
            </xsd:all>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="named_scalar">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="name" type="xsd:string" use="required" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

    <!-- DBAL configuration -->

    <xsd:attributeGroup name="connection-config">
        <xsd:attribute name="driver" type="xsd:string" />
        <xsd:attribute name="driver-class" type="xsd:string" />
        <xsd:attribute name="wrapper-class" type="xsd:string" />
        <xsd:attribute name="keep-slave" type="xsd:string" />
        <xsd:attribute name="keep-replica" type="xsd:string" />
        <xsd:attribute name="platform-service" type="xsd:string" />
        <xsd:attribute name="auto-commit" type="xsd:string" />
        <xsd:attribute name="schema-filter" type="xsd:string" />
        <xsd:attribute name="logging" type="xsd:string" default="false" />
        <xsd:attribute name="profiling" type="xsd:string" default="false" />
        <xsd:attribute name="profiling-collect-backtrace" type="xsd:string" default="false" />
        <xsd:attribute name="profiling-collect-schema-errors" type="xsd:string" default="true" />
        <xsd:attribute name="server-version" type="xsd:string" />
        <xsd:attribute name="schema-manager-factory" type="xsd:string" />
        <xsd:attribute name="result-cache" type="xsd:string" />
        <xsd:attribute name="use-savepoints" type="xsd:boolean" />
        <xsd:attribute name="disable-type-comments" type="xsd:boolean" />
        <xsd:attributeGroup ref="driver-config" />
    </xsd:attributeGroup>

    <xsd:attributeGroup name="driver-config">
        <xsd:attribute name="url" type="xsd:string" />
        <xsd:attribute name="dbname" type="xsd:string" />
        <xsd:attribute name="host" type="xsd:string" />
        <xsd:attribute name="port" type="xsd:string" />
        <xsd:attribute name="user" type="xsd:string" />
        <xsd:attribute name="password" type="xsd:string" />
        <xsd:attribute name="override-url" type="xsd:boolean" />
        <xsd:attribute name="dbname-suffix" type="xsd:string" />
        <xsd:attribute name="application-name" type="xsd:string" />
        <xsd:attribute name="path" type="xsd:string" />
        <xsd:attribute name="unix-socket" type="xsd:string" />
        <xsd:attribute name="memory" type="xsd:string" />
        <xsd:attribute name="charset" type="xsd:string" />
        <xsd:attribute name="persistent" type="xsd:string" />
        <xsd:attribute name="protocol" type="xsd:string" />
        <xsd:attribute name="server" type="xsd:string" />
        <xsd:attribute name="service" type="xsd:string" />
        <xsd:attribute name="servicename" type="xsd:string" />
        <xsd:attribute name="session-mode" type="xsd:string" />
        <xsd:attribute name="default_dbname" type="xsd:string" />
        <xsd:attribute name="sslmode" type="xsd:string" />
        <xsd:attribute name="sslrootcert" type="xsd:string" />
        <xsd:attribute name="sslcert" type="xsd:string" />
        <xsd:attribute name="sslkey" type="xsd:string" />
        <xsd:attribute name="sslcrl" type="xsd:string" />
        <xsd:attribute name="pooled" type="xsd:string" />
        <xsd:attribute name="multiple-active-result-sets" type="xsd:string" />
        <xsd:attribute name="connectstring" type="xsd:string" />
        <xsd:attribute name="instancename" type="xsd:string" />
    </xsd:attributeGroup>

    <xsd:group name="connection-child-config">
        <xsd:choice>
            <xsd:element name="option" type="option" />
            <xsd:element name="mapping-type" type="named_scalar" />
            <xsd:element name="slave" type="replica" />
            <xsd:element name="replica" type="replica" />
            <xsd:element name="default-table-option" type="named_scalar" />
        </xsd:choice>
    </xsd:group>

    <xsd:complexType name="dbal">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="connection" type="connection" />
            <xsd:element name="type" type="named_scalar" />
            <xsd:element name="driver-scheme" type="driver_scheme" />
            <xsd:group ref="connection-child-config" />
        </xsd:choice>

        <xsd:attribute name="default-connection" type="xsd:string" />
        <xsd:attributeGroup ref="connection-config" />
    </xsd:complexType>

    <xsd:complexType name="driver_scheme">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="scheme" type="xsd:string" use="required" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

    <xsd:complexType name="option">
        <xsd:complexContent>
            <xsd:extension base="xsd:anyType">
                <xsd:attribute name="key" type="xsd:string" use="required" />
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:complexType name="connection">
        <xsd:group ref="connection-child-config" minOccurs="0" maxOccurs="unbounded" />

        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attributeGroup ref="connection-config" />
    </xsd:complexType>

    <xsd:complexType name="replica">
        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attributeGroup ref="driver-config" />
    </xsd:complexType>

    <!-- ORM configuration -->

    <xsd:complexType name="mapping">
        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attribute name="type" type="xsd:string" />
        <xsd:attribute name="dir" type="xsd:string" />
        <xsd:attribute name="alias" type="xsd:string" />
        <xsd:attribute name="prefix" type="xsd:string" />
        <xsd:attribute name="is-bundle" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="orm">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="entity-manager" type="entity_manager" />
            <xsd:element name="resolve-target-entity" type="resolve_target_entity" minOccurs="0" maxOccurs="unbounded" />
            <xsd:group ref="entity-manager-child-config" />
        </xsd:choice>

        <xsd:attribute name="default-entity-manager" type="xsd:string" />
        <xsd:attribute name="proxy-dir" type="xsd:string" />
        <xsd:attribute name="proxy-namespace" type="xsd:string" />
        <xsd:attribute name="auto-generate-proxy-classes" type="xsd:string" default="false" />
        <xsd:attribute name="enable-lazy-ghost-objects" type="xsd:boolean" />
        <xsd:attribute name="enable-native-lazy-objects" type="xsd:boolean" />
        <xsd:attributeGroup ref="entity-manager-config" />
    </xsd:complexType>

    <xsd:complexType name="resolve_target_entity">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="interface" type="xsd:string" use="required" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

    <xsd:simpleType name="cache_driver_type">
        <xsd:restriction base="xsd:token">
            <xsd:enumeration value="pool"/>
            <xsd:enumeration value="service"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="cache_driver">
        <xsd:attribute name="type" type="cache_driver_type" default="pool" />
        <xsd:attribute name="id" type="xsd:string" />
        <xsd:attribute name="pool" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="entity_listeners">
        <xsd:choice minOccurs="1">
            <xsd:element name="entity" type="entity_listeners_entity" minOccurs="1" maxOccurs="unbounded" />
        </xsd:choice>
    </xsd:complexType>

    <xsd:complexType name="entity_listeners_entity">
        <xsd:choice minOccurs="1">
            <xsd:element name="listener" type="entity_listeners_listener" minOccurs="1" maxOccurs="unbounded" />
        </xsd:choice>
        <xsd:attribute name="class" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="entity_listeners_listener">
        <xsd:choice minOccurs="1">
            <xsd:element name="event" type="entity_listeners_event" minOccurs="1" maxOccurs="unbounded" />
        </xsd:choice>
        <xsd:attribute name="class" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="entity_listeners_event">
        <xsd:attribute name="type" type="xsd:string" />
        <xsd:attribute name="method" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="entity_manager">
        <xsd:group ref="entity-manager-child-config" minOccurs="0" maxOccurs="unbounded" />

        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attributeGroup ref="entity-manager-config" />
    </xsd:complexType>

    <xsd:group name="entity-manager-child-config">
        <xsd:choice>
            <xsd:element name="mapping" type="mapping" />
            <xsd:element name="metadata-cache-driver" type="cache_driver" minOccurs="0" maxOccurs="1" />
            <xsd:element name="result-cache-driver" type="cache_driver" minOccurs="0" maxOccurs="1" />
            <xsd:element name="query-cache-driver" type="cache_driver" minOccurs="0" maxOccurs="1" />
            <xsd:element name="dql" type="dql" minOccurs="0" maxOccurs="1" />
            <xsd:element name="hydrator" type="named_scalar" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="filter" type="filter" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="entity-listeners" type="entity_listeners" minOccurs="0" maxOccurs="1" />
            <xsd:element name="second-level-cache" type="second-level-cache" minOccurs="0" maxOccurs="1" />
            <xsd:element name="schema-ignore-class" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="identity-generation-preference" type="identity_generation_preference" minOccurs="0" maxOccurs="unbounded" />
        </xsd:choice>
    </xsd:group>

    <xsd:attributeGroup name="entity-manager-config">
        <xsd:attribute name="auto-mapping" type="xsd:string" />
        <xsd:attribute name="connection" type="xsd:string" />
        <xsd:attribute name="default-repository-class" type="xsd:string" />
        <xsd:attribute name="class-metadata-factory-name" type="xsd:string" />
        <xsd:attribute name="fetch-mode-subselect-batch-size" type="xsd:int" />
        <xsd:attribute name="naming-strategy" type="xsd:string" />
        <xsd:attribute name="quote-strategy" type="xsd:string" />
        <xsd:attribute name="typed-field-mapper" type="xsd:string" />
        <xsd:attribute name="entity-listener-resolver" type="xsd:string" />
        <xsd:attribute name="repository-factory" type="xsd:string" />
        <xsd:attribute name="report-fields-where-declared" type="xsd:boolean" />
        <xsd:attribute name="validate-xml-mapping" type="xsd:boolean" />
    </xsd:attributeGroup>

    <xsd:complexType name="filter" mixed="true">
        <xsd:choice minOccurs="0">
            <xsd:element name="parameter" type="named_scalar" minOccurs="0" maxOccurs="unbounded" />
        </xsd:choice>
        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attribute name="class" type="xsd:string" />
        <xsd:attribute name="enabled" type="xsd:boolean" />
    </xsd:complexType>

    <xsd:complexType name="second-level-cache-region" mixed="true">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="cache-driver" type="cache_driver" minOccurs="0" maxOccurs="1" />
        </xsd:choice>
        <xsd:attribute name="name" type="xsd:string" />
        <xsd:attribute name="type" type="xsd:string" />
        <xsd:attribute name="service" type="xsd:string" />
        <xsd:attribute name="lifetime" type="xsd:integer" />
        <xsd:attribute name="lock-lifetime" type="xsd:integer" />
        <xsd:attribute name="cache-driver" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="second-level-cache-logger" mixed="true">
        <xsd:attribute name="name" type="xsd:string" />
        <xsd:attribute name="service" type="xsd:string" />
    </xsd:complexType>

    <xsd:complexType name="second-level-cache" mixed="true">
         <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="logger" type="second-level-cache-logger" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="region" type="second-level-cache-region" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="region-cache-driver" type="cache_driver" minOccurs="0" maxOccurs="1" />
        </xsd:choice>
        <xsd:attribute name="enabled" type="xsd:boolean" default="true"/>
        <xsd:attribute name="log-enabled" type="xsd:boolean" default="true"/>
        <xsd:attribute name="factory" type="xsd:string" />
        <xsd:attribute name="query-validator" type="xsd:string" />
        <xsd:attribute name="region-lifetime" type="xsd:integer" />
        <xsd:attribute name="region-lock-lifetime" type="xsd:integer" />
    </xsd:complexType>

    <xsd:complexType name="dql">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="string-function" type="named_scalar" />
            <xsd:element name="numeric-function" type="named_scalar" />
            <xsd:element name="datetime-function" type="named_scalar" />
        </xsd:choice>
    </xsd:complexType>

    <xsd:complexType name="identity_generation_preference">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="platform" type="xsd:string" use="required" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
</xsd:schema>
