PHP code example of whirlwind-framework / migration-core
1. Go to this page and download the library: Download whirlwind-framework/migration-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
whirlwind-framework / migration-core example snippets
class DummyMigrationTableGateway extends MongoTableGateway implements MigrationTableGatewayInterface
{
protected string $collectionName = 'migrations';
public function queryOrCreateCollection(array $conditions = [], int $limit = 0, array $order = []): array
{
$collection = $this->connection->listCollections(['name' => $this->collectionName]);
if (!$collection) {
$this->createCollection($this->collectionName);
}
return $this->queryAll($conditions, $order, $limit)
}
}
class DummyBlueprint implements \Whirlwind\MigrationCore\BlueprintInterface
{
protected string $collectionName;
protected Query $current; // your database query builder implementation
protected array $queries = [];
public function __construct(string $collectionName) {
$this->collectionName = $collectionName;
}
public function build(ConnectionInterface $connection): void
{
foreach ($queries as $query) {
$query->execute($connection);
}
}
public function create(callable $callback): void
{
$this->current = new Query();
$callback($this);
$this->queries[] = $this->current;
}
public function drop(): void
{
$this->queries[] = (new Query())->dropCollection($this->collectionName);
}
public function dropIfExists(): void
{
$this->queries[] = (new Query())->dropCollectionIfExists($this->collectionName);
}
public function createIfNotExists(callable $callback)
{
$this->create($callback);
}
}
class MyDatabaseServiceProvider extends \League\Container\ServiceProvider\AbstractServiceProvider
{
public function register(): void
{
$container->add(
\Whirlwind\MigrationCore\Config\MigrationPaths::class,
fn() => new \Whirlwind\MigrationCore\Config\MigrationPaths([
new \Whirlwind\MigrationCore\Config\MigrationPath(
'path/to/your/migrations',
'Your\\Migration\\Namespace'
),
new \Whirlwind\MigrationCore\Config\MigrationPath(
'path/to/your/another/migrations',
'Your\\Another\\Migration\\Namespace'
),
])
);
$container->add(
\Whirlwind\MigrationCore\Config\Config::class,
fn () => new \Whirlwind\MigrationCore\Config\Config(
$container->get(\Whirlwind\MigrationCore\Config\MigrationPaths::class),
'/path/to/your/template' // by default using template from core package
)
);
}
}