Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diviner/atomizer/DivinerArticleAtomizer.php
12262 views
1
<?php
2
3
final class DivinerArticleAtomizer extends DivinerAtomizer {
4
5
protected function executeAtomize($file_name, $file_data) {
6
$atom = $this->newAtom(DivinerAtom::TYPE_ARTICLE)
7
->setLine(1)
8
->setLength(count(explode("\n", $file_data)))
9
->setLanguage('human');
10
11
$block = "/**\n".str_replace("\n", "\n * ", $file_data)."\n */";
12
$atom->setDocblockRaw($block);
13
14
$meta = $atom->getDocblockMeta();
15
16
$title = idx($meta, 'title');
17
if (!strlen($title)) {
18
$title = pht('Untitled Article "%s"', basename($file_name));
19
$atom->addWarning(pht('Article has no %s!', '@title'));
20
$atom->setDocblockMetaValue('title', $title);
21
}
22
23
// If the article has no `@name`, use the filename after stripping any
24
// extension.
25
$name = idx($meta, 'name');
26
if (!$name) {
27
$name = basename($file_name);
28
$name = preg_replace('/\\.[^.]+$/', '', $name);
29
}
30
$atom->setName($name);
31
32
return array($atom);
33
}
34
35
}
36
37