//connect to memcached server //$memcached->addServer($options['memcached']['host'], $options['memcached']['port']); /** * Database Section * */ //create adapter $MysqlAdapter = new MysqlPDOAdapter($options['pdo_mysql']['db_type'] . ':host=' . $options['pdo_mysql']['host'] . ';dbname=' . $options['pdo_mysql']['db_name'] . ';charset=' . $options['pdo_mysql']['charset'], $options['pdo_mysql']['user'], $options['pdo_mysql']['password'], array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING)); //create data base object $dataBase = new Database($MysqlAdapter); /** * Dependency Injection Section * */ //create dipendency injection resolver $DIResolver = new DIResolver(); //add unresolvable class to DIResolver $DIResolver->cacheUnResolvable('\\Linna\\Database\\Database', $dataBase); //$DIResolver->cacheUnResolvable('\Memcached', $memcached); //$DIResolver->cacheUnResolvable('\Linna\Session\MemcachedSessionHandler', new MemcachedSessionHandler($memcached, $options['session']['expire'])); /** * Session section * */ //resolve Session Handler $sessionHandler = $DIResolver->resolve('\\Linna\\Session\\DatabaseSessionHandler'); //$sessionHandler = $DIResolver->resolve('\Linna\Session\MemcachedSessionHandler'); //create session object $session = new Session($options['session']); //set session handler //optional if not set, app will use php session standard storage
public function testResolve() { $DIResolver = new DIResolver(); $DIResolver->cacheUnResolvable('\\Linna\\FOO\\FOOClassAA', new FOOClassAA('DIResolver')); $FOOClassA = $DIResolver->resolve('\\Linna\\FOO\\FOOClassA'); $FOOClassB = $DIResolver->resolve('\\Linna\\FOO\\FOOClassB'); $FOOClassC = $DIResolver->resolve('\\Linna\\FOO\\FOOClassC'); $FOOClassD = $DIResolver->resolve('\\Linna\\FOO\\FOOClassD'); $FOOClassE = $DIResolver->resolve('\\Linna\\FOO\\FOOClassE'); $FOOClassF = $DIResolver->resolve('\\Linna\\FOO\\FOOClassF'); $FOOClassG = $DIResolver->resolve('\\Linna\\FOO\\FOOClassG'); $FOOClassH = $DIResolver->resolve('\\Linna\\FOO\\FOOClassH'); $FOOClassI = $DIResolver->resolve('\\Linna\\FOO\\FOOClassI'); $this->assertInstanceOf(\Linna\FOO\FOOClassA::class, $FOOClassA); $this->assertInstanceOf(\Linna\FOO\FOOClassB::class, $FOOClassB); $this->assertInstanceOf(\Linna\FOO\FOOClassC::class, $FOOClassC); $this->assertInstanceOf(\Linna\FOO\FOOClassD::class, $FOOClassD); $this->assertInstanceOf(\Linna\FOO\FOOClassE::class, $FOOClassE); $this->assertInstanceOf(\Linna\FOO\FOOClassF::class, $FOOClassF); $this->assertInstanceOf(\Linna\FOO\FOOClassG::class, $FOOClassG); $this->assertInstanceOf(\Linna\FOO\FOOClassH::class, $FOOClassH); $this->assertInstanceOf(\Linna\FOO\FOOClassI::class, $FOOClassI); }