Inheritance: implements ArrayAccess, implements IteratorAggregate, use trait Webiny\Component\StdLib\StdObjectTrait, use trait Webiny\Component\StdLib\ValidatorTrait
示例#1
0
 /**
  * Base constructor.
  * In the base constructor the bridge gets the mailer configuration.
  *
  * @param ConfigObject $config The base configuration.
  *
  * @throws MandrillException
  */
 public function __construct($config)
 {
     $this->config = $config;
     $this->disableDelivery = $config->get('DisableDelivery', false);
     $apiKey = $config->get('ApiKey', false);
     if (!$apiKey) {
         throw new MandrillException('`ApiKey` was not found in the mailer configuration!');
     }
     $this->mailer = new \Mandrill($apiKey);
 }
示例#2
0
 /**
  * Returns an instance of MessageInterface.
  *
  * @param ConfigObject $config The configuration of current mailer
  *
  * @return MessageInterface
  */
 public static function getMessage(ConfigObject $config)
 {
     $message = new Message($config);
     if ($config->get('Sender', false)) {
         $sender = new Email($config->get('Sender.Email', 'me@localhost'), $config->get('Sender.Name', null));
         $message->setSender($sender);
         // Fix/Hack (wasn't in headers before)
         $message->setFrom($sender);
     }
     return $message;
 }
示例#3
0
 public function __construct(ConfigObject $config = null)
 {
     $this->message = new \Swift_Message();
     if ($config) {
         $this->message->setCharset($config->get('CharacterSet', 'utf-8'));
         $this->message->setMaxLineLength($config->get('MaxLineLength', 78));
         if ($config->get('Priority', false)) {
             $this->message->setPriority($config->get('Priority', 3));
         }
     }
 }
示例#4
0
 /**
  * @param ConfigObject $config Config options.
  *
  * @throws \Webiny\Component\Http\Session\SessionException
  */
 public function __construct(ConfigObject $config)
 {
     $this->prefix = $config->get('Storage.Prefix', '');
     $this->ttl = $config->get('Storage.ExpireTime', 86400);
     $this->cache = $config->get('Storage.Params.Cache', false);
     try {
         $this->cacheDriver = $this->cache($this->cache);
     } catch (CacheException $e) {
         throw new SessionException('Unable to get cache driver "' . $this->cache . '" for session storage.');
     }
 }
示例#5
0
 public function __construct(ConfigObject $config = null)
 {
     if ($config) {
         // Overwrite default message params with those in config
         foreach ($this->message as $param => $value) {
             $cParam = $this->str($param)->replace('_', ' ')->caseWordUpper()->replace(' ', '')->val();
             $cValue = $config->get('Message.' . $cParam);
             if ($cValue !== null) {
                 if ($cValue instanceof ConfigObject) {
                     $cValue = $cValue->toArray();
                 }
                 $this->message[$param] = $cValue;
             }
         }
     }
 }
示例#6
0
 /**
  * Sets the decision strategy based on the application configuration.
  *
  * @throws AccessControlException
  */
 private function setDecisionStrategy()
 {
     $strategy = $this->config->get('DecisionStrategy', 'unanimous');
     if ($strategy != self::VOTER_STR_AFFIRMATIVE && $strategy != self::VOTER_STR_CONSENSUS && $strategy != self::VOTER_STR_UNANIMOUS) {
         throw new AccessControlException('Invalid access control decision strategy "' . $strategy . '"');
     }
     $this->strategy = $strategy;
 }
示例#7
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;
 }
示例#8
0
 /**
  * Base constructor.
  *
  * @param ConfigObject $config Configuration for the template engine.
  *
  * @throws SmartyException
  */
 public function __construct(ConfigObject $config)
 {
     $this->smarty = new \Smarty();
     // compile dir
     $compileDir = $config->get('CompileDir', false);
     if (!$compileDir) {
         throw new SmartyException('Configuration error, "CompileDir" is missing.');
     }
     $this->setCompileDir($compileDir);
     // cache dir
     $cacheDir = $config->get('CacheDir', false);
     if (!$cacheDir) {
         throw new SmartyException('Configuration error, "CacheDir" is missing.');
     }
     $this->setCacheDir($cacheDir);
     // template dir
     $templateDir = $config->get('TemplateDir', false);
     if ($templateDir) {
         $this->setTemplateDir($templateDir);
     }
     // force compile
     $this->setForceCompile($config->get('ForceCompile', false));
     // merge compiled includes
     if (!$config->get('MergeCompiledIncludes', true)) {
         $this->setMergeCompiledIncludes(false);
     }
     // mute expected errors
     if ($config->get('MuteExpectedErrors', false)) {
         $this->smarty->muteExpectedErrors();
     } else {
         $this->smarty->unmuteExpectedErrors();
     }
     // register extensions
     $this->registerExtensions();
 }
示例#9
0
 /**
  * Create cache key for storing ConfigObject
  *
  * @param $resource
  *
  * @return mixed
  */
 public static function createCacheKey($resource)
 {
     $resourceType = ConfigObject::determineResourceType($resource);
     switch ($resourceType) {
         case ConfigObject::ARRAY_RESOURCE:
             return self::str(json_encode($resource))->md5()->val();
         case ConfigObject::STRING_RESOURCE:
         default:
             return self::str($resource)->md5()->val();
     }
 }
示例#10
0
 /**
  * Builds a Route instance based on the given route config.
  *
  * @param ConfigObject $routeConfig A config object containing route parameters.
  *
  * @return Route
  */
 public function processRoute(ConfigObject $routeConfig)
 {
     // base route
     $callback = $this->isString($routeConfig->Callback) ? $routeConfig->Callback : $routeConfig->Callback->toArray();
     $route = new Route($routeConfig->Path, $callback);
     // route options
     if (($options = $routeConfig->get('Options', false)) !== false) {
         $route->setOptions($options->toArray());
     }
     // host
     if (($host = $routeConfig->get('Host', false)) !== false) {
         $route->setHost($host);
     }
     // schemes
     if (($schemes = $routeConfig->get('Schemes', false)) !== false) {
         $route->setSchemes($schemes);
     }
     // methods
     if (($methods = $routeConfig->get('Methods', false)) !== false) {
         $route->setMethods($methods->toArray());
     }
     // tags
     if (($tags = $routeConfig->get('Tags', false)) !== false) {
         $route->setTags($tags->toArray());
     }
     return $route;
 }
示例#11
0
 /**
  * Register service using given config
  *
  * @param string       $serviceName
  * @param ConfigObject $config
  *
  * @param bool         $overwrite Overwrite service if it has been registered before (Default: false)
  *
  * @throws ServiceManagerException
  * @return $this
  */
 public function registerService($serviceName, ConfigObject $config, $overwrite = false)
 {
     /**
      * Check if service instance already exists
      */
     if ($this->registeredServices->keyExists($serviceName) && !$overwrite) {
         throw new ServiceManagerException(ServiceManagerException::SERVICE_NAME_ALREADY_EXISTS, [$serviceName]);
     }
     $this->registeredServices[$serviceName] = $config;
     /**
      * Tagify service
      */
     foreach ($config->get('Tags', []) as $tag) {
         $tagServices = $this->taggedServices->key($tag, [], true);
         $tagServices[] = $serviceName;
         $this->taggedServices->key($tag, $tagServices);
     }
     return $this;
 }
示例#12
0
 /**
  * Extracts the rate control information from the method annotations.
  *
  * @param ConfigObject $annotations
  *
  * @return array
  */
 private function getRateControl(ConfigObject $annotations)
 {
     return $annotations->get('rateControl', [], true);
 }
示例#13
0
 /**
  * Registers SwiftMailer plugins based on the provided $config.
  *
  * @param ConfigObject $config
  */
 private function registerPlugins(ConfigObject $config)
 {
     // antiflood
     if ($config->get('AntiFlood', false)) {
         $antiflood = new \Swift_Plugins_AntiFloodPlugin($config->get('AntiFlood.Threshold', 99), $config->get('AntiFlood.Sleep', 1));
         $this->mailer->registerPlugin($antiflood);
     }
 }
示例#14
0
 /**
  * @param string       $serviceName Service name
  * @param ConfigObject $config      ConfigObject to compile
  * @param array        $parameters  Parameters to use when parsing $config
  */
 public function __construct($serviceName, ConfigObject $config, $parameters)
 {
     $this->serviceName = $serviceName;
     $this->serviceConfig = $config->toArray(true);
     $this->parameters = $parameters;
 }
示例#15
0
文件: Rest.php 项目: Webiny/Framework
 /**
  * Internal static method that is called when initRest method matches a URL agains the Path.
  * This method then processes that matched response and then creates and returns a Rest instance back to iniRest.
  *
  * @param MatchedRoute $matchedRoute The matched route.
  * @param ConfigObject $config       Current api config.
  * @param string       $api          Current api name.
  *
  * @return Rest
  * @throws \Webiny\Component\StdLib\StdObject\StringObject\StringObjectException
  */
 private static function processRouterResponse(MatchedRoute $matchedRoute, ConfigObject $config, $api)
 {
     // based on the matched route create the class name
     $className = self::str($config->get('Router.Class'))->trimLeft('\\')->prepend('\\');
     $normalize = $config->get('Router.Normalize', false);
     $matchedParams = $matchedRoute->getParams();
     foreach ($matchedParams as $mpName => $mpParam) {
         if ($normalize) {
             $mpParam = self::str($mpParam)->replace('-', ' ')->caseWordUpper()->replace(' ', '');
         }
         $className->replace('{' . $mpName . '}', $mpParam);
     }
     // return the new rest instance
     return new self($api, $className->val());
 }
示例#16
0
 /**
  * Base constructor.
  *
  * @param ConfigObject $config
  */
 public function __construct(ConfigObject $config)
 {
     $library = $this->str($config->get('Library', 'gd'))->caseLower()->val();
     $this->instance = $this->getLibraryInstance($library);
 }
示例#17
0
 /**
  * Get cookie storage driver.
  *
  * @param ConfigObject|null $config Cookie config - needed only if storage driver does not yet exist.
  *
  * @return CookieStorageInterface
  * @throws \Webiny\Component\Http\Cookie\CookieException
  */
 private function getStorage(ConfigObject $config = null)
 {
     if (!isset($this->storage)) {
         try {
             $driver = $config->get('Storage.Driver', self::$nativeDriver);
             $this->storage = $this->factory($driver, '\\Webiny\\Component\\Http\\Cookie\\CookieStorageInterface', [$config]);
         } catch (Exception $e) {
             throw new CookieException($e->getMessage());
         }
     }
     return $this->storage;
 }
示例#18
0
 /**
  * Registers SwiftMailer plugins based on the provided $config.
  *
  * @param ConfigObject $config
  */
 private function registerPlugins(ConfigObject $config)
 {
     // antiflood
     if ($config->get('AntiFlood', false)) {
         $antiflood = new \Swift_Plugins_AntiFloodPlugin($config->get('AntiFlood.Threshold', 99), $config->get('AntiFlood.Sleep', 1));
         $this->mailer->registerPlugin($antiflood);
     }
     // array logger
     if ($config->get('Debug', false)) {
         $this->logger = new \Swift_Plugins_Loggers_ArrayLogger();
         $this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->logger));
     }
 }
示例#19
0
 /**
  * Initializes role hierarchy.
  */
 private function initRoleHierarchy()
 {
     $this->roleHierarchy = new RoleHierarchy($this->config->get('RoleHierarchy', [], true));
 }
示例#20
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;
 }