-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchDynamic.php
More file actions
44 lines (35 loc) · 912 Bytes
/
Copy pathSearchDynamic.php
File metadata and controls
44 lines (35 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace App\FactoryMethod;
class SearchDynamic
{
private $type;
private $types = [
'email' => Types\SearchEmail::class,
'ip' => Types\SearchIp::class,
'name' => Types\SearchName::class,
];
public function search($search) : String
{
return $this->type->search($search);
}
public function searchAll($search) : String
{
$type = $this->getTypeSearch($search);
$this->setType($type);
return $this->search($search);
}
public function setType($type)
{
$class = $this->types[$type];
$this->type = new $class;
}
private function getTypeSearch($search) : String
{
if (filter_var($search, FILTER_VALIDATE_EMAIL)) {
return "email";
} elseif (filter_var($search, FILTER_VALIDATE_IP)) {
return "ip";
}
return 'name';
}
}