mergeWith() public method

Merge current config with given config
public mergeWith ( array | ArrayObject | ConfigObject $config )
$config array | Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject | ConfigObject ConfigObject or array of ConfigObject to merge with
Exemplo n.º 1
0
 /**
  * Returns the config of current auth provider.
  *
  * @param string $authProvider Name of the auth provider you wish to use to process the login.
  *                             If you don't set it, the first registered provider will be used.
  *
  * @throws FirewallException
  * @return ConfigObject
  */
 private function getAuthProviderConfig($authProvider)
 {
     // have we already fetched the auth config
     if ($this->authProviderConfig) {
         return $this->authProviderConfig;
     }
     if ($authProvider == '') {
         // get the first auth provider from the list
         $providers = $this->getConfig()->get('AuthenticationProviders', []);
         $authProvider = $providers[0];
     }
     $this->authProviderConfig = Security::getConfig()->get('AuthenticationProviders.' . $authProvider, new ConfigObject());
     // merge the internal driver
     // merge only if driver is not set and it matches the internal auth provider name
     if (!$this->authProviderConfig->get('Driver', false) && isset(self::$authProviders[$authProvider])) {
         $this->authProviderConfig->mergeWith(['Driver' => self::$authProviders[$authProvider]]);
     }
     // make sure the requested auth provider is assigned to the current firewall
     if (!in_array($authProvider, $this->getConfig()->get('AuthenticationProviders', [])->toArray())) {
         throw new FirewallException('Authentication provider "' . $authProvider . '" is not defined on "' . $this->getFirewallKey() . '" firewall.');
     }
     // check that we have the driver
     if (!$this->authProviderConfig->get('Driver', false)) {
         throw new FirewallException('Unable to detect configuration for authentication provider "' . $authProvider . '".');
     }
     $this->authProviderName = $authProvider;
     return $this->authProviderConfig;
 }
Exemplo n.º 2
0
 /**
  * Returns an instance of MessageInterface based on current bridge.
  *
  * @param              $mailer
  *
  * @param ConfigObject $config
  *
  * @return \Webiny\Component\Mailer\MessageInterface
  * @throws MailerException
  * @throws \Webiny\Component\StdLib\Exception\Exception
  */
 public static function getMessage($mailer, ConfigObject $config = null)
 {
     // Do it this way to avoid merging into the original mailer config
     $mailerConfig = Mailer::getConfig()->get($mailer)->toArray();
     $mailerConfig = new ConfigObject($mailerConfig);
     if ($config) {
         $mailerConfig->mergeWith($config);
     }
     $lib = self::getLibrary($mailer);
     /** @var MailerInterface $libInstance */
     $libInstance = self::factory($lib, '\\Webiny\\Component\\Mailer\\Bridge\\MailerInterface');
     $instance = $libInstance::getMessage($mailerConfig);
     if (!self::isInstanceOf($instance, '\\Webiny\\Component\\Mailer\\Bridge\\MessageInterface')) {
         throw new MailerException(MailerException::MESSAGE_INTERFACE);
     }
     return $instance;
 }
Exemplo n.º 3
0
 /**
  * Loads all the configurations from a specific environment.
  *
  * @param string $environment Environment name.
  *
  * @return ConfigObject
  * @throws \Webiny\Component\Config\ConfigException
  */
 private function loadConfigurations($environment)
 {
     $configs = new ConfigObject([]);
     $configFolder = $this->applicationAbsolutePath . 'App/Config/' . $environment;
     $h = scandir($configFolder);
     foreach ($h as $configFile) {
         if (strpos($configFile, 'yaml') === false) {
             continue;
         }
         $configs->mergeWith($this->config()->yaml($configFolder . DIRECTORY_SEPARATOR . $configFile));
     }
     return $configs;
 }