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'])) { |
28
|
|
|
$this->title = $array['title']; |
29
|
|
|
} |
30
|
|
|
if (isset($array['forename'])) { |
31
|
|
|
$this->forename = $array['forename']; |
32
|
|
|
} |
33
|
|
|
if (isset($array['surname'])) { |
34
|
|
|
$this->surname = $array['surname']; |
35
|
|
|
} |
36
|
|
|
if (isset($array['email'])) { |
37
|
|
|
$this->email = $array['email']; |
38
|
|
|
} |
39
|
|
|
if (isset($array['age'])) { |
40
|
|
|
$this->age = $array['age']; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $name |
46
|
|
|
* @param string|integer $value |
47
|
|
|
*/ |
48
|
|
|
public function __set($name, $value) |
49
|
|
|
{ |
50
|
|
|
if (property_exists($this, $name)) { |
51
|
|
|
$this->$name = $value; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $name |
57
|
|
|
* |
58
|
|
|
* @return string|integer|void |
59
|
|
|
*/ |
60
|
|
|
public function __get($name) |
61
|
|
|
{ |
62
|
|
|
if (property_exists($this, $name)) { |
63
|
|
|
return $this->$name; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$people = []; |
69
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'Tom', 'surname' => 'Guy', 'age' => 17, 'email' => '[email protected]']); |
70
|
|
|
$people[] = new Person(['title' => 'Mrs', 'forename' => 'Holly', 'surname' => 'Berry', 'age' => 28, 'email' => '[email protected]']); |
71
|
|
|
$people[] = new Person(['title' => 'Miss', 'forename' => 'Hannah', 'surname' => 'Pots', 'age' => 22, 'email' => '[email protected]']); |
72
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'David', 'surname' => 'Summers', 'age' => 24, 'email' => '[email protected]']); |
73
|
|
|
$people[] = new Person(['title' => 'Dr', 'forename' => 'Paul', 'surname' => 'Sky', 'age' => 18, 'email' => '[email protected]']); |
74
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'Steve', 'surname' => 'Smith', 'age' => 27, 'email' => '[email protected]']); |
75
|
|
|
$people[] = new Person(['title' => 'Mr', 'forename' => 'Philip', 'surname' => 'Comms', 'age' => 29, 'email' => '[email protected]']); |
76
|
|
|
|
77
|
|
|
$logicStatement = 'where("forename").equals("Tom").OR.where("age").between(18, 21).OR.where("email").contains(".co.uk").AND.where("forename").equals("Holly")'; |
78
|
|
|
$logicalFactory = new LogicalFactory(); |
79
|
|
|
$logical = $logicalFactory->build($people, $logicStatement); |
80
|
|
|
$logical->execute(); |
81
|
|
|
$results = $logical->getResults(); |
82
|
|
|
|
83
|
|
|
var_dump($results); |
|
|
|
|
84
|
|
|
|