Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Configuration.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  *
10  * Class for preparing configuration.
11  */
13 {
14  /**
15  * Build configuration file. Custom user modules support implemented here.
16  * Example:
17  * Module placed in /common/modules/comments its config in /frontend/config/comments.php
18  * Custom copy placed in /common/custom/comments its config in /custom/config/comments.php
19  *
20  * To activate module
21  * in /config/main.php add
22  * 'modules' => array(
23  * 'comments',
24  * )
25  * By default common module will be loaded, To load custom add '_active' => true to its configuration file
26  *
27  * @param string $mainConfigFile configuration file path
28  *
29  * @throws Exception
30  * @return array result configuration file
31  */
32  public static function build($mainConfigFile)
33  {
34  $mainConfigFile = realpath($mainConfigFile);
35  $customConfigFile = realpath(dirname(__FILE__) . '/../../custom/config/client_main.php');
36  //check if configFile not outside app directory
37  if ($mainConfigFile) {
38  $appDir = realpath(dirname(__FILE__) . '/../../');
39  if (strpos($mainConfigFile, $appDir) !== 0) {
40  throw new Exception('Config file error');
41  }
42  }
43  $mainConfig = include $mainConfigFile;
44  $customConfig = include $customConfigFile;
45  foreach ($customConfig['modules'] as $key => $cConfig) {
46  $name = is_integer($key) ? $cConfig : $key;
47  $cConfig = !is_array($cConfig) ? array() : $cConfig;
48  if (isset($mainConfig['modules'][$name])) {
49  $mainConfig['modules'][$name] = CMap::mergeArray($mainConfig['modules'][$name], $cConfig);
50  } else {
51  $mainConfig['modules'][$name] = $cConfig;
52  if (($k = array_search($name, $mainConfig['modules'])) !== false) {
53  unset($mainConfig['modules'][$k]);
54  }
55  }
56  unset($customConfig['modules'][$key]);
57  }
58 
59  foreach ($customConfig['components'] as $key => $cConfig) {
60  $name = is_integer($key) ? $cConfig : $key;
61  $cConfig = !is_array($cConfig) ? array() : $cConfig;
62  if (isset($mainConfig['components'][$name])) {
63  $mainConfig['components'][$name] = CMap::mergeArray($mainConfig['components'][$name], $cConfig);
64  } else {
65  $mainConfig['components'][$name] = $cConfig;
66  if (($k = array_search($name, $mainConfig['components'])) !== false) {
67  unset($mainConfig['components'][$k]);
68  }
69  }
70  unset($customConfig['components'][$key]);
71  }
72  $resultConfig = CMap::mergeArray($mainConfig, $customConfig);
73 
74  return $resultConfig;
75  }
76 }