PHP code example of krak / static-seed

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

    

krak / static-seed example snippets




use Krak\StaticSeed;

const SEED_DIR = __DIR__ . '/path/to/seed/dir';

/** Setup the export tables */
function export(StaticSeed\Export $export) {
    $export->export([
        new StaticSeed\Table('colors', 'tuple'),
        new StaticSeed\Table('color_sets', 'struct'),
        StaticSeed\Table::createJoin('color_sets_colors', 'color_set_id', [
            'color_set_id' => ['table' => 'color_sets', 'field' => 'slug'],
            'color_id' => ['table' => 'colors', 'field' => 'slug'],
        ])
    ], SEED_DIR);
}

function import(StaticSeed\Import $import) {
    $import->import(SEED_DIR);
}

function usage($argv) {
    printf("usage: %s <export|import>\n", $argv[0]);
    return 1;
}

function main($argv) {
    if (count($argv) <= 1) {
        exit(usage($argv));
    }

    $conn = myDoctrineDbalConnection();

    if ($argv[1] == 'export') {
        export(new StaticSeed\Export($conn));
    } else if ($argv[1] == 'import') {
        import(new StaticSeed\Import($conn));
    } else {
        exit(usage($argv));
    }
}

main($argv);

    Krak\StaticSeed\Bridge\Symfony\StaticSeedBundle::class => ['all' => true],