addConnection() public méthode

Add database connection
public addConnection ( string $name, string $dsn, array $options = [], $default = false ) : Spot_Adapter_Interface
$name string Unique name for the connection
$dsn string DSN string for this connection
$options array Array of key => value options for adapter
Résultat Spot_Adapter_Interface Spot adapter instance
 public function register()
 {
     $di = $this->getContainer();
     $connections = $di->get('config')['connections'];
     $first = true;
     foreach ($connections as $connection) {
         $di->add('spot.config.' . $connection['name'], function ($logger) use($connection) {
             $cfg = new Config();
             $param = isset($connection['dsn']) ? $connection['dsn'] : $connection;
             $conn = $cfg->addConnection($connection['name'], $param);
             $sqlLogger = new \Laasti\SpotProvider\MonologSqlLogger($logger);
             $conn->getConfiguration()->setSQLLogger($sqlLogger);
             return $cfg;
         }, true)->withArgument('Psr\\Log\\LoggerInterface');
         $di->add('spot.locator.' . $connection['name'], function () use($di, $connection) {
             $spot = new Locator($di->get('spot.config.' . $connection['name']));
             return $spot;
         }, true);
         if ($first) {
             $di->add('Spot\\Config', function () use($di, $connection) {
                 return $di->get('spot.config.' . $connection['name']);
             }, true);
             $di->add('Spot\\Locator', function ($config = null) use($di, $connection) {
                 return $di->get('spot.locator.' . $connection['name'], [$config]);
             }, true);
             $first = false;
         }
     }
 }
Exemple #2
0
 public function register()
 {
     $this->app['spot'] = function () {
         $config = new Config();
         $config->addConnection('default', $this->config);
         return new Locator($config);
     };
 }
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     $app['spot'] = $app->share(function ($app) {
         $config = new SpotConfig();
         $config->addConnection('mysql', ['dbname' => $app->config('database.database'), 'user' => $app->config('database.user'), 'password' => $app->config('database.password'), 'host' => $app->config('database.host'), 'driver' => 'pdo_mysql']);
         return new SpotLocator($config);
     });
 }
 /**
  * Register this provider.
  *
  * The spot2.connections array can have an arbitrary number of connections in
  * it. The array should use the following format:
  *
  * <code>
  * $connections = [
  *      'my_sqlite' => 'sqlite://path/to/my_database.sqlite',
  *      'my_sqlite' => [
  *          'dbname'   => 'my_database',
  *          'user'     => 'username',
  *          'password' => 'sshhh-secret',
  *          'host'     => 'localhost',
  *          'drivers'  => 'pdo_mysql'
  *      ]
  * ];
  * </code>
  *
  * @param Silex\Application $app
  *
  * @author Ronan Chilvers <*****@*****.**>
  */
 public function register(Application $app)
 {
     $app['spot2.connections'] = [];
     $app['spot2.connections.default'] = null;
     $app['spot2.config'] = $app->share(function (Application $app) {
         $config = new Config();
         foreach ($app['spot2.connections'] as $name => $data) {
             $default = $app['spot2.connections.default'] === $name ? true : false;
             $config->addConnection($name, $data, $default);
         }
         return $config;
     });
     $app['spot2.locator'] = $app->share(function (Application $app) {
         return new Locator($app['spot2.config']);
     });
 }
Exemple #5
0
 * User: kayladaniels
 * Date: 3/24/15
 * Time: 9:46 PM
 */
use GuzzleHttp\Client;
use Spot\Config;
use Spot\Locator;
require_once __DIR__ . '/vendor/autoload.php';
Dotenv::load(__DIR__);
session_start();
$app = new \Slim\Slim(array('templates.path' => './views', 'debug' => true));
$loader = new Twig_Loader_Filesystem(__DIR__ . '/views');
$twig = new Twig_Environment($loader);
$cfg = new Config();
// MySQL
$cfg->addConnection('mysql', 'mysql://' . $_ENV['DATABASE_USER'] . ':' . $_ENV['DATABASE_PASSWORD'] . '@localhost/helpmeabstract');
$spot = new Locator($cfg);
$volunteerMapper = $spot->mapper('Kayladnls\\Entity\\Volunteer');
$proposalMapper = $spot->mapper('Kayladnls\\Entity\\Proposal');
$app->notFound(function () use($app) {
    $app->redirect('/error');
});
$app->get('/', function () use($twig, $volunteerMapper) {
    $volunteers = $volunteerMapper->getForHomePage();
    echo $twig->render('index.php', array('volunteers' => $volunteers));
});
$app->get('/volunteer', function () use($twig) {
    echo $twig->render('volunteer.php');
});
$app->post('/submitVolunteer', function () use($twig, $volunteerMapper) {
    $field_errors = $volunteerMapper->verifyFields();