1. Go to this page and download the library: Download tflori/breyta 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/ */
tflori / breyta example snippets
namespace Breyta\Migrations;
use Breyta\AbstractMigration;
class CreateAnimalsTable extends AbstractMigration
{
public function up(): void
{
$this->exec('DROP TABLE IF EXISTS animals');
$this->exec('CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
)');
}
public function down(): void
{
$this->exec('DROP TABLE IF EXISTS animals');
}
}
namespace App\Cli\Commands;
class MigrateCommand extends AbstractCommand // implements \Breyta\ProgressInterface
{
/**
* Your database connection
* @var PDO
*/
protected $db;
public function handle()
{
$breyta = new \Breyta\Migrations($this->db, '/path/to/migrations', function($class, ...$args) {
// return app()->make($class, $args);
// the closure is optional. default:
if ($class === \Breyta\AdapterInterface::class) {
return new \Breyta\BasicAdapter(...$args); // first arg = closure $executor
}
return new $class(...$args); // first arg = AdapterInterface $adapter
});
// register handler (optional)
/** @var \Breyta\CallbackProgress $callbackProgress */
$callbackProgress = $breyta->getProgress();
$callbackProgress->onStart([$this, 'start'])
->onBeforeMigration([$this, 'beginMigration'])
->onBeforeExecution([$this, 'beforeExecution'])
->onAfterExecution([$this, 'afterExecution'])
->onAfterMigration([$this, 'finishMigration'])
->onFinish([$this, 'finish']);
// alternative: implement \Breyta\ProgressInterface and register
// $breyta->setProgress($this);
$breyta->migrate();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.