/** * 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); }
/** * 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; }
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)); } } }
/** * @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.'); } }
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; } } } }
/** * 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; }
/** * 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; }
/** * 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(); }
/** * 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(); } }
/** * 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; }
/** * 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; }
/** * Extracts the rate control information from the method annotations. * * @param ConfigObject $annotations * * @return array */ private function getRateControl(ConfigObject $annotations) { return $annotations->get('rateControl', [], true); }
/** * 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); } }
/** * @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; }
/** * 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()); }
/** * Base constructor. * * @param ConfigObject $config */ public function __construct(ConfigObject $config) { $library = $this->str($config->get('Library', 'gd'))->caseLower()->val(); $this->instance = $this->getLibraryInstance($library); }
/** * 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; }
/** * 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)); } }
/** * Initializes role hierarchy. */ private function initRoleHierarchy() { $this->roleHierarchy = new RoleHierarchy($this->config->get('RoleHierarchy', [], true)); }
/** * 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; }