SettingsFactory.php in Lockr 4.x
File
src/SettingsFactory.php
View source
<?php
namespace Drupal\lockr;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Site\Settings;
use Lockr\LockrSettings;
class SettingsFactory {
protected $configFactory;
protected $fileSystem;
protected $settings;
public function __construct(ConfigFactoryInterface $config_factory, FileSystemInterface $file_system, Settings $settings) {
$this->configFactory = $config_factory;
$this->fileSystem = $file_system;
$this->settings = $settings;
}
public function getSettings() {
$config = $this->configFactory
->get('lockr.settings');
if ($config
->get('custom')) {
$cert_path = $this->fileSystem
->realpath($config
->get('cert_path'));
}
else {
$partner = $this
->getPartner();
$cert_path = isset($partner['cert']) ? $partner['cert'] : NULL;
}
switch ($config
->get('region')) {
case 'us':
$host = 'us.api.lockr.io';
break;
case 'eu':
$host = 'eu.api.lockr.io';
break;
default:
$host = 'api.lockr.io';
break;
}
$client_config = $this->settings
->get('lockr_http_client_config');
if (is_array($client_config)) {
$opts = $client_config;
}
else {
$opts = [];
}
return new LockrSettings($cert_path, $host, null, $opts);
}
public function getPartner() {
if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
$cert_path = '/certs/binding.pem';
if (!is_file($cert_path) && defined('PANTHEON_BINDING')) {
$cert_path = '/srv/bindings/' . PANTHEON_BINDING . '/certs/binding.pem';
}
return [
'name' => 'pantheon',
'title' => 'Pantheon',
'description' => "The Pantheor is strong with this one.\n We're detecting you're on Pantheon and a friend of theirs is a friend of ours.\n Welcome to Lockr.",
'cert' => $cert_path,
];
}
return NULL;
}
}