Ejemplo n.º 1
0
 /**
  * Instantiate a Factory object.
  *
  * @since 1.0.0
  *
  * @param ConfigInterface $config  Configuration settings.
  * @param string          $element The type of element to instantiate a factory for.
  *
  * @throws FailedToInstantiateFactory When an unknown element type is requested.
  */
 public function __construct(ConfigInterface $config, $element)
 {
     $this->config = $config;
     if (!$this->config->hasKey($element)) {
         throw new FailedToInstantiateFactory(sprintf('Could not instantiate Factory for unknown Element Type "%1$s".', $element));
     }
     $this->element = $element;
 }
Ejemplo n.º 2
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.º 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);
 }
Ejemplo n.º 6
0
 /**
  * Get an array of all the keys that are known by the Config.
  *
  * @since 0.1.2
  *
  * @return array Array of strings containing all the keys.
  */
 protected function getConfigKeys()
 {
     return $this->config->getKeys();
 }