Ejemplo n.º 1
0
 /**
  * Create a new mail object.
  *
  * @since 1.0.0
  *
  * @param string          $format   Optional. Format to use.
  * @param string|Template $template Optional. Template to be used.
  *
  * @return Mail
  */
 public function createMail($format = 'html', $template = 'BasicTemplate')
 {
     $mail_factory = new Factory($this->config, 'mails');
     $mail_class = $this->config->getKey('formats')[$format]['mail'];
     $mail = $mail_factory->create($mail_class);
     $mail->setTemplate($template);
     return $mail;
 }
Ejemplo n.º 2
0
 /**
  * Get the callable Config value for a specific key.
  *
  * If the fetched value is indeed a callable, it will be executed with the provided arguments, and the resultant
  * value will be returned instead.
  *
  * @since 0.4.8
  *
  * @param string|array $key  Key or array of nested keys.
  * @param array        $args Optional. Array of arguments to pass to the callable.
  *
  * @return mixed Resultant value of the key's callable.
  */
 protected function getConfigCallable($key, array $args = [])
 {
     $value = $this->config->getKey($key);
     if (is_callable($value)) {
         $value = $value(...$args);
     }
     return $value;
 }
Ejemplo n.º 3
0
 /**
  * Register the NullObject defined in the given configuration.
  *
  * @since 0.1.0
  *
  * @param ConfigInterface $config Configuration to register the NullObject from.
  */
 public function registerNullObject(ConfigInterface $config)
 {
     $this->nullObject = $config->getKey($this->getNullObjectConfigKey());
 }
Ejemplo n.º 4
0
 /**
  * Register mapping definitions.
  *
  * Takes a ConfigInterface and reads the following keys to add definitions:
  * - 'sharedAliases'
  * - 'standardAliases'
  * - 'argumentDefinitions'
  * - 'argumentProviders'
  * - 'delegations'
  * - 'preparations'
  *
  * @since 0.1.0
  *
  * @param ConfigInterface $config Config file to parse.
  *
  * @throws InvalidMappingsException If a needed key could not be read from the config file.
  * @throws InvalidMappingsException If the dependency injector could not be set up.
  */
 public function registerMappings(ConfigInterface $config)
 {
     $configKeys = [static::K_STANDARD_ALIASES => 'mapAliases', static::K_SHARED_ALIASES => 'shareAliases', static::K_ARGUMENT_DEFINITIONS => 'defineArguments', static::K_ARGUMENT_PROVIDERS => 'defineArgumentProviders', static::K_DELEGATIONS => 'defineDelegations', static::K_PREPARATIONS => 'definePreparations'];
     try {
         foreach ($configKeys as $key => $method) {
             ${$key} = $config->hasKey($key) ? $config->getKey($key) : [];
         }
         $standardAliases = array_merge($sharedAliases, $standardAliases);
     } catch (Exception $exception) {
         throw new InvalidMappingsException(sprintf(_('Failed to read needed keys from config. Reason: "%1$s".'), $exception->getMessage()));
     }
     try {
         foreach ($configKeys as $key => $method) {
             array_walk(${$key}, [$this, $method]);
         }
     } catch (Exception $exception) {
         throw new InvalidMappingsException(sprintf(_('Failed to set up dependency injector. Reason: "%1$s".'), $exception->getMessage()));
     }
 }
Ejemplo n.º 5
0
 /**
  * Set the template to the default template defined in the configuration.
  *
  * @since 1.0.0
  *
  * @throws RuntimeException
  */
 protected function setDefaultTemplate()
 {
     $defaultTemplate = $this->config->getKey('default_template');
     $this->setTemplate($defaultTemplate);
 }