PHP code example of eghojansu / wai

1. Go to this page and download the library: Download eghojansu/wai 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/ */

    

eghojansu / wai example snippets




// index.php
// mark file and line to clean
Wai::mark(__FILE__, $lineStart = 6, $lineEnd = 62);

// configuration
$config = [
    // current version
    'version'      => '0.1.0',
    // used for saving installed version and schema, ensure this directory is writable
    'workingDir'   => 'tmp/',
    // schema directory that contains every schema that need to be installed
    // filename should be prefixed by ordered number
    'schemaDir'    => 'app/schema/',
    // argument for constructing PDO class
    'database'     => [
        // dsn, string, without database name
        'dsn'      => 'mysql:host=127.0.0.1',
        // username, string
        'username' => 'root',
        // password, string
        'password' => null,
        // options, array
        'options'  => [],
        // database name
        'dbname'   => 'test_wai',
        // drop db first
        'dropdb'   => false,
    ],
];
Wai::setup($config);

// check if current version is same as installed version
if (Wai::isNotInstalled()) {

	// not installed, install it
	// you can pass array of callback that will be execute
	// before and after database procedure called
    $dir = __DIR__;
    $callbacksBefore = [
        function() use ($dir) {
            chmod($dir.'/tmp', 0777);
        },
        function() {
            // other statements to do
        },
    ];
    $callbacksAfter = [
        function() {
            // other statements to do
        },
    ];
    Wai::handleInstallation($callbacksBefore, $callbacksAfter);
}

// catch result
// $result = Wai::result();

// or write result and exit
Wai::hold();