-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReqFactory.php
More file actions
69 lines (51 loc) · 1.31 KB
/
Copy pathReqFactory.php
File metadata and controls
69 lines (51 loc) · 1.31 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class ReqFactory {
public $multi;
public $exe;
public $objects;
public function __construct($args=null, $multi=1, $exe=0) {
if($args) { $this->args = $args;}
$this->multi = $multi;
$this->exe = $exe;
}
public function make($args,$filter='all',$type='objects') {
$chosenObjects = $this->choose($filter, $type);
$req = array();
foreach($chosenObjects as $k) {
$a = $this->$type[$k];
$className = isset($a['class'])?$a['class']:$k;
$constructor = 'make'.$k;
if(method_exists($this,$constructor)) {
$reqs[$k] = $this->$constructor($args);
} else {
$reflector = new ReflectionClass($className);
$reqs[$k] =(object) $reflector->newInstanceArgs($args);
}
}
return $this->exe?$this->exe($reqs):$reqs;
}
// Intersects $objects array with ReqFactory::$type array
// Returns chosen $keys.
protected function choose($filter,$type='objects') {
if($filter == 'all') {
$s = array_keys($this->$type);
} else {
if(!is_array($filter))
$filter = array($filter);
$s = array_intersect(array_keys($this->$type), $filter);
}
return $s;
}
protected function exe($objects) {
if($this->multi) {
$c = new CurlBase;
$c->addArr($objects);
$c->perform();
return $c->requests;
} else {
CurlExec::sendArr($objects);
return $objects;
}
}
}
?>