Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/conduit/FileInfoConduitAPIMethod.php
12241 views
1
<?php
2
3
final class FileInfoConduitAPIMethod extends FileConduitAPIMethod {
4
5
public function getAPIMethodName() {
6
return 'file.info';
7
}
8
9
public function getMethodDescription() {
10
return pht('Get information about a file.');
11
}
12
13
public function getMethodStatus() {
14
return self::METHOD_STATUS_FROZEN;
15
}
16
17
public function getMethodStatusDescription() {
18
return pht(
19
'This method is frozen and will eventually be deprecated. New code '.
20
'should use "file.search" instead.');
21
}
22
23
protected function defineParamTypes() {
24
return array(
25
'phid' => 'optional phid',
26
'id' => 'optional id',
27
);
28
}
29
30
protected function defineReturnType() {
31
return 'nonempty dict';
32
}
33
34
protected function defineErrorTypes() {
35
return array(
36
'ERR-NOT-FOUND' => pht('No such file exists.'),
37
);
38
}
39
40
protected function execute(ConduitAPIRequest $request) {
41
$phid = $request->getValue('phid');
42
$id = $request->getValue('id');
43
44
$query = id(new PhabricatorFileQuery())
45
->setViewer($request->getUser());
46
if ($id) {
47
$query->withIDs(array($id));
48
} else {
49
$query->withPHIDs(array($phid));
50
}
51
52
$file = $query->executeOne();
53
54
if (!$file) {
55
throw new ConduitException('ERR-NOT-FOUND');
56
}
57
58
$uri = $file->getInfoURI();
59
60
return array(
61
'id' => $file->getID(),
62
'phid' => $file->getPHID(),
63
'objectName' => 'F'.$file->getID(),
64
'name' => $file->getName(),
65
'mimeType' => $file->getMimeType(),
66
'byteSize' => $file->getByteSize(),
67
'authorPHID' => $file->getAuthorPHID(),
68
'dateCreated' => $file->getDateCreated(),
69
'dateModified' => $file->getDateModified(),
70
'uri' => PhabricatorEnv::getProductionURI($uri),
71
);
72
}
73
74
}
75
76