1 | <?php |
||
15 | class Laboratory |
||
16 | { |
||
17 | /** |
||
18 | * Collection of journals to report to. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $journals = []; |
||
23 | |||
24 | /** |
||
25 | * Register a collection of journals. |
||
26 | * |
||
27 | * @param array $journals |
||
28 | * |
||
29 | * @return $this |
||
30 | */ |
||
31 | 1 | public function setJournals(array $journals = []) |
|
37 | |||
38 | /** |
||
39 | * Register a new journal. |
||
40 | * |
||
41 | * @param \Scientist\Journals\Journal $journal |
||
42 | * |
||
43 | * @return $this |
||
44 | */ |
||
45 | 4 | public function addJournal(Journal $journal) |
|
51 | |||
52 | /** |
||
53 | * Retrieve registers journals. |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | 3 | public function getJournals() |
|
61 | |||
62 | /** |
||
63 | * Start a new experiment. |
||
64 | * |
||
65 | * @param string $name |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | 5 | public function experiment($name) |
|
73 | |||
74 | /** |
||
75 | * Run an experiment. |
||
76 | * |
||
77 | * @param \Scientist\Experiment $experiment |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 4 | public function runExperiment(Experiment $experiment) |
|
82 | { |
||
83 | 4 | if ($experiment->shouldRun()) { |
|
84 | 3 | $result = $this->getResult($experiment); |
|
85 | 3 | return $result->getControl()->getValue(); |
|
86 | } |
||
87 | |||
88 | 1 | return call_user_func_array( |
|
89 | 1 | $experiment->getControl(), |
|
90 | 1 | $experiment->getParams() |
|
91 | 1 | ); |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * Run an experiment and return the result. |
||
96 | * |
||
97 | * @param \Scientist\Experiment $experiment |
||
98 | * |
||
99 | * @return \Scientist\Report |
||
100 | */ |
||
101 | 4 | public function getResult(Experiment $experiment) |
|
108 | |||
109 | /** |
||
110 | * Report experiment result to registered journals. |
||
111 | * |
||
112 | * @param \Scientist\Experiment $experiment |
||
113 | * @param \Scientist\Report $result |
||
114 | * |
||
115 | * @return void |
||
116 | */ |
||
117 | 4 | protected function reportToJournals(Experiment $experiment, Report $result) |
|
123 | } |
||
124 |