Skip to content

Commit 150893e

Browse files
committed
Add more dependencies.
1 parent 7cf4696 commit 150893e

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

src/NomadicMigration.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace ChrisHalbert\LaravelNomadic;
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
abstract class NomadicMigration extends Migration
8+
{
9+
protected $properties = array();
10+
11+
public function setProperty($key, $value)
12+
{
13+
$this->properties[$key] = $value;
14+
}
15+
16+
public function getProperty($key)
17+
{
18+
return $this->properties[$key];
19+
}
20+
21+
public function getProperties()
22+
{
23+
return $this->properties;
24+
}
25+
}

src/NomadicMigrator.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
namespace ChrisHalbert\LaravelNomadic;
3+
4+
use Illuminate\Database\Migrations\Migrator;
5+
use ChrisHalbert\LaravelNomadic\NomadicRepositoryInterface;
6+
7+
8+
use Illuminate\Filesystem\Filesystem;
9+
use Illuminate\Database\ConnectionResolverInterface as Resolver;
10+
11+
class NomadicMigrator extends Migrator
12+
{
13+
/**
14+
* The migration repository implementation.
15+
*
16+
* @var \Illuminate\Database\Migrations\MigrationRepositoryInterface
17+
*/
18+
protected $repository;
19+
20+
/**
21+
* Create a new migrator instance.
22+
*
23+
* @param NomadicRepositoryInterface $repository
24+
* @param \Illuminate\Database\ConnectionResolverInterface $resolver
25+
* @param \Illuminate\Filesystem\Filesystem $files
26+
* @return void
27+
*/
28+
public function __construct(NomadicRepositoryInterface $repository,
29+
Resolver $resolver,
30+
Filesystem $files)
31+
{
32+
$this->files = $files;
33+
$this->resolver = $resolver;
34+
$this->repository = $repository;
35+
}
36+
37+
/**
38+
* Run "up" a migration instance.
39+
*
40+
* @param string $file
41+
* @param int $batch
42+
* @param bool $pretend
43+
* @return void
44+
*/
45+
protected function runUp($file, $batch, $pretend)
46+
{
47+
// First we will resolve a "real" instance of the migration class from this
48+
// migration file name. Once we have the instances we can run the actual
49+
// command such as "up" or "down", or we can just simulate the action.
50+
$migration = $this->resolve(
51+
$name = $this->getMigrationName($file)
52+
);
53+
54+
if ($pretend) {
55+
return $this->pretendToRun($migration, 'up');
56+
}
57+
58+
$this->note("<comment>Migrating:</comment> {$name}");
59+
60+
$this->runMigration($migration, 'up');
61+
62+
// Once we have run a migrations class, we will log that it was run in this
63+
// repository so that we don't try to run it next time we do a migration
64+
// in the application. A migration repository keeps the migrate order.
65+
$this->repository->log($name, $batch, $migration->getProperties());
66+
67+
$this->note("<info>Migrated:</info> {$name}");
68+
}
69+
}

src/NomadicServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function registerRepository()
2828
$this->app->singleton('migration.repository', function ($app) {
2929
$table = $app['config']['database.migrations'];
3030

31-
return new DatabaseNomadizationRepository($app['db'], $table);
31+
return new DatabaseNomadicRepository($app['db'], $table);
3232
});
3333
}
3434

@@ -45,7 +45,7 @@ protected function registerMigrator()
4545
$this->app->singleton('migrator', function ($app) {
4646
$repository = $app['migration.repository'];
4747

48-
return new Nomad($repository, $app['db'], $app['files']);
48+
return new NomadicMigrator($repository, $app['db'], $app['files']);
4949
});
5050
}
5151
}

0 commit comments

Comments
 (0)