1. Go to this page and download the library: Download mb4it/conditionable 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/ */
class User {
public string $name = 'John';
public int $age = 25;
}
$user = new User();
$result = condition()
->context($user, 'u')
->where('u.name', 'John')
->where('u.age', '>=', 18)
->result();
// true
// или
$result = condition(['u' => $user])
->where('u.name', 'John')
->where('u.age', '>=', 18)
->result();
// true
use MB\Support\Conditionable\Traits\Conditionable;
class Product {
use Conditionable;
public float $price = 150.0;
public string $category = 'electronics';
}
$product = new Product();
// При использовании Trait классе
// Его алиас для контекста -> this
$result = $product->condition()
->where('this.price', '>', 100)
->where('this.category', 'electronics')
->result();
// true