PHP code example of bogdanbeniaminb / simpledep

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

    

bogdanbeniaminb / simpledep example snippets



$foo1 = (new Package('foo', '1.0.0'))->addLink('re', 'bar', '>=1.0.1');
$bar1 = (new Package('bar', '1.0.0'))->addLink('k('conflict', 'bee', '>=1.0.0')
  ->addLink('replace', 'wow', '>=1.0.0');
$boo2 = (new Package('boo', '1.0.7'))
  ->addLink('conflict', 'bee', '>=1.0.0')
  ->addLink('replace', 'wow', '>=1.0.0');
$baz1 = new Package('baz', '1.0.0');
$baz2 = new Package('baz', '1.0.1');

$pool = (new Pool())
  ->addPackage($foo1)
  ->addPackage($bar1)
  ->addPackage($boo1)
  ->addPackage($boo2)
  ->addPackage($baz1)
  ->addPackage($foo2)
  ->addPackage($bar2)
  ->addPackage($baz2);

$requests = (new RequestsCollection())
  ->install('foo', '>=1.0.0')
  ->update('boo')
  ->uninstall('bee');

$installed = [
  'boo' => [
    'version' => '1.0.0',
  ],
  'bee' => [
    'version' => '1.0.0',
  ],
];

$solver = new Solver($pool, $requests, $installed);
$solution = $solver->solve();
// print_r($solution);

// Convert the solution to an array of arrays.
$solutionArray = array_map(
  fn(Operation $operation) => $operation->toArray(),
  $solution
);
echo (json_encode($solutionArray, JSON_PRETTY_PRINT));