1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once __DIR__ . "/vendor/autoload.php"; |
4
|
|
|
|
5
|
|
|
use Cornford\Logical\LogicalFactory; |
6
|
|
|
|
7
|
|
|
class Person |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var integer |
11
|
|
|
*/ |
12
|
|
|
protected $age; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $email; |
18
|
|
|
protected $forename; |
19
|
|
|
protected $surname; |
20
|
|
|
protected $title; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array $array |
24
|
|
|
*/ |
25
|
|
|
public function __construct(array $array = []) |
26
|
|
|
{ |
27
|
|
|
if (isset($array['title'])) $this->title = $array['title']; |
28
|
|
|
if (isset($array['forename'])) $this->forename = $array['forename']; |
29
|
|
|
if (isset($array['surname'])) $this->surname = $array['surname']; |
30
|
|
|
if (isset($array['email'])) $this->email = $array['email']; |
31
|
|
|
if (isset($array['age'])) $this->age = $array['age']; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $name |
36
|
|
|
* @param string|integer $value |
37
|
|
|
*/ |
38
|
|
|
public function __set($name, $value) |
39
|
|
|
{ |
40
|
|
|
if (property_exists($this, $name)) { |
41
|
|
|
$this->$name = $value; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $name |
47
|
|
|
* |
48
|
|
|
* @return string|integer|void |
49
|
|
|
*/ |
50
|
|
|
public function __get($name) |
51
|
|
|
{ |
52
|
|
|
if (property_exists($this, $name)) { |
53
|
|
|
return $this->$name; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$people = []; |
59
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'Tom', 'surname' => 'Guy', 'age' => 17, 'email' => '[email protected]']); |
60
|
|
|
$people[] = new Person(['title' => 'Mrs', 'forename' => 'Holly', 'surname' => 'Berry', 'age' => 28, 'email' => '[email protected]']); |
61
|
|
|
$people[] = new Person(['title' => 'Miss', 'forename' => 'Hannah', 'surname' => 'Pots', 'age' => 22, 'email' => '[email protected]']); |
62
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'David', 'surname' => 'Summers', 'age' => 24, 'email' => '[email protected]']); |
63
|
|
|
$people[] = new Person(['title' => 'Dr', 'forename' => 'Paul', 'surname' => 'Sky', 'age' => 18, 'email' => '[email protected]']); |
64
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'Steve', 'surname' => 'Smith', 'age' => 27, 'email' => '[email protected]']); |
65
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'Philip', 'surname' => 'Comms', 'age' => 29, 'email' => '[email protected]']); |
66
|
|
|
|
67
|
|
|
$logicStatement = 'where("forename").equals("Tom").OR.where("age").between(18, 21).OR.where("email").contains(".co.uk").AND.where("forename").equals("Holly")'; |
68
|
|
|
$logicalFactory = new LogicalFactory(); |
69
|
|
|
$logical = $logicalFactory->build($people, $logicStatement); |
70
|
|
|
$logical->execute(); |
71
|
|
|
$results = $logical->getResults(); |
72
|
|
|
|
73
|
|
|
var_dump($results); |
|
|
|
|
74
|
|
|
|