Skip to content

Commit

Permalink
fixed #38 - Feature request: config should follow symfony/pimcore rul…
Browse files Browse the repository at this point in the history
…es for dev/prod
  • Loading branch information
Christian Fasching committed Sep 2, 2019
1 parent 7c33727 commit e4ec71a
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions src/AdvancedObjectSearchBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
namespace AdvancedObjectSearchBundle;

use AdvancedObjectSearchBundle\Tools\Installer;
use Elasticsearch\Client;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;

class AdvancedObjectSearchBundle extends AbstractPimcoreBundle
{
use PackageVersionTrait;

const CONFIG_PATH = 'advancedobjectsearch';
const CONFIG_FILENAME = 'config.php';

/**
* @var array
*/
Expand All @@ -32,15 +34,53 @@ class AdvancedObjectSearchBundle extends AbstractPimcoreBundle
/**
* @return array
*/
public static function getConfig() {
if(empty(self::$config)) {
$file = PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY . "/advancedobjectsearch/config.php";
if(file_exists($file)) {
$config = include($file);
} else {

/**
* @return array|mixed
* @throws \Exception
*/
public static function getConfig()
{
if (empty(self::$config)) {
$pathsToCheck = [
PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY,
PIMCORE_CONFIGURATION_DIRECTORY,
PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY . '/' . self::CONFIG_PATH,
PIMCORE_CONFIGURATION_DIRECTORY . '/' . self::CONFIG_PATH,
];

$file = null;

// check for environment configuration
$env = \Pimcore\Config::getEnvironment();
if ($env) {
$fileExt = \Pimcore\File::getFileExtension(self::CONFIG_FILENAME);
$pureName = str_replace('.' . $fileExt, '', self::CONFIG_FILENAME);
foreach ($pathsToCheck as $path) {
$tmpFile = $path . '/' .$pureName . '_' . $env . '.' . $fileExt;
if (file_exists($tmpFile)) {
$file = $tmpFile;
break;
}
}
}

//check for config file without environment configuration
if (!$file) {
foreach ($pathsToCheck as $path) {
$tmpFile = $path . '/' . self::CONFIG_FILENAME;
if (file_exists($tmpFile)) {
$file = $tmpFile;
break;
}
}
}

if (!$file) {
throw new \Exception($file . " doesn't exist");
}
self::$config = $config;

self::$config = include $file;
}

return self::$config;
Expand Down

0 comments on commit e4ec71a

Please sign in to comment.