-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathXml.php
More file actions
71 lines (63 loc) · 2.51 KB
/
Xml.php
File metadata and controls
71 lines (63 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php declare(strict_types = 1);
namespace TheSeer\phpDox\Generator\Engine;
use TheSeer\phpDox\BuildConfig;
use TheSeer\phpDox\Generator\AbstractEvent;
use TheSeer\phpDox\Generator\ClassStartEvent;
use TheSeer\phpDox\Generator\InterfaceStartEvent;
use TheSeer\phpDox\Generator\PHPDoxEndEvent;
use TheSeer\phpDox\Generator\TokenFileStartEvent;
use TheSeer\phpDox\Generator\TraitStartEvent;
class Xml extends AbstractEngine {
private $outputDir;
public function __construct(BuildConfig $config) {
$this->outputDir = $config->getOutputDirectory();
}
public function registerEventHandlers(EventHandlerRegistry $registry): void {
$registry->addHandler('phpdox.end', $this, 'handleIndex');
$registry->addHandler('class.start', $this, 'handle');
$registry->addHandler('trait.start', $this, 'handle');
$registry->addHandler('interface.start', $this, 'handle');
$registry->addHandler('token.file.start', $this, 'handleToken');
}
public function handle(AbstractEvent $event): void {
if ($event instanceof ClassStartEvent) {
$ctx = $event->getClass();
$path = 'classes';
} else {
if ($event instanceof TraitStartEvent) {
$ctx = $event->getTrait();
$path = 'traits';
} else {
if ($event instanceof InterfaceStartEvent) {
$ctx = $event->getInterface();
$path = 'interfaces';
} else {
throw new EngineException(
'Unexpected Event of type ' . \get_class($event),
XMLEngineException::UnexpectedType
);
}
}
}
$dom = $ctx->asDom();
$fname = sha1($dom->documentElement->getAttribute('full'));
$this->saveDomDocument(
$dom,
$this->outputDir . '/' . $path . '/' . $fname . '.xml'
);
}
public function handleIndex(PHPDoxEndEvent $event): void {
$dom = $event->getIndex()->asDom();
$this->saveDomDocument($dom, $this->outputDir . '/index.xml');
}
public function handleToken(TokenFileStartEvent $event): void {
$dom = $event->getTokenFile()->asDom();
$this->saveDomDocument(
$dom,
$this->outputDir . '/tokens/' . $dom->queryOne('//phpdox:file')->getAttribute('relative') . '.xml'
);
}
}
class XMLEngineException extends EngineException {
public const UnexpectedType = 2;
}