/** * Chargement une classe de type Table * * @param string $tableName * @return Table */ protected function loadTable($tableName) { if (!isset($this->tables[$tableName])) { $this->tables[$tableName] = DIC::get($tableName); $this->tables[$tableName]->db = Connections::get(); } return $this->tables[$tableName]; }
/** * Permet de tester la facade DIC */ public function testFacadeDIC() { DIC::set(Connection::class, function (DependencyResolver $dic) { return new Connection('test', 'root', ''); }); $this->assertCount(1, DependencyResolver::getInstance()->singletons); DIC::setFactory(Model::class, function (DependencyResolver $dic) { return new Model($dic->get(Connection::class)); }); $this->assertCount(1, DependencyResolver::getInstance()->factories); $emptyInstance = new EmptyConstruct(); DIC::setInstance($emptyInstance); $this->assertCount(1, DependencyResolver::getInstance()->instancies); $connectionInstance = DIC::get(Connection::class); $this->assertInstanceOf(Connection::class, $connectionInstance); $this->assertSame('test', $connectionInstance->db_name); $constructorInstance = DIC::createInstance(new ReflectionClass(EmptyExistConstruct::class)); $this->assertInstanceOf(EmptyExistConstruct::class, $constructorInstance); }
private function getCallParameters($parameters) { $result = []; foreach ($parameters as $parameter) { $class = $parameter->getClass(); if ($class) { try { $result[] = DIC::get($class); } catch (DependencyException $e) { $result[] = null; } } elseif (isset($this->matches[$parameter->getName()])) { $result[] = $this->matches[$parameter->getName()]; // En vrai les langage qui m'on le plus appris c'est le C#, C/C++ } elseif ($parameter->isDefaultValueAvailable()) { $result[] = $parameter->getDefaultValue(); } elseif (!$parameter->isOptional()) { $result[] = null; } } return $result; }