Merge pull request #18794 from eileenmcnaughton/need_less
[civicrm-core.git] / CRM / Extension / Container / Static.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * @package CRM
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
15 */
16
17 /**
18 * An extension container is a locally-accessible source tree which can be
19 * scanned for extensions.
20 */
21 class CRM_Extension_Container_Static implements CRM_Extension_Container_Interface {
22
23 /**
24 * @param array $exts
25 * Array(string $key => array $spec) List of extensions.
26 */
27 public function __construct($exts) {
28 $this->exts = $exts;
29 }
30
31 /**
32 * @inheritDoc
33 */
34 public function checkRequirements() {
35 return [];
36 }
37
38 /**
39 * @inheritDoc
40 */
41 public function getName() {
42 return $this->name;
43 }
44
45 /**
46 * @inheritDoc
47 */
48 public function getKeys() {
49 return array_keys($this->exts);
50 }
51
52 /**
53 * @inheritDoc
54 */
55 public function getPath($key) {
56 $e = $this->getExt($key);
57 return $e['path'];
58 }
59
60 /**
61 * @inheritDoc
62 */
63 public function getResUrl($key) {
64 $e = $this->getExt($key);
65 return $e['resUrl'];
66 }
67
68 /**
69 * @inheritDoc
70 */
71 public function refresh() {
72 }
73
74 /**
75 * @param string $key
76 * Extension name.
77 *
78 * @throws CRM_Extension_Exception_MissingException
79 */
80 protected function getExt($key) {
81 if (isset($this->exts[$key])) {
82 return $this->exts[$key];
83 }
84 else {
85 throw new CRM_Extension_Exception_MissingException("Missing extension: $key");
86 }
87 }
88
89 }