1. Go to this page and download the library: Download stellarwp/schema 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/ */
stellarwp / schema example snippets
use Boom\Shakalaka\StellarWP\Schema\Config;
// You'll need a Dependency Injection Container that is compatible with https://github.com/lucatume/di52.
use Boom\Shakalaka\lucatume\DI52\Container;
// You'll need to use the StellarWP\DB library for database operations.
use Boom\Shakalaka\StellarWP\DB\DB;
$container = new Boom\Shakalaka\lucatume\DI52\Container();
Config::set_container( $container );
Config::set_db( DB::class );
namespace Boom\Shakalaka\Tables;
use Boom\Shakalaka\StellarWP\Schema\Tables\Contracts\Table;
use Boom\Shakalaka\StellarWP\Schema\Tables\Table_Schema;
use Boom\Shakalaka\StellarWP\Schema\Collections\Column_Collection;
use Boom\Shakalaka\StellarWP\Schema\Columns\ID;
use Boom\Shakalaka\StellarWP\Schema\Columns\String_Column;
use Boom\Shakalaka\StellarWP\Schema\Columns\Column_Types;
class Sandwiches extends Table {
/**
* {@inheritdoc}
*/
const SCHEMA_VERSION = '1.0.0';
/**
* {@inheritdoc}
*/
protected static $base_table_name = 'sandwiches';
/**
* {@inheritdoc}
*/
protected static $group = 'boom';
/**
* {@inheritdoc}
*/
protected static $schema_slug = 'boom-sandwiches';
/**
* {@inheritdoc}
*/
public static function get_schema_history(): array {
$table_name = static::table_name( true );
return [
'1.0.0' => function() use ( $table_name ) {
$columns = new Column_Collection();
// Define an auto-incrementing ID column
$columns[] = ( new ID( 'id' ) )
->set_length( 11 )
->set_type( Column_Types::INT )
->set_auto_increment( true );
// Define a varchar column for the name
$columns[] = ( new String_Column( 'name' ) )
->set_type( Column_Types::VARCHAR )
->set_length( 50 );
return new Table_Schema( $table_name, $columns );
},
];
}
}
namespace Boom\Shakalaka;
use Boom\Shakalaka\StellarWP\Schema\Register;
use Boom\Shakalaka\Tables\Sandwiches;
add_action( 'plugins_loaded', static function() {
Register::table( Sandwiches::class );
} );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.