Config, setup and bootstrap
This commit is contained in:
32
app/bootstrap/app.php
Normal file
32
app/bootstrap/app.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
function buildApp(): Symfony\Component\Console\Application
|
||||||
|
{
|
||||||
|
$builder = new DI\ContainerBuilder();
|
||||||
|
|
||||||
|
$baseFolder = dirname(__DIR__);
|
||||||
|
$folders = [
|
||||||
|
'configs',
|
||||||
|
'setups'
|
||||||
|
];
|
||||||
|
foreach ($folders as $folderName) {
|
||||||
|
$folder = implode(DIRECTORY_SEPARATOR, [$baseFolder, $folderName]);
|
||||||
|
if (!isset($folder)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$files = new FilesystemIterator($folder);
|
||||||
|
foreach ($files as $file) {
|
||||||
|
if ($file->isDir()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$builder->addDefinitions($file->getRealPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$app = (new ProVM\Extend\Application())
|
||||||
|
->setContainer($builder->build());
|
||||||
|
return require_once 'commands.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'composer.php';
|
||||||
|
|
||||||
|
return buildApp();
|
9
app/bootstrap/commands.php
Normal file
9
app/bootstrap/commands.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
function buildCommands(\Symfony\Component\Console\Application &$app): \Symfony\Component\Console\Application {
|
||||||
|
$commands = $app->getContainer()->get('commands');
|
||||||
|
foreach ($commands as $commandClass) {
|
||||||
|
$app->add($app->getContainer()->get($commandClass));
|
||||||
|
}
|
||||||
|
return $app;
|
||||||
|
}
|
||||||
|
return buildCommands($app);
|
6
app/bootstrap/composer.php
Normal file
6
app/bootstrap/composer.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
require_once implode(DIRECTORY_SEPARATOR, [
|
||||||
|
dirname(__DIR__),
|
||||||
|
'vendor',
|
||||||
|
'autoload.php'
|
||||||
|
]);
|
6
app/configs/commands.php
Normal file
6
app/configs/commands.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'commands' => [
|
||||||
|
ProVM\Command\GenerateMigrations::class,
|
||||||
|
]
|
||||||
|
];
|
13
app/configs/env.php
Normal file
13
app/configs/env.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
...$_ENV,
|
||||||
|
'start_date' => '20141101080000',
|
||||||
|
'skips' => [
|
||||||
|
'monolog',
|
||||||
|
'phinxlog',
|
||||||
|
'personas',
|
||||||
|
'datos_personas',
|
||||||
|
'proveedores',
|
||||||
|
'datos_proveedores'
|
||||||
|
]
|
||||||
|
];
|
8
app/configs/paths.php
Normal file
8
app/configs/paths.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'paths.base' => dirname(__DIR__),
|
||||||
|
'paths.resources' => DI\String('{paths.base}/resources'),
|
||||||
|
'paths.database' => DI\String('{paths.resources}/database'),
|
||||||
|
'paths.migrations' => DI\String('{paths.database}/migrations'),
|
||||||
|
'paths.seeds' => DI\String('{paths.database}/seeds')
|
||||||
|
];
|
26
app/setups/concepts.php
Normal file
26
app/setups/concepts.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
return [
|
||||||
|
ProVM\Concept\Database::class => function(ContainerInterface $container) {
|
||||||
|
return (new ProVM\Database\MySQL())
|
||||||
|
->setHost($container->get('DB_HOST'))
|
||||||
|
->setName($container->get('DB_DATABASE'))
|
||||||
|
->setUser($container->get('DB_USER'))
|
||||||
|
->setPassword($container->get('DB_PASSWORD'));
|
||||||
|
},
|
||||||
|
ProVM\Concept\Database\Connection::class => function(ContainerInterface $container) {
|
||||||
|
return new ProVM\Database\Connection($container->get(ProVM\Concept\Database::class));
|
||||||
|
},
|
||||||
|
ProVM\Concept\Database\Query\Builder::class => function(ContainerInterface $container) {
|
||||||
|
return new ProVM\Database\Query\Builder([
|
||||||
|
ProVM\Concept\Database\Query\Select::class => ProVM\Database\Query\MySQL\Select::class,
|
||||||
|
ProVM\Concept\Database\Query\Insert::class => ProVM\Database\Query\MySQL\Insert::class,
|
||||||
|
ProVM\Concept\Database\Query\Update::class => ProVM\Database\Query\MySQL\Update::class,
|
||||||
|
ProVM\Concept\Database\Query\Delete::class => ProVM\Database\Query\MySQL\Delete::class,
|
||||||
|
ProVM\Concept\Database\Query\Create::class => ProVM\Database\Query\MySQL\Create::class,
|
||||||
|
ProVM\Concept\Database\Query\Drop::class => ProVM\Database\Query\MySQL\Drop::class,
|
||||||
|
ProVM\Concept\Database\Query\Truncate::class => ProVM\Database\Query\MySQL\Truncate::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
];
|
18
app/setups/generators.php
Normal file
18
app/setups/generators.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
return [
|
||||||
|
ProVM\Generator\Migration::class => function(ContainerInterface $container) {
|
||||||
|
return new ProVM\Generator\Migration(
|
||||||
|
$container->get(ProVM\Concept\Database\Connection::class),
|
||||||
|
$container->get(ProVM\Concept\Database::class),
|
||||||
|
$container->get(ProVM\Concept\Database\Query\Builder::class),
|
||||||
|
$container->get(ProVM\Repository\Table::class),
|
||||||
|
$container->get(Psr\Log\LoggerInterface::class),
|
||||||
|
new DateTimeImmutable($container->get('start_date')),
|
||||||
|
$container->get('DB_DATABASE'),
|
||||||
|
$container->get('paths.migrations'),
|
||||||
|
$container->get('skips')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
];
|
16
app/setups/logs.php
Normal file
16
app/setups/logs.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
return [
|
||||||
|
Psr\Log\LoggerInterface::class => function(ContainerInterface $container) {
|
||||||
|
return new Monolog\Logger('migrations', [
|
||||||
|
(new Monolog\Handler\RotatingFileHandler('/logs/migrations.log'))
|
||||||
|
->setFormatter(new Monolog\Formatter\LineFormatter(null, null, false, false, true))
|
||||||
|
], [
|
||||||
|
$container->get(Monolog\Processor\IntrospectionProcessor::class),
|
||||||
|
$container->get(Monolog\Processor\MemoryUsageProcessor::class),
|
||||||
|
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class),
|
||||||
|
$container->get(Monolog\Processor\PsrLogMessageProcessor::class)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
];
|
15
app/setups/repositories.php
Normal file
15
app/setups/repositories.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
|
||||||
|
return [
|
||||||
|
ProVM\Repository\Table::class => function(ContainerInterface $container) {
|
||||||
|
return new ProVM\Repository\Table(
|
||||||
|
$container->get(ProVM\Concept\Database\Connection::class),
|
||||||
|
$container->get('DB_DATABASE'));
|
||||||
|
},
|
||||||
|
ProVM\Repository\Data::class => function(ContainerInterface $container) {
|
||||||
|
return new ProVM\Repository\Data(
|
||||||
|
$container->get(ProVM\Concept\Database\Connection::class),
|
||||||
|
$container->get(ProVM\Concept\Database\Query\Builder::class));
|
||||||
|
}
|
||||||
|
];
|
Reference in New Issue
Block a user