1<?php
2
3namespace dokuwiki\plugin\extension;
4
5use dokuwiki\Remote\Response\ApiResponse;
6
7class ExtensionApiResponse extends ApiResponse
8{
9    protected Extension $extension;
10
11    /** @var string The type of this extension ("plugin" or "template") */
12    public $type;
13
14    /** @var string The id of this extension (templates are prefixed with "template") */
15    public $id;
16
17    /** @var string The base name of this extension */
18    public $base;
19
20    /** @var string The display name of this extension */
21    public $name;
22
23    /** @var string The installed version/date of this extension */
24    public $version;
25
26    /** @var string The author of this extension */
27    public $author;
28
29    /** @var string The description of this extension */
30    public $description;
31
32    /** @var bool Whether this extension is installed */
33    public $isInstalled;
34
35    /** @var bool Whether this extension is enabled */
36    public $isEnabled;
37
38    /** @var bool Whether an update is available */
39    public $updateAvailable;
40
41    /** @var bool Whether this extension is bundled with DokuWiki */
42    public $isBundled;
43
44    /** @var bool Whether this extension is under git control */
45    public $isGitControlled;
46
47    /** @var string[] Notices for this extension */
48    public $notices;
49
50    /** @var string Documentation URL for this extension */
51    public $url;
52
53    /** @var string[] The component types this plugin provides */
54    public $componentTypes;
55
56    /** @var string The last available remote update date */
57    public $lastUpdate;
58
59    /** @var string The download URL for this extension */
60    public string $downloadURL;
61
62    /**
63     * Constructor
64     *
65     * @param Extension $extension The extension to create the response for
66     */
67    public function __construct(Extension $extension)
68    {
69        $this->extension = $extension;
70        $this->type = $extension->getType();
71        $this->id = $extension->getId();
72        $this->base = $extension->getBase();
73        $this->name = $extension->getDisplayName();
74        $this->version = $extension->getInstalledVersion();
75        $this->author = $extension->getAuthor();
76        $this->description = $extension->getDescription();
77        $this->isInstalled = $extension->isInstalled();
78        $this->isEnabled = $extension->isEnabled();
79        $this->updateAvailable = $extension->isUpdateAvailable();
80        $this->isBundled = $extension->isBundled();
81        $this->isGitControlled = $extension->isGitControlled();
82        $this->componentTypes = $extension->getComponentTypes();
83        $this->lastUpdate = $extension->getLastUpdate();
84        $this->url = $extension->getURL();
85        $this->downloadURL = $extension->getDownloadURL();
86
87        // Add notices
88        $this->notices = array_merge(...array_values(Notice::list($extension)));
89    }
90
91    /** @inheritdoc */
92    public function __toString()
93    {
94        return $this->extension->getId();
95    }
96}
97