/** * @return DependencyContainer */ private function collectDependencies() { $dependencies = new DependencyContainer(); if (!$this->invokableReflection) { return $dependencies; } foreach ($this->invokableReflection->getParameters() as $parameter) { $dependencies->addDependency($parameter); } return $dependencies; }
/** * @expectedException InvincibleMarketing\Courses\DBException */ public function testDependencyContainerIncorrectDbDetails() { $container = DependencyContainer::getInstance(); $container->setConfiguration('./tests/_files/settings_incorrect.yml'); $container->setDbConnection(); $db = $container->getDbConnection(); }
protected function _before() { $this->container = DependencyContainer::getInstance(); $this->container->setConfiguration('./tests/_files/settings_correct.yml'); $this->container->setRouter('./tests/_files/router_correct.yml'); $this->container->setTwig(); $this->container->setDbConnection(); }
public function testAbstractEntity() { $container = DependencyContainer::getInstance(); $container->setConfiguration('./tests/_files/settings_correct.yml'); $container->setRouter('./tests/_files/router_correct.yml'); $container->setTwig(); $container->setDbConnection(); $testEntity = new TestEntity($container->getDbConnection()); $connection = $testEntity->getDb(); $this->assertNotNull($connection); $tableName = $testEntity->getTableName(); $this->assertEquals($tableName, 'test_entity'); }
// trim POST array, preserve array values function storeArrays(array $input) { $result = array(); foreach ($input as $key => $value) { if (is_array($value)) { $result[$key] = $value; } } return $result; } $preservedArrays = storeArrays($_POST); $_POST = array_map('trim', $_POST); $_POST = array_merge($_POST, $preservedArrays); // load the dependencies into the container $container = DependencyContainer::getInstance(); try { $container->setConfiguration(APP_PATH . '/config/settings.yml'); } catch (ParameterNotFoundException $e) { echo "Missing Environment!"; die; } catch (WrongFileFormatException $e) { echo "Wrong File Format - config/settings.yml!"; die; } try { $container->setDbConnection(); } catch (DBException $e) { echo "Cannot connect to database!"; die; }
public function __construct(DependencyContainer $container) { $this->container = $container; $this->dbConnection = $container->getDbConnection(); }
public function __construct() { $this->container = DependencyContainer::getInstance(); }