/**
  * {@inheritDoc}
  */
 public function register(Application $app)
 {
     $app['email.mapper'] = $app->share(function (Application $app) {
         return new EmailMapper($app['db'], new EmailEntity());
     });
     $app['email.service'] = $app->share(function (Application $app) {
         $service = new EmailService();
         $service->setEmailMapper($app['email.mapper'])->setEmailConfig($app['config']->load('email'))->setResque($app['resque']);
         return $service;
     });
     $app['email.sender'] = $app->share(function (Application $app) {
         $emailConfig = $app['config']->load('email');
         if (!($apiKey = Arr::path($emailConfig, 'sender.mandrill.apiKey'))) {
             return;
         }
         $sender = new MandrillSender(new Mandrill($apiKey), $app['email.mapper']);
         $sender->setConfig($emailConfig);
         return $sender;
     });
     $app['email.send'] = $app->share(function (Application $app) {
         $command = new SendEmailCommand('email:send');
         $command->setEmailMapper($app['email.mapper']);
         if ($app['email.sender']) {
             $command->setEmailSender($app['email.sender']);
         }
         return $command;
     });
 }
 /**
  * Wrap the handle function and only allow a record through if it is not a
  * DummyException
  *
  * {@inheritDoc}
  */
 public function handle(array $record)
 {
     $e = Arr::path($record, 'context.exception');
     if ($e !== null and $e instanceof DummyException) {
         return false;
     }
     return $this->handler->handle($record);
 }
예제 #3
0
 /**
  * Create an email entity from an array and populate with default data
  *
  * @param  array  $data Data to populate the email
  * @return Email
  */
 public function createFromArray(array $data)
 {
     $headers = json_encode(Arr::path($this->emailConfig, 'defaults.headers', []));
     $defaults = ['headers' => $headers, 'sender_email' => Arr::path($this->emailConfig, 'defaults.sender.email'), 'sender_name' => Arr::path($this->emailConfig, 'defaults.sender.name')];
     $email = $this->emailMapper->getPrototype();
     $email = $email->exchangeArray(array_merge($defaults, $data));
     $email = $this->emailMapper->persist($email);
     return $email;
 }
예제 #4
0
 /**
  * Return the whitelist trap address with the specified email injected as a suffix
  *
  * Example:
  *     Email to transform : smith@email.com
  *     Trap email         : foo@bar.com
  *     Result             : foo+smith+email.com@bar.com
  *
  * @param  string $address Email address to transform
  * @return string          Transformed address
  */
 protected function injectIntoTrapAddress($address)
 {
     $trapAddress = Arr::path($this->config, 'whitelist.trap');
     if (!$trapAddress) {
         throw new RuntimeException('Email address not whitelisted but no email trap exists');
     }
     $address = str_ireplace('@', '+', $address);
     list($trapName, $trapDomain) = explode('@', $trapAddress);
     return sprintf('%s+%s@%s', $trapName, $address, $trapDomain);
 }
예제 #5
0
 /**
  * @param RollbarNotifier  $rollbarNotifier RollbarNotifier object constructed with valid token
  * @param string           $environment
  * @param boolean          $bubble          Whether the messages that are handled can bubble up the stack or not
  */
 public function __construct($config, $environment, $bubble = true)
 {
     $token = Arr::get($config, 'post_server_item_access_token');
     if (!$token) {
         throw new ConfigException('Rollbar is enabled but the post server item access token is not set.');
     }
     $this->rollbarNotifier = new RollbarNotifier(['access_token' => $token, 'environment' => $environment, 'batched' => false, 'root' => Arr::get($config, 'root')]);
     $level = Arr::path($config, 'level') ?: Logger::ERROR;
     parent::__construct($level, $bubble);
 }
 public function register(Application $app)
 {
     $app['css-to-inline'] = $app->share(function ($app) {
         return new CssToInlineStyles();
     });
     $app['handlebars'] = $app->share(function ($app) {
         $emailConfig = $app['config']->load('template');
         $templatePath = Arr::path($emailConfig, 'handlebars.path', APPDIR . '/templates');
         return new Handlebars(['loader' => new FilesystemLoader($templatePath, ['extension' => '.hbs']), 'partials_loader' => new FilesystemLoader($templatePath, ['prefix' => '_'])]);
     });
     $app['template.service'] = $app->share(function ($app) {
         return new TemplateService($app['handlebars'], $app['css-to-inline']);
     });
 }
예제 #7
0
 /**
  * Create an email entity from an array and populate with default data
  *
  * @param  array  $data Data to populate the email
  * @return Email
  */
 public function createFromArray(array $data)
 {
     $headers = json_encode(Arr::path($this->emailConfig, 'defaults.headers', []));
     if (isset($data['sender_localpart'])) {
         if (!Arr::path($this->emailConfig, 'defaults.sender.domain')) {
             throw new \Exception('defaults.sender.domain not set in email config');
         }
         $data['sender_email'] = Arr::remove($data, 'sender_localpart') . '@' . Arr::path($this->emailConfig, 'defaults.sender.domain');
     }
     $defaults = ['headers' => $headers, 'sender_email' => Arr::path($this->emailConfig, 'defaults.sender.email'), 'sender_name' => Arr::path($this->emailConfig, 'defaults.sender.name')];
     $email = $this->emailMapper->getPrototype();
     $email = $email->exchangeArray(array_merge($defaults, $data));
     $email = $this->emailMapper->persist($email);
     return $email;
 }
예제 #8
0
 /**
  * Log handler for Loggly
  *
  * @return LogglyHandler
  */
 protected function getLogglyHandler()
 {
     $token = Arr::path($this->config, 'loggly.token');
     if (!$token) {
         throw new ConfigException('Loggly is enabled but the token is not set.');
     }
     return new LogglyHandler($token, Logger::INFO);
 }
예제 #9
0
 /**
  * Tests Arr::path()
  *
  * @test
  * @dataProvider providerPath
  * @param string  $path       The path to follow
  * @param mixed   $default    The value to return if dnx
  * @param boolean $expected   The expected value
  * @param string  $delimiter  The path delimiter
  */
 public function testPath($expected, $array, $path, $default = null, $delimiter = null)
 {
     $this->assertSame($expected, Arr::path($array, $path, $default, $delimiter));
 }
예제 #10
0
 /**
  * Retrieves multiple paths from an array. If the path does not exist in the
  * array, the default value will be added instead.
  *
  *     // Get the values "username", "password" from $_POST
  *     $auth = Arr::extract($_POST, array('username', 'password'));
  *
  *     // Get the value "level1.level2a" from $data
  *     $data = array('level1' => array('level2a' => 'value 1', 'level2b' => 'value 2'));
  *     Arr::extract($data, array('level1.level2a', 'password'));
  *
  * @param  array $array   array to extract paths from
  * @param  array $paths   list of path
  * @param  mixed $default default value
  * @return array
  */
 public static function extract($array, array $paths, $default = null)
 {
     $found = [];
     foreach ($paths as $path) {
         Arr::setPath($found, $path, Arr::path($array, $path, $default));
     }
     return $found;
 }