Skip to content

Commit

Permalink
OrmSchemaTool: Automated tool for run o:s:u command in vanilla Nette
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Jul 12, 2019
1 parent 05d6aeb commit 6548d4e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/DatabaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public function afterCompile(ClassType $class): void
. '$entityManager->getConfiguration()->addCustomNumericFunction(\'rand\', ' . Rand::class . '::class);' . "\n"
. '$entityManager->buildCache();' . "\n"
. $initialize->getBody()
. (PHP_SAPI === 'cli' ? "\n"
. OrmSchemaUpdateTool::class . '::setContainer($this);' . "\n"
. 'register_shutdown_function([' . OrmSchemaUpdateTool::class . '::class, \'run\']);' : '')
);
}

Expand Down
50 changes: 50 additions & 0 deletions src/OrmSchemaUpdateTool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Baraja\Doctrine;


use Contributte\Console\Application;
use Nette\DI\Container;
use Tracy\Debugger;

class OrmSchemaUpdateTool
{

/**
* @var Container
*/
private static $container;

public static function run(): void
{
if (self::$container === null) {
return;
}

if (PHP_SAPI === 'cli' && preg_match('/^or?m?:sc?h?e?m?a?-?t?o?o?l?:up?d?a?t?e?$/', $_SERVER['argv'][1] ?? '')) {
try {
/** @var Application $application */
$application = self::$container->getByType(Application::class);

exit($application->run());
} catch (\Throwable $e) {
Debugger::log($e);

echo $e->getMessage();

exit($e->getCode() ? : 1);
}
}
}

/**
* @param Container $container
*/
public static function setContainer(Container $container): void
{
self::$container = $container;
}

}

0 comments on commit 6548d4e

Please sign in to comment.