@@ 11-39 (lines=29) @@ | ||
8 | use T4web\Migrations\Service\Generator; |
|
9 | use T4web\Migrations\Exception\RuntimeException; |
|
10 | ||
11 | class GenerateController extends AbstractActionController |
|
12 | { |
|
13 | /** |
|
14 | * @var Generator |
|
15 | */ |
|
16 | protected $generator; |
|
17 | ||
18 | /** |
|
19 | * @param Generator $generator |
|
20 | */ |
|
21 | public function __construct(Generator $generator) |
|
22 | { |
|
23 | $this->generator = $generator; |
|
24 | } |
|
25 | ||
26 | public function onDispatch(MvcEvent $e) |
|
27 | { |
|
28 | if (!$e->getRequest() instanceof ConsoleRequest) { |
|
29 | throw new RuntimeException('You can only use this action from a console!'); |
|
30 | } |
|
31 | ||
32 | $classPath = $this->generator->generate(); |
|
33 | ||
34 | $response = sprintf("Generated skeleton class @ %s\n", realpath($classPath)); |
|
35 | ||
36 | $e->setResult($response); |
|
37 | return $response; |
|
38 | } |
|
39 | } |
|
40 |
@@ 14-41 (lines=28) @@ | ||
11 | /** |
|
12 | * Migration commands controller |
|
13 | */ |
|
14 | class VersionController extends AbstractActionController |
|
15 | { |
|
16 | /** |
|
17 | * @var Table |
|
18 | */ |
|
19 | protected $table; |
|
20 | ||
21 | /** |
|
22 | * @param Table $table |
|
23 | */ |
|
24 | public function __construct(Table $table) |
|
25 | { |
|
26 | $this->table = $table; |
|
27 | } |
|
28 | ||
29 | public function onDispatch(MvcEvent $e) |
|
30 | { |
|
31 | if (!$e->getRequest() instanceof ConsoleRequest) { |
|
32 | throw new RuntimeException('You can only use this action from a console!'); |
|
33 | } |
|
34 | ||
35 | $response = sprintf("Current version %s\n", $this->table->getCurrentVersion()); |
|
36 | ||
37 | $e->setResult($response); |
|
38 | ||
39 | return $response; |
|
40 | } |
|
41 | } |
|
42 |