Esempio n. 1
0
 public function testUsage()
 {
     $di = new \PHPCraftdream\BeeEye\BeeEye();
     ###########################################################################
     $di->set('dbConf', function ($di, $args) {
         $object = new \stdClass();
         $object->dbHost = 'localhost';
         $object->dbUser = '******';
         $object->dbPass = '******';
         $object->dbName = 'database';
         $object->getCount = 0;
         return $object;
     }, function ($di, $object, $args) {
         $object->getCount++;
         return $object;
     });
     ###########################################################################
     $di->set('db', function ($di, $args) {
         $object = new \stdClass();
         $object->dbConf = $di->get('dbConf');
         $object->getCount = 0;
         return $object;
     }, function ($di, $object, $args) {
         $object->getCount++;
         return clone $object;
     });
     ###########################################################################
     $db1 = $di->get('db');
     $db2 = $di->get('db');
     $di->get('dbConf')->TEST = 'TEST';
     $this->assertEquals('TEST', $db1->dbConf->TEST);
     $this->assertEquals('TEST', $db2->dbConf->TEST);
     $this->assertTrue($db1 === $db1);
     $this->assertTrue($db2 === $db2);
     $this->assertTrue($db1 !== $db2);
     $this->assertEquals(1, $db1->getCount);
     $this->assertEquals(2, $db2->getCount);
     $this->assertEquals(2, $db1->dbConf->getCount);
     $this->assertEquals(2, $db2->dbConf->getCount);
     $di->get('dbConf');
     $this->assertEquals(3, $db1->dbConf->getCount);
     $this->assertEquals(3, $db2->dbConf->getCount);
 }
Esempio n. 2
0
<?php

require_once 'autoload.php';
###########################################################################
$di = new \PHPCraftdream\BeeEye\BeeEye();
###########################################################################
$di->set('dbConf', function ($di, $args) {
    $object = new \stdClass();
    $object->dbHost = 'localhost';
    $object->dbUser = '******';
    $object->dbPass = '******';
    $object->dbName = 'database';
    $object->getCount = 0;
    return $object;
}, function ($di, $object, $args) {
    $object->getCount++;
    return $object;
});
###########################################################################
$di->set('db', function ($di, $args) {
    $object = new \stdClass();
    $object->dbConf = $di->get('dbConf');
    $object->getCount = 0;
    return $object;
}, function ($di, $object, $args) {
    $object->getCount++;
    return clone $object;
});
###########################################################################
$db1 = $di->get('db');
$db2 = $di->get('db');