示例#1
0
 /**
  * Registers services for the applications
  * 
  * @param Application $app
  */
 private function registerServices(Application $app)
 {
     // Queue message for emailing task
     $app['email_message'] = function (Application $app) {
         return new EmailMessage(['mailer' => $app['mailer']]);
     };
     // To use Gmail SMTP server for mailing, use smtp transport
     $app['swiftmailer.transport'] = Swift_SmtpTransport::newInstance($app['email_host'], $app['email_port'], $app['email_encrypt'])->setUsername($app['email_username'])->setPassword($app['email_password']);
     // Register SwiftMailer with smtp transport
     $app['mailer'] = $app->share(function ($app) {
         return new Swift_Mailer($app['swiftmailer.transport']);
     });
     // Queue manager which handles queue processing
     $app['queue_manager'] = $app->share(function ($app) {
         // Set up pdo connection to the database
         $dbh = new PDO($app['db_dsn'], $app['db_user'], $app['db_password']);
         $manager = new Manager();
         // Let manager use this connection for database management
         $manager->setPdo($dbh);
         return $manager;
     });
 }
示例#2
0
#!/usr/bin/env php

<?php 
use PDO;
use Swift_Mailer;
use Queue\Manager;
use Swift_SmtpTransport;
use Igorw\Silex\ConfigServiceProvider;
set_time_limit(0);
require_once __DIR__ . '/vendor/autoload.php';
$app = new Silex\Application();
// For building console commands
$app->register(new Knp\Provider\ConsoleServiceProvider(), ['console.name' => 'EmailAppConsole', 'console.version' => '0.1.0', 'console.project_directory' => __DIR__ . "/.."]);
// Register general application settings
$app->register(new ConfigServiceProvider(__DIR__ . "/config/settings.json"));
// Register environment-specific parameters
$app->register(new ConfigServiceProvider(__DIR__ . "/config/{$app['environment']}.json"));
$app['swiftmailer.transport'] = Swift_SmtpTransport::newInstance($app['email_host'], $app['email_port'], $app['email_encrypt'])->setUsername($app['email_username'])->setPassword($app['email_password']);
$app['mailer'] = $app->share(function ($app) {
    return new Swift_Mailer($app['swiftmailer.transport']);
});
$app['queue_manager'] = $app->share(function ($app) {
    $dbh = new PDO($app['db_dsn'], $app['db_user'], $app['db_password']);
    $manager = new Manager();
    $manager->setPdo($dbh);
    return $manager;
});
$console = $app["console"];
$console->add(new Emailapp\EmailCommand());
$console->run();