Changing how database connections are held. Adding phinx stuff.
This commit is contained in:
parent
ad8dc7fa6c
commit
049814387a
3 changed files with 22 additions and 12 deletions
19
src/App.php
19
src/App.php
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Benzine;
|
||||
|
||||
use Benzine\ORM\Connection\Databases;
|
||||
use Benzine\ORM\Laminator;
|
||||
use Benzine\Services\ConfigurationService;
|
||||
use Benzine\Services\EnvironmentService;
|
||||
|
|
@ -68,6 +69,15 @@ class App
|
|||
$errorMiddleware = $this->app->addErrorMiddleware(true, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from Dependency Injection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $id){
|
||||
return $this->getApp()->getContainer()->get($id);
|
||||
}
|
||||
|
||||
protected function setup(ContainerInterface $container): void
|
||||
{
|
||||
$this->logger = $container->get(Logger::class);
|
||||
|
|
@ -227,10 +237,17 @@ class App
|
|||
);
|
||||
});
|
||||
|
||||
$container->set(Databases::class, function(ContainerInterface $container){
|
||||
return new Databases(
|
||||
$container->get(ConfigurationService::class)
|
||||
);
|
||||
|
||||
});
|
||||
$container->set(Laminator::class, function(ContainerInterface $container){
|
||||
return new Laminator(
|
||||
APP_ROOT,
|
||||
$container->get(ConfigurationService::class)
|
||||
$container->get(ConfigurationService::class),
|
||||
$container->get(Databases::class)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace Benzine\Controllers;
|
|||
use Laminas\Db\Adapter\Exception\InvalidQueryException;
|
||||
use Slim\Http\Request;
|
||||
use Slim\Http\Response;
|
||||
use ⌬\Database\Interfaces\ModelInterface;
|
||||
use Benzine\ORM\Interfaces\ModelInterface;
|
||||
|
||||
abstract class CrudController extends Controller
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Benzine\Services;
|
|||
|
||||
use Benzine\App;
|
||||
use Benzine\ORM\Connection\Database;
|
||||
use Benzine\ORM\Connection\Databases;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ConfigurationService
|
||||
|
|
@ -95,17 +96,9 @@ class ConfigurationService
|
|||
return trim($scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Database[]
|
||||
*/
|
||||
public function getDatabases() : array
|
||||
public function getDatabases() : Databases
|
||||
{
|
||||
$databases = [];
|
||||
foreach($this->config['databases'] as $name => $config){
|
||||
$database = new Database($name, $config);
|
||||
$databases[$database->getName()] = $database;
|
||||
}
|
||||
return $databases;
|
||||
return $this->databases;
|
||||
}
|
||||
|
||||
public function getNamespace(): string
|
||||
|
|
|
|||
Loading…
Reference in a new issue