PHP code example of derptest / phpmachinist

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

    

derptest / phpmachinist example snippets


    
    use DerpTest\Machinist\Machinist;
    use DerpTest\Machinist\Store\SqlStore;
    
    // This store will be referenced by the name "default"
    Machinist::store(SqlStore::fromPdo(new \PDO('sqlite::memory:')));
    
    // This store will be referenced by the name "non-default"
    Machinist::instance()->addStore(
        SqlStore::fromPdo(new \PDO('sqlite::memory:')),
        'non-default'
    );
    

    
    
    use DerpTest\Machinist\Machinist;
    use DerpTest\Machinist\Store\SqlStore;
    use DerpTest\Machinist\Blueprint;
    
    // Register the default data store
    Machinist::store(SqlStore::fromPdo(new \PDO('sqlite::memory:')));
    
    // Create a company blueprint using the "hard way".  This will be used in a relationship
    $company = new Blueprint(
        Machinist::instance(),
        'company',
        array(
            'streetAddress' => '123 Any Street',
            'city'          => 'Any Town',
            'state'         => 'NV',
            'zip'           => '89101'
        )
    );
    Machinist::instance()->addBlueprint('company', $company);
    
    // Create a standard user blueprint using the "easy way"
    Machinist::blueprint(
        'user',                                            // This is the blueprint name
        array(
            'role'    => 'USER',                           // The user will default to the STANDARD_USER role
            'active'  => true                              // The user will default to active
            'company' => Machinist::relationship($company) // Create relationship
        ),
        'user',                                            // The "user" table/collection to used.  Not 


// ...
 
Machinist::blueprint('user')->make(
    array(
        'username' => '[email protected]',
        'company' => array('name' => 'Pedro for Class President')
    )
);


Machinist::blueprint('user')->make(
    array(
        'username' => '[email protected]',
        'company' => array('name' => 'Pedro for Class President')
    )
);



// ...
 
$pedro = Machinist::blueprint('user')->findOne(array('username' => '[email protected]'));
echo ($pedro->company->name);