PHP code example of php-tui / cassowary

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

    

php-tui / cassowary example snippets



PhpTui\Cassowary\AddConstraintaintError;
use PhpTui\Cassowary\Constraint;
use PhpTui\Cassowary\RelationalOperator;
use PhpTui\Cassowary\Solver;
use PhpTui\Cassowary\Strength;
use PhpTui\Cassowary\Variable;

$ax1 = Variable::new();
$ax2 = Variable::new();
$bx1 = Variable::new();
$bx2 = Variable::new();
$y1 = Variable::new();
$y2 = Variable::new();

$s = Solver::new();
$s->addConstraints([
    Constraint::equalTo($ax1, 0.0, Strength::REQUIRED),
    Constraint::greaterThanOrEqualTo($ax2, $ax1, Strength::REQUIRED),
    Constraint::greaterThanOrEqualTo($ax2, $ax1->add(10.0), Strength::WEAK),
    Constraint::equalTo($bx1, $ax2, Strength::REQUIRED),
    Constraint::equalTo($bx2, 30.0, Strength::REQUIRED),
    Constraint::equalTo($y1, 0.0, Strength::REQUIRED),
    Constraint::equalTo($y2, 3.0, Strength::REQUIRED),
]);
$changes = $s->fetchChanges();
var_dump($changes->getValue($ax2)); // 10
var_dump($changes->getValue($bx1);  // 10
var_dump($changes->getValue($bx2)); // 30
var_dump($changes->getValue($y2));  // 3