1 | <?php namespace KamranAhmed\Smasher; |
||
12 | class Scanner |
||
13 | { |
||
14 | /** |
||
15 | * @var \KamranAhmed\Smasher\Path The path to operate on |
||
16 | */ |
||
17 | protected $path; |
||
18 | |||
19 | /** |
||
20 | * @var \KamranAhmed\Smasher\Contracts\ResponseContract Format for the response |
||
21 | */ |
||
22 | protected $response; |
||
23 | |||
24 | /** |
||
25 | * @var string Encoded response which will be returned |
||
26 | */ |
||
27 | protected $result; |
||
28 | |||
29 | /** |
||
30 | * Scanner constructor. |
||
31 | * |
||
32 | * @param \KamranAhmed\Smasher\Contracts\ResponseContract $response |
||
33 | */ |
||
34 | 8 | public function __construct(ResponseContract $response) |
|
40 | |||
41 | /** |
||
42 | * Scans the provided path and returns the encoded response. Also if |
||
43 | * resultPath is provided then the response will be stored in the resultPath |
||
44 | * |
||
45 | * @param $path The path to scan |
||
46 | * @param string $resultPath The path at which the resultant file will be created |
||
47 | * |
||
48 | * @throws \KamranAhmed\Smasher\Exceptions\InvalidPathException |
||
49 | * @throws \KamranAhmed\Smasher\Exceptions\UnreadablePathException |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | 3 | public function scan($path, $resultPath = '') |
|
71 | |||
72 | /** |
||
73 | * Probes the path and keeps populating the array with the results |
||
74 | * |
||
75 | * @param $path |
||
76 | * @param $parentItem |
||
77 | * @param string $fullPath |
||
78 | */ |
||
79 | 3 | protected function probe($path, &$parentItem, $fullPath = '') |
|
104 | |||
105 | /** |
||
106 | * Uses the source file to populate the path provided |
||
107 | * |
||
108 | * @param $outputDir The directory at which the content from file is to be populated |
||
109 | * @param $sourceFile The file to use for populating |
||
110 | */ |
||
111 | 1 | public function populate($outputDir, $sourceFile) |
|
115 | |||
116 | /** |
||
117 | * Uses the smashed/response file to recursively populate the path |
||
118 | * |
||
119 | * @param $outputDir Where to populate the output |
||
120 | * @param $sourceFile Path to the source file |
||
121 | * @param array $content The array to use instead of the source file |
||
122 | * @param bool $isRecursive Whether it is the recursive call |
||
123 | * |
||
124 | * @throws \KamranAhmed\Smasher\Exceptions\InvalidContentException |
||
125 | * @throws \KamranAhmed\Smasher\Exceptions\NoContentException |
||
126 | */ |
||
127 | 1 | private function populatePath($outputDir, $sourceFile, $content = [], $isRecursive = false) |
|
157 | |||
158 | /** |
||
159 | * Gets the scanned content from passed file |
||
160 | * |
||
161 | * @param $path |
||
162 | * |
||
163 | * @throws \KamranAhmed\Smasher\Exceptions\InvalidContentException |
||
164 | * @throws \KamranAhmed\Smasher\Exceptions\NoContentException |
||
165 | * @throws \KamranAhmed\Smasher\Exceptions\UnreadablePathException |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | 4 | protected function getScannedContent($path) |
|
188 | } |
||
189 |