Esempio n. 1
0
 public function testShouldRegisterServicesDefinedInArray()
 {
     $di = new \Phalcon\Di\FactoryDefault();
     $fooClassStr = 'class Foo implements \\Vegas\\Di\\Injector\\SharedServiceProviderInterface {
         public function getName() {
             return "foo";
         }
         public function getProvider(\\Phalcon\\DiInterface $di) {
             return function() {
                 $o = new \\stdClass;
                 $o->foo = "bar";
                 return $o;
             };
         }
     }';
     eval($fooClassStr);
     $barClassStr = 'class Bar implements \\Vegas\\Di\\Injector\\SharedServiceProviderInterface {
         public function getName() {
             return "bar";
         }
         public function getProvider(\\Phalcon\\DiInterface $di) {
             return function() {
                 $o = new \\stdClass;
                 $o->bar = "foo";
                 return $o;
             };
         }
     }';
     eval($barClassStr);
     $injector = new Injector($di);
     $injector->inject(['Foo', 'Bar']);
     $this->assertTrue($di->has('foo'));
     $this->assertNotNull($di->get('foo'));
     $this->assertNotNull($di->get('bar'));
     $this->assertEquals("foo", $di->get('bar')->bar);
     $this->assertEquals("bar", $di->get('foo')->foo);
 }
Esempio n. 2
0
 public function testCrash()
 {
     $di = new Phalcon\Di\FactoryDefault();
     $bag = $di->get('sessionBag', array('dummy'));
     $this->assertTrue(true);
 }
/**
 * @description App - \App\Http\Response
 */
$di->setShared(Services::RESPONSE, new \App\Services\Response());
/**
 * @description Phalcon - \Phalcon\Crypt
 */
$di->set(Services::CRYPT, function () use($config) {
    $crypt = new \Phalcon\Crypt();
    $crypt->setKey($config->cryptKey);
    return $crypt;
});
/**
 * @description Phalcon - \Phalcon\Http\Response\Cookies
 */
$di->set(Services::COOKIES, function () {
    $cookies = new \Phalcon\Http\Response\Cookies();
    $cookies->useEncryption(false);
    return $cookies;
});
/**
 * @description Phalcon - \Phalcon\Db\Adapter\Pdo\Mysql
 */
$di->setShared(Services::DB, function () use($config, $di) {
    $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
    // Assign the eventsManager to the db adapter instance
    $connection->setEventsManager($di->get(Services::EVENTS_MANAGER));
    return $connection;
});
$di->set('config', $config);
return $di;