1. Go to this page and download the library: Download ap-lib/conditions 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/ */
ap-lib / conditions example snippets
/**
* @return int[]
*/
function getConsents(int $phone): array;
use AP\Conditions\All;
use AP\Conditions\Limit;
use AP\Conditions\LeastOne;
enum Protein
{
case Chicken;
case Beef;
case Salmon;
case Tofu;
case Shrimp;
}
enum Greens
{
case Lettuce;
case Spinach;
case Kale;
case Arugula;
case Cabbage;
case Romaine;
}
enum Vegetables
{
case Tomatoes;
case Cucumbers;
case Carrots;
case BellPeppers;
case Onions;
case Radishes;
}
enum Toppings
{
case Croutons;
case Seeds;
case Nuts;
case Cheese;
case Avocado;
case Olives;
case Garlic;
}
enum Dressing
{
case Ranch;
case Vinaigrette;
case Caesar;
case Balsamic;
case HoneyMustard;
case YogurtDressing;
case OliveOil;
case SourCream;
}
enum Extras
{
case Quinoa;
case Pasta;
case Rice;
case Potatoes;
case Breadsticks;
}
$salad = new All([
new Limit(Protein::cases(), min: 0, max: 1),
new Limit(Greens::cases(), min: 0, max: 2),
new Limit(Vegetables::cases(), min: 1, max: 2),
new Limit(Dressing::cases(), min: 1, max: 1),
new Limit(Toppings::cases(), min: 0, max: 2),
new Limit(Extras::cases(), min: 0, max: 2),
]);
//////////////////////////////////////////////////////////////////////////
// good choice
$this->assertTrue(
$salad->check([
Protein::Chicken,
Greens::Spinach,
Vegetables::Tomatoes,
Toppings::Avocado,
Dressing::OliveOil,
Extras::Rice,
])
);
//////////////////////////////////////////////////////////////////////////
// I'm not hungry, russian summer greens salad, please
$this->assertTrue(
$salad->check([
Vegetables::Tomatoes,
Vegetables::Cucumbers,
Toppings::Garlic,
Dressing::SourCream,
])
);
//////////////////////////////////////////////////////////////////////////
// double Vegetables
$this->assertTrue(
$salad->check([
Protein::Chicken,
Greens::Spinach,
Vegetables::Tomatoes, Vegetables::Cucumbers,
Toppings::Avocado,
Dressing::OliveOil,
Extras::Rice,
])
);
//////////////////////////////////////////////////////////////////////////
// vegetarian option with no protein
$this->assertTrue(
$salad->check([
Greens::Spinach,
Vegetables::Tomatoes, Vegetables::Cucumbers,
Toppings::Avocado,
Dressing::Caesar,
Extras::Rice,
])
);
//////////////////////////////////////////////////////////////////////////
// oh, no. too much Protein
$this->assertFalse(
$salad->check([
Protein::Chicken, Protein::Salmon,
Greens::Spinach,
Vegetables::Tomatoes,
Toppings::Avocado,
Dressing::Caesar,
Extras::Rice,
])
);
//////////////////////////////////////////////////////////////////////////
// unfortunately, double protein no available either
$this->assertFalse(
$salad->check([
Protein::Chicken, Protein::Chicken,
Greens::Spinach,
Vegetables::Tomatoes,
Toppings::Avocado,
Dressing::Caesar,
Extras::Rice,
])
);
//////////////////////////////////////////////////////////////////////////
// btw, if you need, you can ignore dups
$options_with_ignore_dups = new All([
new Limit(Protein::cases(), min: 0, max: 1, ignore_duplicates: true),
new Limit(Greens::cases(), min: 0, max: 2, ignore_duplicates: true),
new Limit(Vegetables::cases(), min: 1, max: 2, ignore_duplicates: true),
new LeastOne(Dressing::cases()),
new Limit(Toppings::cases(), min: 0, max: 2, ignore_duplicates: true),
new Limit(Extras::cases(), min: 0, max: 2, ignore_duplicates: true),
]);
// now it works
$this->assertTrue(
$options_with_ignore_dups->check([
Protein::Chicken, Protein::Chicken, Protein::Chicken,
Greens::Spinach, Greens::Spinach, Greens::Spinach,
Vegetables::Tomatoes, Vegetables::Tomatoes, Vegetables::Tomatoes,
Toppings::Avocado, Toppings::Avocado, Toppings::Avocado,
Dressing::Caesar, Dressing::Caesar, Dressing::Caesar,
Extras::Rice, Extras::Rice, Extras::Rice,
])
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.