1 | <?php |
||
12 | class Scanner |
||
13 | { |
||
14 | const ERROR = 'error'; |
||
15 | const PASSED = 'passed'; |
||
16 | |||
17 | private $rules; |
||
18 | private $eventDispatcher; |
||
19 | |||
20 | private $responseRetriever; |
||
21 | |||
22 | private $status = 0; |
||
23 | |||
24 | public function __construct(array $rules, HttpAdapterInterface $client, Dispatcher $eventDispatcher, Retriever $responseRetriever) |
||
25 | { |
||
26 | $eventDispatcher->simpleNotify('Scanner.Init', array('rules' => $rules, 'httpClient' => $client, 'dispatcher' => $eventDispatcher)); |
||
27 | |||
28 | $this->rules = $rules; |
||
29 | $this->eventDispatcher = $eventDispatcher; |
||
30 | |||
31 | $this->responseRetriever = $responseRetriever; |
||
32 | |||
33 | $this->eventDispatcher->simpleNotify('Scanner.Init.ResponseRetriever', array('responseRetriever' => $this->responseRetriever)); |
||
34 | } |
||
35 | |||
36 | public function scan() |
||
37 | { |
||
38 | $this->eventDispatcher->simpleNotify('Scanner.Scan.Begin'); |
||
39 | |||
40 | while (($response = $this->responseRetriever->next()) && !$this->eventDispatcher->notifyUntil(new Event('Scanner.Scan.isStopped'))) { |
||
41 | |||
42 | // this is the url filter |
||
43 | if ($this->eventDispatcher->notifyUntil(new Event('Scanner.ProcessHtml.isFiltered', array('uri' => $response->getUri())))) { |
||
44 | continue; |
||
45 | } |
||
46 | |||
47 | $resultArray = $this->checkResponse($response); |
||
48 | |||
49 | $result = new Result($response->getUri(), |
||
50 | $resultArray['type'], |
||
51 | $response, |
||
52 | '', |
||
53 | $resultArray['time']); |
||
54 | |||
55 | if ($result->isFailure()) { |
||
56 | $result->setMessages($resultArray['messages']); |
||
57 | $this->status = 1; |
||
58 | } |
||
59 | |||
60 | $this->eventDispatcher->simpleNotify('Scanner.Scan.Validate', array('result' => $result)); |
||
61 | } |
||
62 | |||
63 | $this->eventDispatcher->simpleNotify('Scanner.Scan.Finish'); |
||
64 | } |
||
65 | |||
66 | public function getStatus() |
||
70 | |||
71 | private function checkResponse(Response $response) |
||
72 | { |
||
99 | } |
||
100 |