|
1
|
|
|
<?php |
|
2
|
|
|
namespace Finder\Spider\Registrator; |
|
3
|
|
|
|
|
4
|
|
|
use Finder\Contracts\Spider\TargetManager; |
|
5
|
|
|
|
|
6
|
|
|
use Stalker\Models\File; |
|
7
|
|
|
use Finder\Models\Digital\Internet\ComputerFile; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Run all script analysers and outputs their result. |
|
11
|
|
|
*/ |
|
12
|
|
|
class FileRegistrator extends TargetManager |
|
13
|
|
|
{ |
|
14
|
|
|
protected $file = false; |
|
15
|
|
|
protected $computerFile = false; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct($target, $parent = false) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct($target, $parent); |
|
20
|
|
|
|
|
21
|
|
|
$computer = $this->returnComputerFile(); |
|
|
|
|
|
|
22
|
|
|
// @todo Verificar se alterou o arquivo e gravar o novo arquivo |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
private function returnComputerFile() |
|
26
|
|
|
{ |
|
27
|
|
|
if ($this->computerFile) { |
|
28
|
|
|
return $this->computerFile; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if (!$this->computerFile = ComputerFile::where('location', $this->getLocation())->first()) { |
|
32
|
|
|
$this->computerFile = ComputerFile::create($this->getArray()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return $this->computerFile; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function returnFile() |
|
39
|
|
|
{ |
|
40
|
|
|
if ($this->file) { |
|
41
|
|
|
return $this->file; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$md5 = md5($this->getTarget()->getContents()); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
if ($this->file = File::where('location', $md5)->first()) { |
|
47
|
|
|
return $this->file; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $this->file = File::create( |
|
51
|
|
|
[ |
|
52
|
|
|
'location' => $md5, |
|
53
|
|
|
'name' => $this->getTarget()->getFilename() |
|
|
|
|
|
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function getArray() |
|
59
|
|
|
{ |
|
60
|
|
|
$target = $this->getTarget(); |
|
61
|
|
|
|
|
62
|
|
|
$array = [ |
|
63
|
|
|
'file_id' => $this->returnFile()->id, |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
if ($this->isStringPath) { |
|
67
|
|
|
return array_merge( |
|
68
|
|
|
$array, [ |
|
69
|
|
|
'location' => $target |
|
70
|
|
|
] |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return array_merge( |
|
75
|
|
|
$array, [ |
|
76
|
|
|
|
|
77
|
|
|
// dd($target); |
|
78
|
|
|
'location' => $this->getLocation(), |
|
79
|
|
|
'path' => self::clearUrl($target->getPath()), |
|
|
|
|
|
|
80
|
|
|
'filename' => self::clearUrl($target->getFilename()), |
|
|
|
|
|
|
81
|
|
|
'basename' => self::clearUrl($target->getBasename()), |
|
|
|
|
|
|
82
|
|
|
'pathname' => self::clearUrl($target->getPathname()), |
|
|
|
|
|
|
83
|
|
|
'extension' => self::clearUrl($target->getExtension()), |
|
|
|
|
|
|
84
|
|
|
'realPath' => self::clearUrl($target->getRealPath()), |
|
|
|
|
|
|
85
|
|
|
'aTime' => self::clearUrl($target->getATime()), |
|
|
|
|
|
|
86
|
|
|
'mTime' => self::clearUrl($target->getMTime()), |
|
|
|
|
|
|
87
|
|
|
'cTime' => self::clearUrl($target->getCTime()), |
|
|
|
|
|
|
88
|
|
|
'inode' => self::clearUrl($target->getInode()), |
|
|
|
|
|
|
89
|
|
|
'size' => self::clearUrl($target->getSize()), |
|
|
|
|
|
|
90
|
|
|
'perms' => self::clearUrl($target->getPerms()), |
|
|
|
|
|
|
91
|
|
|
'owner' => self::clearUrl($target->getOwner()), |
|
|
|
|
|
|
92
|
|
|
'group' => self::clearUrl($target->getGroup()), |
|
|
|
|
|
|
93
|
|
|
'type' => self::clearUrl($target->getType()), |
|
|
|
|
|
|
94
|
|
|
'writable' => $target->isWritable(), |
|
|
|
|
|
|
95
|
|
|
'readable' => $target->isReadable(), |
|
|
|
|
|
|
96
|
|
|
'executable' => $target->isExecutable(), |
|
|
|
|
|
|
97
|
|
|
// 'file' => $target->getFile(), |
|
98
|
|
|
// 'dir' => $target->getDir(), |
|
99
|
|
|
// 'link' => $target->getLink(), |
|
100
|
|
|
] |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.