aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins/extension/ExtensionApiResponse.php
blob: c684e770f3880fda4cddbe12796b9f22f943cd7f (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php

namespace dokuwiki\plugin\extension;

use dokuwiki\Remote\Response\ApiResponse;

class ExtensionApiResponse extends ApiResponse
{
    protected Extension $extension;

    /** @var string The type of this extension ("plugin" or "template") */
    public $type;

    /** @var string The id of this extension (templates are prefixed with "template") */
    public $id;

    /** @var string The base name of this extension */
    public $base;

    /** @var string The display name of this extension */
    public $name;

    /** @var string The installed version/date of this extension */
    public $version;

    /** @var string The author of this extension */
    public $author;

    /** @var string The description of this extension */
    public $description;

    /** @var bool Whether this extension is installed */
    public $isInstalled;

    /** @var bool Whether this extension is enabled */
    public $isEnabled;

    /** @var bool Whether an update is available */
    public $updateAvailable;

    /** @var bool Whether this extension is bundled with DokuWiki */
    public $isBundled;

    /** @var bool Whether this extension is under git control */
    public $isGitControlled;

    /** @var string[] Notices for this extension */
    public $notices;

    /** @var string Documentation URL for this extension */
    public $url;

    /** @var string[] The component types this plugin provides */
    public $componentTypes;

    /** @var string The last available remote update date */
    public $lastUpdate;

    /** @var string The download URL for this extension */
    public string $downloadURL;

    /**
     * Constructor
     *
     * @param Extension $extension The extension to create the response for
     */
    public function __construct(Extension $extension)
    {
        $this->extension = $extension;
        $this->type = $extension->getType();
        $this->id = $extension->getId();
        $this->base = $extension->getBase();
        $this->name = $extension->getDisplayName();
        $this->version = $extension->getInstalledVersion();
        $this->author = $extension->getAuthor();
        $this->description = $extension->getDescription();
        $this->isInstalled = $extension->isInstalled();
        $this->isEnabled = $extension->isEnabled();
        $this->updateAvailable = $extension->isUpdateAvailable();
        $this->isBundled = $extension->isBundled();
        $this->isGitControlled = $extension->isGitControlled();
        $this->componentTypes = $extension->getComponentTypes();
        $this->lastUpdate = $extension->getLastUpdate();
        $this->url = $extension->getURL();
        $this->downloadURL = $extension->getDownloadURL();

        // Add notices
        $this->notices = array_merge(...array_values(Notice::list($extension)));
    }

    /** @inheritdoc */
    public function __toString()
    {
        return $this->extension->getId();
    }
}