PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/app/config/config.php

https://gitlab.com/e0/mautic
PHP | 358 lines | 288 code | 33 blank | 37 comment | 14 complexity | 1f64291b9146fb09fc0aba532517be0b MD5 | raw file
  1. <?php
  2. include __DIR__ . '/paths_helper.php';
  3. $ormMappings =
  4. $serializerMappings =
  5. $ipLookupServices = array();
  6. //Note Mautic specific bundles so they can be applied as needed without having to specify them individually
  7. $buildBundles = function($namespace, $bundle) use ($container, $paths, $root, &$ormMappings, &$serializerMappings, &$ipLookupServices) {
  8. $isPlugin = $isMautic = false;
  9. if (strpos($namespace, 'MauticPlugin\\') !== false) {
  10. $isPlugin = true;
  11. $bundleBase = $bundle;
  12. $relative = $paths['plugins'].'/'.$bundleBase;
  13. } elseif (strpos($namespace, 'MauticAddon\\') !== false) {
  14. // @deprecated 1.1.4; to be removed in 2.0; BC support for MauticAddon
  15. $isPlugin = true;
  16. $bundleBase = $bundle;
  17. $relative = 'addons/'.$bundleBase;
  18. } elseif (strpos($namespace, 'Mautic\\') !== false) {
  19. $isMautic = true;
  20. $bundleBase = str_replace('Mautic', '', $bundle);
  21. $relative = $paths['bundles'] . '/' . $bundleBase;
  22. }
  23. if ($isMautic || $isPlugin) {
  24. $baseNamespace = preg_replace('#\\\[^\\\]*$#', '', $namespace);
  25. $directory = $paths['root'].'/'.$relative;
  26. // Check for a single config file
  27. $config = (file_exists($directory.'/Config/config.php')) ? include $directory.'/Config/config.php' : array();
  28. // Register IP lookup services
  29. if (isset($config['ip_lookup_services'])) {
  30. $ipLookupServices = array_merge($ipLookupServices, $config['ip_lookup_services']);
  31. }
  32. // Check for staticphp mapping
  33. if (file_exists($directory.'/Entity')) {
  34. $finder = \Symfony\Component\Finder\Finder::create()->files('*.php')->in($directory.'/Entity')->notName('*Repository.php');
  35. foreach ($finder as $file) {
  36. // @deprecated 1.1.4; to be removed in 2.0; BC support for Addon
  37. if (strpos($baseNamespace, 'PluginBundle') !== false && $file->getFilename() == 'Addon.php') {
  38. // Do not include this class as it's used for BC support
  39. continue;
  40. }
  41. // Check to see if entities are organized by subfolder
  42. $subFolder = $file->getRelativePath();
  43. // Just check first file for the loadMetadata function
  44. $reflectionClass = new \ReflectionClass('\\' . $baseNamespace . '\\Entity\\' . (!empty($subFolder) ? $subFolder . '\\': '') . basename($file->getFilename(), '.php'));
  45. // Register API metadata
  46. if ($reflectionClass->hasMethod('loadApiMetadata')) {
  47. $serializerMappings[$bundle] = array(
  48. 'namespace_prefix' => $baseNamespace . '\\Entity',
  49. 'path' => "@$bundle/Entity"
  50. );
  51. }
  52. // Register entities
  53. if ($reflectionClass->hasMethod('loadMetadata')) {
  54. $ormMappings[$bundle] = array(
  55. 'dir' => 'Entity',
  56. 'type' => 'staticphp',
  57. 'prefix' => $baseNamespace . '\\Entity',
  58. 'mapping' => true,
  59. 'is_bundle' => true
  60. );
  61. }
  62. }
  63. }
  64. return array(
  65. 'isPlugin' => $isPlugin,
  66. 'base' => str_replace('Bundle', '', $bundleBase),
  67. 'bundle' => $bundleBase,
  68. 'namespace' => $baseNamespace,
  69. 'symfonyBundleName' => $bundle,
  70. 'bundleClass' => $namespace,
  71. 'relative' => $relative,
  72. 'directory' => $directory,
  73. 'config' => $config
  74. );
  75. }
  76. return false;
  77. };
  78. // Seperate out Mautic's bundles from other Symfony bundles
  79. $symfonyBundles = $container->getParameter('kernel.bundles');
  80. $mauticBundles = array_filter(
  81. array_map($buildBundles, $symfonyBundles, array_keys($symfonyBundles)),
  82. function ($v) { return (!empty($v)); }
  83. );
  84. unset($buildBundles);
  85. // Sort Mautic's bundles into Core and Plugins
  86. $setBundles = $setPluginBundles = array();
  87. foreach ($mauticBundles as $bundle) {
  88. if ($bundle['isPlugin']) {
  89. $setPluginBundles[$bundle['symfonyBundleName']] = $bundle;
  90. } else {
  91. $setBundles[$bundle['symfonyBundleName']] = $bundle;
  92. }
  93. }
  94. // Make Core the first in the list
  95. $coreBundle = $setBundles['MauticCoreBundle'];
  96. unset($setBundles['MauticCoreBundle']);
  97. $setBundles = array_merge(array('MauticCoreBundle' => $coreBundle), $setBundles);
  98. $container->setParameter('mautic.bundles', $setBundles);
  99. $container->setParameter('mautic.plugin.bundles', $setPluginBundles);
  100. unset($setBundles, $setPluginBundles);
  101. // Set IP lookup services
  102. $container->setParameter('mautic.ip_lookup_services', $ipLookupServices);
  103. // Load parameters
  104. $loader->import('parameters.php');
  105. $container->loadFromExtension('mautic_core');
  106. // Set template engines
  107. $engines = array('php', 'twig');
  108. // Generate session name
  109. if (isset($_COOKIE['mautic_session_name'])) {
  110. // Attempt to keep from losing sessions if cache is cleared through UI
  111. $sessionName = $_COOKIE['mautic_session_name'];
  112. } else {
  113. $key = $container->hasParameter('mautic.secret_key') ? $container->getParameter('mautic.secret_key') : uniqid();
  114. $sessionName = md5(md5($paths['local_config']).$key);
  115. }
  116. $container->loadFromExtension('framework', array(
  117. 'secret' => '%mautic.secret_key%',
  118. 'router' => array(
  119. 'resource' => '%kernel.root_dir%/config/routing.php',
  120. 'strict_requirements' => null,
  121. ),
  122. 'form' => null,
  123. 'csrf_protection' => true,
  124. 'validation' => array(
  125. 'enable_annotations' => false
  126. ),
  127. 'templating' => array(
  128. 'engines' => $engines,
  129. 'form' => array(
  130. 'resources' => array(
  131. 'MauticCoreBundle:FormTheme\\Custom',
  132. ),
  133. ),
  134. ),
  135. 'default_locale' => '%mautic.locale%',
  136. 'translator' => array(
  137. 'enabled' => true,
  138. 'fallback' => 'en_US'
  139. ),
  140. 'trusted_hosts' => '%mautic.trusted_hosts%',
  141. 'trusted_proxies' => '%mautic.trusted_proxies%',
  142. 'session' => array( //handler_id set to null will use default session handler from php.ini
  143. 'handler_id' => null,
  144. 'name' => $sessionName,
  145. ),
  146. 'fragments' => null,
  147. 'http_method_override' => true,
  148. /*'validation' => array(
  149. 'static_method' => array('loadValidatorMetadata')
  150. )*/
  151. ));
  152. //Doctrine Configuration
  153. $dbalSettings = array(
  154. 'driver' => '%mautic.db_driver%',
  155. 'host' => '%mautic.db_host%',
  156. 'port' => '%mautic.db_port%',
  157. 'dbname' => '%mautic.db_name%',
  158. 'user' => '%mautic.db_user%',
  159. 'password' => '%mautic.db_password%',
  160. 'charset' => 'UTF8',
  161. 'types' => array(
  162. 'array' => 'Mautic\CoreBundle\Doctrine\Type\ArrayType',
  163. 'datetime' => 'Mautic\CoreBundle\Doctrine\Type\UTCDateTimeType'
  164. ),
  165. // Prevent Doctrine from crapping out with "unsupported type" errors due to it examining all tables in the database and not just Mautic's
  166. 'mapping_types' => array(
  167. 'enum' => 'string',
  168. 'point' => 'string',
  169. 'bit' => 'string',
  170. )
  171. );
  172. // If using pdo_sqlite as the database driver, add the path to config file
  173. $dbDriver = $container->getParameter('mautic.db_driver');
  174. if ($dbDriver == 'pdo_sqlite') {
  175. $dbalSettings['path'] = '%mautic.db_path%';
  176. }
  177. $container->loadFromExtension('doctrine', array(
  178. 'dbal' => $dbalSettings,
  179. 'orm' => array(
  180. 'auto_generate_proxy_classes' => '%kernel.debug%',
  181. 'auto_mapping' => true,
  182. 'mappings' => $ormMappings
  183. )
  184. ));
  185. //MigrationsBundle Configuration
  186. $prefix = $container->getParameter('mautic.db_table_prefix');
  187. $container->loadFromExtension('doctrine_migrations', array(
  188. 'dir_name' => '%kernel.root_dir%/migrations',
  189. 'namespace' => 'Mautic\\Migrations',
  190. 'table_name' => $prefix . 'migrations',
  191. 'name' => 'Mautic Migrations'
  192. ));
  193. // Swiftmailer Configuration
  194. $mailerSettings = array(
  195. 'transport' => '%mautic.mailer_transport%',
  196. 'host' => '%mautic.mailer_host%',
  197. 'port' => '%mautic.mailer_port%',
  198. 'username' => '%mautic.mailer_user%',
  199. 'password' => '%mautic.mailer_password%',
  200. 'encryption' => '%mautic.mailer_encryption%',
  201. 'auth_mode' => '%mautic.mailer_auth_mode%'
  202. );
  203. // Only spool if using file as otherwise emails are not sent on redirects
  204. $spoolType = $container->getParameter('mautic.mailer_spool_type');
  205. if ($spoolType == 'file') {
  206. $mailerSettings['spool'] = array(
  207. 'type' => '%mautic.mailer_spool_type%',
  208. 'path' => '%mautic.mailer_spool_path%'
  209. );
  210. }
  211. $container->loadFromExtension('swiftmailer', $mailerSettings);
  212. //KnpMenu Configuration
  213. $container->loadFromExtension('knp_menu', array(
  214. 'twig' => false,
  215. 'templating' => true,
  216. 'default_renderer' => 'mautic'
  217. ));
  218. // OneupUploader Configuration
  219. $uploadDir = $container->getParameter('mautic.upload_dir');
  220. $maxSize = $container->getParameter('mautic.max_size');
  221. $container->loadFromExtension('oneup_uploader', array(
  222. // 'orphanage' => array(
  223. // 'maxage' => 86400,
  224. // 'directory' => $uploadDir . '/orphanage'
  225. // ),
  226. 'mappings' => array(
  227. 'asset' => array(
  228. 'error_handler' => 'mautic.asset.upload.error.handler',
  229. 'frontend' => 'custom',
  230. 'custom_frontend' => array(
  231. 'class' => 'Mautic\AssetBundle\Controller\UploadController',
  232. 'name' => 'mautic'
  233. ),
  234. // 'max_size' => ($maxSize * 1000000),
  235. // 'use_orphanage' => true,
  236. 'storage' => array(
  237. 'directory' => $uploadDir
  238. )
  239. )
  240. )
  241. ));
  242. //FOS Rest for API
  243. $container->loadFromExtension('fos_rest', array(
  244. 'routing_loader' => array(
  245. 'default_format' => 'json',
  246. 'include_format' => false
  247. ),
  248. 'view' => array(
  249. 'formats' => array(
  250. 'json' => true,
  251. 'xml' => false,
  252. 'html' => false
  253. ),
  254. 'templating_formats' => array(
  255. 'html' => false
  256. )
  257. ),
  258. 'disable_csrf_role' => 'ROLE_API'
  259. ));
  260. //JMS Serializer for API and Webhooks
  261. $container->loadFromExtension('jms_serializer', array(
  262. 'handlers' => array(
  263. 'datetime' => array(
  264. 'default_format' => 'c',
  265. 'default_timezone' => 'UTC'
  266. )
  267. ),
  268. 'property_naming' => array(
  269. 'separator' => '',
  270. 'lower_case' => false
  271. ),
  272. 'metadata' => array(
  273. 'cache' => 'none',
  274. 'auto_detection' => false,
  275. 'directories' => $serializerMappings
  276. )
  277. ));
  278. $container->setParameter(
  279. 'jms_serializer.camel_case_naming_strategy.class',
  280. 'JMS\Serializer\Naming\IdenticalPropertyNamingStrategy'
  281. );
  282. // Monolog formatter
  283. $container->register('mautic.monolog.fulltrace.formatter', 'Monolog\Formatter\LineFormatter')
  284. ->addMethodCall('includeStacktraces', array(true));
  285. //Register command line logging
  286. use Symfony\Component\DependencyInjection\Definition;
  287. use Symfony\Component\DependencyInjection\Reference;
  288. $container->setParameter(
  289. 'console_exception_listener.class',
  290. 'Mautic\CoreBundle\EventListener\ConsoleExceptionListener'
  291. );
  292. $definitionConsoleExceptionListener = new Definition(
  293. '%console_exception_listener.class%',
  294. array(new Reference('monolog.logger.mautic'))
  295. );
  296. $definitionConsoleExceptionListener->addTag(
  297. 'kernel.event_listener',
  298. array('event' => 'console.exception')
  299. );
  300. $container->setDefinition(
  301. 'mautic.kernel.listener.command_exception',
  302. $definitionConsoleExceptionListener
  303. );
  304. $container->setParameter(
  305. 'console_terminate_listener.class',
  306. 'Mautic\CoreBundle\EventListener\ConsoleTerminateListener'
  307. );
  308. $definitionConsoleExceptionListener = new Definition(
  309. '%console_terminate_listener.class%',
  310. array(new Reference('monolog.logger.mautic'))
  311. );
  312. $definitionConsoleExceptionListener->addTag(
  313. 'kernel.event_listener',
  314. array('event' => 'console.terminate')
  315. );
  316. $container->setDefinition(
  317. 'mautic.kernel.listener.command_terminate',
  318. $definitionConsoleExceptionListener
  319. );