PHP code example of beaucal / beaucal-quick-union

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

    

beaucal / beaucal-quick-union example snippets


'modules' => [..., 'BeaucalQuickUnion', ...];

// in controller
$union = $this->getServiceLocator()->get('BeaucalQuickUnion');

$union->union('AAA', 'BBB');
echo $union->query('AAA'); // 'AAA' or 'BBB', random/set behaviour
echo $union->query('AAA') == $union->query('BBB'); // TRUE
echo $union->query('BBB') == $union->query('ZZZ'); // FALSE

$union->union(new Order\Directed('AAA', 'ZZZ'));
echo $union->query('AAA'); // 'ZZZ'
echo $union->query('BBB') == $union->query('ZZZ'); // TRUE

// change from random/set behaviour to known/directed
// or change via beaucalquickunion.global.php: option order_class
$union->getOptions()->setOrderClass('BeaucalQuickUnion\Order\Directed');
$union->union('PPP', 'QQQ');
echo $union->query('PPP'); // 'QQQ', no longer random

$adapterOptions = $serviceLocator->get('BeaucalQuickUnion\Options\DbAdapter');
$adapterOptions->setDbTable('beaucal_union_separate');
$gateway = new TableGateway(
$adapterOptions->getDbTable(), $serviceLocator->get($adapterOptions->getDbAdapterClass())
);
$adapter = new DbAdapter($gateway, $adapterOptions);

$union = new Union($adapter, $unionOptions);

// in beaucalquickunion.global.php
$union = [
    'adapter_class' => 'BeaucalQuickUnion\Adapter\Memory',
// ...
]
// in controller
$union = $this->getServiceLocator()->get('BeaucalQuickUnion');


// alternatively, a shortcut factory that doesn't