PageRenderTime 24ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/doctrine/doctrine-bundle/Doctrine/Bundle/DoctrineBundle/Resources/doc/configuration.rst

https://github.com/nattaphat/hgis
ReStructuredText | 337 lines | 288 code | 49 blank | 0 comment | 0 complexity | da2670a28edfefbe0f7370f34af7546e MD5 | raw file
  1. .. index::
  2. single: Doctrine; ORM Configuration Reference
  3. single: Configuration Reference; Doctrine ORM
  4. Configuration Reference
  5. =======================
  6. .. configuration-block::
  7. .. code-block:: yaml
  8. doctrine:
  9. dbal:
  10. default_connection: default
  11. connections:
  12. default:
  13. dbname: database
  14. host: localhost
  15. port: 1234
  16. user: user
  17. password: secret
  18. driver: pdo_mysql
  19. driver_class: MyNamespace\MyDriverImpl
  20. options:
  21. foo: bar
  22. path: %kernel.data_dir%/data.sqlite
  23. memory: true
  24. unix_socket: /tmp/mysql.sock
  25. wrapper_class: MyDoctrineDbalConnectionWrapper
  26. keep_slave: true
  27. charset: UTF8
  28. logging: %kernel.debug%
  29. platform_service: MyOwnDatabasePlatformService
  30. schema_filter: ^sf2_
  31. mapping_types:
  32. enum: string
  33. conn1:
  34. # ...
  35. types:
  36. custom: Acme\HelloBundle\MyCustomType
  37. orm:
  38. auto_generate_proxy_classes: false
  39. proxy_namespace: Proxies
  40. proxy_dir: %kernel.cache_dir%/doctrine/orm/Proxies
  41. default_entity_manager: default # The first defined is used if not set
  42. entity_managers:
  43. default:
  44. # The name of a DBAL connection (the one marked as default is used if not set)
  45. connection: conn1
  46. mappings: # Required
  47. AcmeHelloBundle: ~
  48. class_metadata_factory_name: Doctrine\ORM\Mapping\ClassMetadataFactory
  49. # All cache drivers have to be array, apc, xcache or memcache
  50. metadata_cache_driver: array
  51. query_cache_driver: array
  52. result_cache_driver:
  53. type: memcache
  54. host: localhost
  55. port: 11211
  56. instance_class: Memcache
  57. class: Doctrine\Common\Cache\MemcacheCache
  58. dql:
  59. string_functions:
  60. test_string: Acme\HelloBundle\DQL\StringFunction
  61. numeric_functions:
  62. test_numeric: Acme\HelloBundle\DQL\NumericFunction
  63. datetime_functions:
  64. test_datetime: Acme\HelloBundle\DQL\DatetimeFunction
  65. naming_strategy: doctrine.orm.naming_strategy.default # Service Reference
  66. em2:
  67. # ...
  68. .. code-block:: xml
  69. <container xmlns="http://symfony.com/schema/dic/services"
  70. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  71. xmlns:doctrine="http://symfony.com/schema/dic/doctrine"
  72. xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
  73. http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd">
  74. <doctrine:config>
  75. <doctrine:dbal default-connection="default">
  76. <doctrine:connection
  77. name="default"
  78. dbname="database"
  79. host="localhost"
  80. port="1234"
  81. user="user"
  82. password="secret"
  83. driver="pdo_mysql"
  84. driver-class="MyNamespace\MyDriverImpl"
  85. path="%kernel.data_dir%/data.sqlite"
  86. memory="true"
  87. unix-socket="/tmp/mysql.sock"
  88. wrapper-class="MyDoctrineDbalConnectionWrapper"
  89. keep-slave="true"
  90. charset="UTF8"
  91. logging="%kernel.debug%"
  92. platform-service="MyOwnDatabasePlatformService"
  93. schema-filter="^sf2_"
  94. >
  95. <doctrine:option key="foo">bar</doctrine:option>
  96. <doctrine:mapping-type name="enum">string</doctrine:mapping-type>
  97. </doctrine:connection>
  98. <doctrine:connection name="conn1" />
  99. <doctrine:type name="custom">Acme\HelloBundle\MyCustomType</doctrine:type>
  100. </doctrine:dbal>
  101. <doctrine:orm default-entity-manager="default" auto-generate-proxy-classes="false" proxy-namespace="Proxies" proxy-dir="%kernel.cache_dir%/doctrine/orm/Proxies">
  102. <doctrine:entity-manager name="default" query-cache-driver="array" result-cache-driver="array" connection="conn1" class-metadata-factory-name="Doctrine\ORM\Mapping\ClassMetadataFactory" naming-strategy="doctrine.orm.naming_strategy.default">
  103. <doctrine:metadata-cache-driver type="memcache" host="localhost" port="11211" instance-class="Memcache" class="Doctrine\Common\Cache\MemcacheCache" />
  104. <doctrine:mapping name="AcmeHelloBundle" />
  105. <doctrine:dql>
  106. <doctrine:string-function name="test_string>Acme\HelloBundle\DQL\StringFunction</doctrine:string-function>
  107. <doctrine:numeric-function name="test_numeric>Acme\HelloBundle\DQL\NumericFunction</doctrine:numeric-function>
  108. <doctrine:datetime-function name="test_datetime>Acme\HelloBundle\DQL\DatetimeFunction</doctrine:datetime-function>
  109. </doctrine:dql>
  110. </doctrine:entity-manager>
  111. <doctrine:entity-manager name="em2" connection="conn2" metadata-cache-driver="apc">
  112. <doctrine:mapping
  113. name="DoctrineExtensions"
  114. type="xml"
  115. dir="%kernel.root_dir%/../src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Entity"
  116. prefix="DoctrineExtensions\Entity"
  117. alias="DExt"
  118. />
  119. </doctrine:entity-manager>
  120. </doctrine:orm>
  121. </doctrine:config>
  122. </container>
  123. Configuration Overview
  124. ----------------------
  125. This following configuration example shows all the configuration defaults that
  126. the ORM resolves to:
  127. .. code-block:: yaml
  128. doctrine:
  129. orm:
  130. auto_mapping: true
  131. # the standard distribution overrides this to be true in debug, false otherwise
  132. auto_generate_proxy_classes: false
  133. proxy_namespace: Proxies
  134. proxy_dir: %kernel.cache_dir%/doctrine/orm/Proxies
  135. default_entity_manager: default
  136. metadata_cache_driver: array
  137. query_cache_driver: array
  138. result_cache_driver: array
  139. There are lots of other configuration options that you can use to overwrite
  140. certain classes, but those are for very advanced use-cases only.
  141. Caching Drivers
  142. ~~~~~~~~~~~~~~~
  143. For the caching drivers you can specify the values "array", "apc", "memcache", "memcached"
  144. or "xcache".
  145. The following example shows an overview of the caching configurations:
  146. .. code-block:: yaml
  147. doctrine:
  148. orm:
  149. auto_mapping: true
  150. metadata_cache_driver: apc
  151. query_cache_driver: xcache
  152. result_cache_driver:
  153. type: memcache
  154. host: localhost
  155. port: 11211
  156. instance_class: Memcache
  157. Mapping Configuration
  158. ~~~~~~~~~~~~~~~~~~~~~
  159. Explicit definition of all the mapped entities is the only necessary
  160. configuration for the ORM and there are several configuration options that you
  161. can control. The following configuration options exist for a mapping:
  162. * ``type`` One of ``annotation``, ``xml``, ``yml``, ``php`` or ``staticphp``.
  163. This specifies which type of metadata type your mapping uses.
  164. * ``dir`` Path to the mapping or entity files (depending on the driver). If
  165. this path is relative it is assumed to be relative to the bundle root. This
  166. only works if the name of your mapping is a bundle name. If you want to use
  167. this option to specify absolute paths you should prefix the path with the
  168. kernel parameters that exist in the DIC (for example %kernel.root_dir%).
  169. * ``prefix`` A common namespace prefix that all entities of this mapping
  170. share. This prefix should never conflict with prefixes of other defined
  171. mappings otherwise some of your entities cannot be found by Doctrine. This
  172. option defaults to the bundle namespace + ``Entity``, for example for an
  173. application bundle called ``AcmeHelloBundle`` prefix would be
  174. ``Acme\HelloBundle\Entity``.
  175. * ``alias`` Doctrine offers a way to alias entity namespaces to simpler,
  176. shorter names to be used in DQL queries or for Repository access. When using
  177. a bundle the alias defaults to the bundle name.
  178. * ``is_bundle`` This option is a derived value from ``dir`` and by default is
  179. set to true if dir is relative proved by a ``file_exists()`` check that
  180. returns false. It is false if the existence check returns true. In this case
  181. an absolute path was specified and the metadata files are most likely in a
  182. directory outside of a bundle.
  183. .. index::
  184. single: Configuration; Doctrine DBAL
  185. single: Doctrine; DBAL configuration
  186. Filters Configuration
  187. ~~~~~~~~~~~~~~~~~~~~~
  188. You can easily define `doctrine filters`_ in your configuration file:
  189. .. code-block:: yaml
  190. doctrine:
  191. orm:
  192. filters:
  193. myFilter:
  194. class: MyVendor\MyBundle\Filters\MyFilter
  195. enabled: true
  196. parameters:
  197. myParameter: myValue
  198. mySecondParameter: mySecondValue
  199. * ``myFilter:`` Filter identifier (Required)
  200. * ``class:`` Filter target class (Required)
  201. * ``enabled:`` Enable/Disable the filter by default (Optional - Default disabled)
  202. * ``parameters:`` Set default parameters (Optional)
  203. * ``myParameter: myValue`` Bind the value ``myValue`` to the parameter ``myParameter`` (Optional)
  204. .. _doctrine filters: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/filters.html
  205. .. _`reference-dbal-configuration`:
  206. Doctrine DBAL Configuration
  207. ---------------------------
  208. .. note::
  209. DoctrineBundle supports all parameters that default Doctrine drivers
  210. accept, converted to the XML or YAML naming standards that Symfony
  211. enforces. See the Doctrine `DBAL documentation`_ for more information.
  212. Besides default Doctrine options, there are some Symfony-related ones that you
  213. can configure. The following block shows all possible configuration keys:
  214. .. configuration-block::
  215. .. code-block:: yaml
  216. doctrine:
  217. dbal:
  218. dbname: database
  219. host: localhost
  220. port: 1234
  221. user: user
  222. password: secret
  223. driver: pdo_mysql
  224. driver_class: MyNamespace\MyDriverImpl
  225. options:
  226. foo: bar
  227. path: %kernel.data_dir%/data.sqlite
  228. memory: true
  229. unix_socket: /tmp/mysql.sock
  230. wrapper_class: MyDoctrineDbalConnectionWrapper
  231. charset: UTF8
  232. logging: %kernel.debug%
  233. platform_service: MyOwnDatabasePlatformService
  234. schema_filter: ^sf2_
  235. mapping_types:
  236. enum: string
  237. types:
  238. custom: Acme\HelloBundle\MyCustomType
  239. .. code-block:: xml
  240. <!-- xmlns:doctrine="http://symfony.com/schema/dic/doctrine" -->
  241. <!-- xsi:schemaLocation="http://symfony.com/schema/dic/doctrine http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd"> -->
  242. <doctrine:config>
  243. <doctrine:dbal
  244. name="default"
  245. dbname="database"
  246. host="localhost"
  247. port="1234"
  248. user="user"
  249. password="secret"
  250. driver="pdo_mysql"
  251. driver-class="MyNamespace\MyDriverImpl"
  252. path="%kernel.data_dir%/data.sqlite"
  253. memory="true"
  254. unix-socket="/tmp/mysql.sock"
  255. wrapper-class="MyDoctrineDbalConnectionWrapper"
  256. charset="UTF8"
  257. logging="%kernel.debug%"
  258. platform-service="MyOwnDatabasePlatformService"
  259. schema-filter="^sf2_"
  260. >
  261. <doctrine:option key="foo">bar</doctrine:option>
  262. <doctrine:mapping-type name="enum">string</doctrine:mapping-type>
  263. <doctrine:type name="custom">Acme\HelloBundle\MyCustomType</doctrine:type>
  264. </doctrine:dbal>
  265. </doctrine:config>
  266. If you want to configure multiple connections in YAML, put them under the
  267. ``connections`` key and give them a unique name:
  268. .. code-block:: yaml
  269. doctrine:
  270. dbal:
  271. default_connection: default
  272. connections:
  273. default:
  274. dbname: Symfony2
  275. user: root
  276. password: null
  277. host: localhost
  278. customer:
  279. dbname: customer
  280. user: root
  281. password: null
  282. host: localhost
  283. The ``database_connection`` service always refers to the *default* connection,
  284. which is the first one defined or the one configured via the
  285. ``default_connection`` parameter.
  286. Each connection is also accessible via the ``doctrine.dbal.[name]_connection``
  287. service where ``[name]`` if the name of the connection.
  288. .. _DBAL documentation: http://www.doctrine-project.org/docs/dbal/2.0/en