@@ -89,7 +89,7 @@ |
||
89 | 89 | * @return IEntry[] |
90 | 90 | */ |
91 | 91 | private function sortEntries(array $entries) { |
92 | - usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
92 | + usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
93 | 93 | return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
94 | 94 | }); |
95 | 95 | return $entries; |
@@ -32,90 +32,90 @@ |
||
32 | 32 | |
33 | 33 | class Manager { |
34 | 34 | |
35 | - /** @var ContactsStore */ |
|
36 | - private $store; |
|
35 | + /** @var ContactsStore */ |
|
36 | + private $store; |
|
37 | 37 | |
38 | - /** @var ActionProviderStore */ |
|
39 | - private $actionProviderStore; |
|
38 | + /** @var ActionProviderStore */ |
|
39 | + private $actionProviderStore; |
|
40 | 40 | |
41 | - /** @var IAppManager */ |
|
42 | - private $appManager; |
|
41 | + /** @var IAppManager */ |
|
42 | + private $appManager; |
|
43 | 43 | |
44 | - /** @var IConfig */ |
|
45 | - private $config; |
|
44 | + /** @var IConfig */ |
|
45 | + private $config; |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param ContactsStore $store |
|
49 | - * @param ActionProviderStore $actionProviderStore |
|
50 | - * @param IAppManager $appManager |
|
51 | - */ |
|
52 | - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
53 | - $this->store = $store; |
|
54 | - $this->actionProviderStore = $actionProviderStore; |
|
55 | - $this->appManager = $appManager; |
|
56 | - $this->config = $config; |
|
57 | - } |
|
47 | + /** |
|
48 | + * @param ContactsStore $store |
|
49 | + * @param ActionProviderStore $actionProviderStore |
|
50 | + * @param IAppManager $appManager |
|
51 | + */ |
|
52 | + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager, IConfig $config) { |
|
53 | + $this->store = $store; |
|
54 | + $this->actionProviderStore = $actionProviderStore; |
|
55 | + $this->appManager = $appManager; |
|
56 | + $this->config = $config; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param IUser $user |
|
61 | - * @param string $filter |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function getEntries(IUser $user, $filter) { |
|
65 | - $maxAutocompleteResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', 25); |
|
66 | - $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
67 | - $topEntries = []; |
|
68 | - if (strlen($filter) >= $minSearchStringLength) { |
|
69 | - $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
59 | + /** |
|
60 | + * @param IUser $user |
|
61 | + * @param string $filter |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function getEntries(IUser $user, $filter) { |
|
65 | + $maxAutocompleteResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', 25); |
|
66 | + $minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0); |
|
67 | + $topEntries = []; |
|
68 | + if (strlen($filter) >= $minSearchStringLength) { |
|
69 | + $entries = $this->store->getContacts($user, $filter, $maxAutocompleteResults); |
|
70 | 70 | |
71 | - $sortedEntries = $this->sortEntries($entries); |
|
72 | - $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
73 | - $this->processEntries($topEntries, $user); |
|
74 | - } |
|
71 | + $sortedEntries = $this->sortEntries($entries); |
|
72 | + $topEntries = array_slice($sortedEntries, 0, $maxAutocompleteResults); |
|
73 | + $this->processEntries($topEntries, $user); |
|
74 | + } |
|
75 | 75 | |
76 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
77 | - return [ |
|
78 | - 'contacts' => $topEntries, |
|
79 | - 'contactsAppEnabled' => $contactsEnabled, |
|
80 | - ]; |
|
81 | - } |
|
76 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
77 | + return [ |
|
78 | + 'contacts' => $topEntries, |
|
79 | + 'contactsAppEnabled' => $contactsEnabled, |
|
80 | + ]; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param IUser $user |
|
85 | - * @param integer $shareType |
|
86 | - * @param string $shareWith |
|
87 | - * @return IEntry |
|
88 | - */ |
|
89 | - public function findOne(IUser $user, $shareType, $shareWith) { |
|
90 | - $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
91 | - if ($entry) { |
|
92 | - $this->processEntries([$entry], $user); |
|
93 | - } |
|
83 | + /** |
|
84 | + * @param IUser $user |
|
85 | + * @param integer $shareType |
|
86 | + * @param string $shareWith |
|
87 | + * @return IEntry |
|
88 | + */ |
|
89 | + public function findOne(IUser $user, $shareType, $shareWith) { |
|
90 | + $entry = $this->store->findOne($user, $shareType, $shareWith); |
|
91 | + if ($entry) { |
|
92 | + $this->processEntries([$entry], $user); |
|
93 | + } |
|
94 | 94 | |
95 | - return $entry; |
|
96 | - } |
|
95 | + return $entry; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @param IEntry[] $entries |
|
100 | - * @return IEntry[] |
|
101 | - */ |
|
102 | - private function sortEntries(array $entries) { |
|
103 | - usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
104 | - return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
105 | - }); |
|
106 | - return $entries; |
|
107 | - } |
|
98 | + /** |
|
99 | + * @param IEntry[] $entries |
|
100 | + * @return IEntry[] |
|
101 | + */ |
|
102 | + private function sortEntries(array $entries) { |
|
103 | + usort($entries, function (IEntry $entryA, IEntry $entryB) { |
|
104 | + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
105 | + }); |
|
106 | + return $entries; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param IEntry[] $entries |
|
111 | - * @param IUser $user |
|
112 | - */ |
|
113 | - private function processEntries(array $entries, IUser $user) { |
|
114 | - $providers = $this->actionProviderStore->getProviders($user); |
|
115 | - foreach ($entries as $entry) { |
|
116 | - foreach ($providers as $provider) { |
|
117 | - $provider->process($entry); |
|
118 | - } |
|
119 | - } |
|
120 | - } |
|
109 | + /** |
|
110 | + * @param IEntry[] $entries |
|
111 | + * @param IUser $user |
|
112 | + */ |
|
113 | + private function processEntries(array $entries, IUser $user) { |
|
114 | + $providers = $this->actionProviderStore->getProviders($user); |
|
115 | + foreach ($entries as $entry) { |
|
116 | + foreach ($providers as $provider) { |
|
117 | + $provider->process($entry); |
|
118 | + } |
|
119 | + } |
|
120 | + } |
|
121 | 121 | } |
@@ -29,140 +29,140 @@ |
||
29 | 29 | |
30 | 30 | class Entry implements IEntry { |
31 | 31 | |
32 | - /** @var string|int|null */ |
|
33 | - private $id = null; |
|
34 | - |
|
35 | - /** @var string */ |
|
36 | - private $fullName = ''; |
|
37 | - |
|
38 | - /** @var string[] */ |
|
39 | - private $emailAddresses = []; |
|
40 | - |
|
41 | - /** @var string|null */ |
|
42 | - private $avatar; |
|
43 | - |
|
44 | - /** @var IAction[] */ |
|
45 | - private $actions = []; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $properties = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $id |
|
52 | - */ |
|
53 | - public function setId($id) { |
|
54 | - $this->id = $id; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $displayName |
|
59 | - */ |
|
60 | - public function setFullName($displayName) { |
|
61 | - $this->fullName = $displayName; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getFullName() { |
|
68 | - return $this->fullName; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $address |
|
73 | - */ |
|
74 | - public function addEMailAddress($address) { |
|
75 | - $this->emailAddresses[] = $address; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getEMailAddresses() { |
|
82 | - return $this->emailAddresses; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $avatar |
|
87 | - */ |
|
88 | - public function setAvatar($avatar) { |
|
89 | - $this->avatar = $avatar; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getAvatar() { |
|
96 | - return $this->avatar; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IAction $action |
|
101 | - */ |
|
102 | - public function addAction(IAction $action) { |
|
103 | - $this->actions[] = $action; |
|
104 | - $this->sortActions(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return IAction[] |
|
109 | - */ |
|
110 | - public function getActions() { |
|
111 | - return $this->actions; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * sort the actions by priority and name |
|
116 | - */ |
|
117 | - private function sortActions() { |
|
118 | - usort($this->actions, function (IAction $action1, IAction $action2) { |
|
119 | - $prio1 = $action1->getPriority(); |
|
120 | - $prio2 = $action2->getPriority(); |
|
121 | - |
|
122 | - if ($prio1 === $prio2) { |
|
123 | - // Ascending order for same priority |
|
124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | - } |
|
126 | - |
|
127 | - // Descending order when priority differs |
|
128 | - return $prio2 - $prio1; |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param array $contact key-value array containing additional properties |
|
134 | - */ |
|
135 | - public function setProperties(array $contact) { |
|
136 | - $this->properties = $contact; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getProperty($key) { |
|
144 | - if (!isset($this->properties[$key])) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - return $this->properties[$key]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function jsonSerialize() { |
|
154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | - $otherActions = array_map(function (IAction $action) { |
|
156 | - return $action->jsonSerialize(); |
|
157 | - }, array_slice($this->actions, 1)); |
|
158 | - |
|
159 | - return [ |
|
160 | - 'id' => $this->id, |
|
161 | - 'fullName' => $this->fullName, |
|
162 | - 'avatar' => $this->getAvatar(), |
|
163 | - 'topAction' => $topAction, |
|
164 | - 'actions' => $otherActions, |
|
165 | - 'lastMessage' => '', |
|
166 | - ]; |
|
167 | - } |
|
32 | + /** @var string|int|null */ |
|
33 | + private $id = null; |
|
34 | + |
|
35 | + /** @var string */ |
|
36 | + private $fullName = ''; |
|
37 | + |
|
38 | + /** @var string[] */ |
|
39 | + private $emailAddresses = []; |
|
40 | + |
|
41 | + /** @var string|null */ |
|
42 | + private $avatar; |
|
43 | + |
|
44 | + /** @var IAction[] */ |
|
45 | + private $actions = []; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $properties = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $id |
|
52 | + */ |
|
53 | + public function setId($id) { |
|
54 | + $this->id = $id; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $displayName |
|
59 | + */ |
|
60 | + public function setFullName($displayName) { |
|
61 | + $this->fullName = $displayName; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getFullName() { |
|
68 | + return $this->fullName; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $address |
|
73 | + */ |
|
74 | + public function addEMailAddress($address) { |
|
75 | + $this->emailAddresses[] = $address; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getEMailAddresses() { |
|
82 | + return $this->emailAddresses; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $avatar |
|
87 | + */ |
|
88 | + public function setAvatar($avatar) { |
|
89 | + $this->avatar = $avatar; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getAvatar() { |
|
96 | + return $this->avatar; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IAction $action |
|
101 | + */ |
|
102 | + public function addAction(IAction $action) { |
|
103 | + $this->actions[] = $action; |
|
104 | + $this->sortActions(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return IAction[] |
|
109 | + */ |
|
110 | + public function getActions() { |
|
111 | + return $this->actions; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * sort the actions by priority and name |
|
116 | + */ |
|
117 | + private function sortActions() { |
|
118 | + usort($this->actions, function (IAction $action1, IAction $action2) { |
|
119 | + $prio1 = $action1->getPriority(); |
|
120 | + $prio2 = $action2->getPriority(); |
|
121 | + |
|
122 | + if ($prio1 === $prio2) { |
|
123 | + // Ascending order for same priority |
|
124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | + } |
|
126 | + |
|
127 | + // Descending order when priority differs |
|
128 | + return $prio2 - $prio1; |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param array $contact key-value array containing additional properties |
|
134 | + */ |
|
135 | + public function setProperties(array $contact) { |
|
136 | + $this->properties = $contact; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getProperty($key) { |
|
144 | + if (!isset($this->properties[$key])) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + return $this->properties[$key]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function jsonSerialize() { |
|
154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | + $otherActions = array_map(function (IAction $action) { |
|
156 | + return $action->jsonSerialize(); |
|
157 | + }, array_slice($this->actions, 1)); |
|
158 | + |
|
159 | + return [ |
|
160 | + 'id' => $this->id, |
|
161 | + 'fullName' => $this->fullName, |
|
162 | + 'avatar' => $this->getAvatar(), |
|
163 | + 'topAction' => $topAction, |
|
164 | + 'actions' => $otherActions, |
|
165 | + 'lastMessage' => '', |
|
166 | + ]; |
|
167 | + } |
|
168 | 168 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * sort the actions by priority and name |
116 | 116 | */ |
117 | 117 | private function sortActions() { |
118 | - usort($this->actions, function (IAction $action1, IAction $action2) { |
|
118 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | 119 | $prio1 = $action1->getPriority(); |
120 | 120 | $prio2 = $action2->getPriority(); |
121 | 121 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function jsonSerialize() { |
154 | 154 | $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
155 | - $otherActions = array_map(function (IAction $action) { |
|
155 | + $otherActions = array_map(function(IAction $action) { |
|
156 | 156 | return $action->jsonSerialize(); |
157 | 157 | }, array_slice($this->actions, 1)); |
158 | 158 |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return string[] |
96 | 96 | */ |
97 | 97 | private function getAppProviderClasses(IUser $user) { |
98 | - return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
98 | + return array_reduce($this->appManager->getEnabledAppsForUser($user), function($all, $appId) { |
|
99 | 99 | $info = $this->appManager->getAppInfo($appId); |
100 | 100 | |
101 | 101 | if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | return $all; |
104 | 104 | } |
105 | 105 | |
106 | - $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
106 | + $providers = array_reduce($info['contactsmenu'], function($all, $provider) { |
|
107 | 107 | return array_merge($all, [$provider]); |
108 | 108 | }, []); |
109 | 109 |
@@ -34,79 +34,79 @@ |
||
34 | 34 | |
35 | 35 | class ActionProviderStore { |
36 | 36 | |
37 | - /** @var IServerContainer */ |
|
38 | - private $serverContainer; |
|
37 | + /** @var IServerContainer */ |
|
38 | + private $serverContainer; |
|
39 | 39 | |
40 | - /** @var AppManager */ |
|
41 | - private $appManager; |
|
40 | + /** @var AppManager */ |
|
41 | + private $appManager; |
|
42 | 42 | |
43 | - /** @var ILogger */ |
|
44 | - private $logger; |
|
43 | + /** @var ILogger */ |
|
44 | + private $logger; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param IServerContainer $serverContainer |
|
48 | - * @param AppManager $appManager |
|
49 | - * @param ILogger $logger |
|
50 | - */ |
|
51 | - public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
52 | - $this->serverContainer = $serverContainer; |
|
53 | - $this->appManager = $appManager; |
|
54 | - $this->logger = $logger; |
|
55 | - } |
|
46 | + /** |
|
47 | + * @param IServerContainer $serverContainer |
|
48 | + * @param AppManager $appManager |
|
49 | + * @param ILogger $logger |
|
50 | + */ |
|
51 | + public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
52 | + $this->serverContainer = $serverContainer; |
|
53 | + $this->appManager = $appManager; |
|
54 | + $this->logger = $logger; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param IUser $user |
|
59 | - * @return IProvider[] |
|
60 | - * @throws Exception |
|
61 | - */ |
|
62 | - public function getProviders(IUser $user) { |
|
63 | - $appClasses = $this->getAppProviderClasses($user); |
|
64 | - $providerClasses = $this->getServerProviderClasses(); |
|
65 | - $allClasses = array_merge($providerClasses, $appClasses); |
|
66 | - $providers = []; |
|
57 | + /** |
|
58 | + * @param IUser $user |
|
59 | + * @return IProvider[] |
|
60 | + * @throws Exception |
|
61 | + */ |
|
62 | + public function getProviders(IUser $user) { |
|
63 | + $appClasses = $this->getAppProviderClasses($user); |
|
64 | + $providerClasses = $this->getServerProviderClasses(); |
|
65 | + $allClasses = array_merge($providerClasses, $appClasses); |
|
66 | + $providers = []; |
|
67 | 67 | |
68 | - foreach ($allClasses as $class) { |
|
69 | - try { |
|
70 | - $providers[] = $this->serverContainer->query($class); |
|
71 | - } catch (QueryException $ex) { |
|
72 | - $this->logger->logException($ex, [ |
|
73 | - 'message' => "Could not load contacts menu action provider $class", |
|
74 | - 'app' => 'core', |
|
75 | - ]); |
|
76 | - throw new Exception("Could not load contacts menu action provider"); |
|
77 | - } |
|
78 | - } |
|
68 | + foreach ($allClasses as $class) { |
|
69 | + try { |
|
70 | + $providers[] = $this->serverContainer->query($class); |
|
71 | + } catch (QueryException $ex) { |
|
72 | + $this->logger->logException($ex, [ |
|
73 | + 'message' => "Could not load contacts menu action provider $class", |
|
74 | + 'app' => 'core', |
|
75 | + ]); |
|
76 | + throw new Exception("Could not load contacts menu action provider"); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - return $providers; |
|
81 | - } |
|
80 | + return $providers; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return string[] |
|
85 | - */ |
|
86 | - private function getServerProviderClasses() { |
|
87 | - return [ |
|
88 | - EMailProvider::class, |
|
89 | - ]; |
|
90 | - } |
|
83 | + /** |
|
84 | + * @return string[] |
|
85 | + */ |
|
86 | + private function getServerProviderClasses() { |
|
87 | + return [ |
|
88 | + EMailProvider::class, |
|
89 | + ]; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param IUser $user |
|
94 | - * @return string[] |
|
95 | - */ |
|
96 | - private function getAppProviderClasses(IUser $user) { |
|
97 | - return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
98 | - $info = $this->appManager->getAppInfo($appId); |
|
92 | + /** |
|
93 | + * @param IUser $user |
|
94 | + * @return string[] |
|
95 | + */ |
|
96 | + private function getAppProviderClasses(IUser $user) { |
|
97 | + return array_reduce($this->appManager->getEnabledAppsForUser($user), function ($all, $appId) { |
|
98 | + $info = $this->appManager->getAppInfo($appId); |
|
99 | 99 | |
100 | - if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
101 | - // Nothing to add |
|
102 | - return $all; |
|
103 | - } |
|
100 | + if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
101 | + // Nothing to add |
|
102 | + return $all; |
|
103 | + } |
|
104 | 104 | |
105 | - $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
106 | - return array_merge($all, [$provider]); |
|
107 | - }, []); |
|
105 | + $providers = array_reduce($info['contactsmenu'], function ($all, $provider) { |
|
106 | + return array_merge($all, [$provider]); |
|
107 | + }, []); |
|
108 | 108 | |
109 | - return array_merge($all, $providers); |
|
110 | - }, []); |
|
111 | - } |
|
109 | + return array_merge($all, $providers); |
|
110 | + }, []); |
|
111 | + } |
|
112 | 112 | } |
@@ -24,12 +24,12 @@ |
||
24 | 24 | namespace OC\BackgroundJob\Legacy; |
25 | 25 | |
26 | 26 | class QueuedJob extends \OC\BackgroundJob\QueuedJob { |
27 | - public function run($argument) { |
|
28 | - $class = $argument['klass']; |
|
29 | - $method = $argument['method']; |
|
30 | - $parameters = $argument['parameters']; |
|
31 | - if (is_callable([$class, $method])) { |
|
32 | - call_user_func([$class, $method], $parameters); |
|
33 | - } |
|
34 | - } |
|
27 | + public function run($argument) { |
|
28 | + $class = $argument['klass']; |
|
29 | + $method = $argument['method']; |
|
30 | + $parameters = $argument['parameters']; |
|
31 | + if (is_callable([$class, $method])) { |
|
32 | + call_user_func([$class, $method], $parameters); |
|
33 | + } |
|
34 | + } |
|
35 | 35 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param callable $callback |
36 | 36 | */ |
37 | 37 | public function listen($scope, $method, callable $callback) { |
38 | - $eventName = $scope . '::' . $method; |
|
38 | + $eventName = $scope.'::'.$method; |
|
39 | 39 | if (!isset($this->listeners[$eventName])) { |
40 | 40 | $this->listeners[$eventName] = []; |
41 | 41 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $names = []; |
54 | 54 | $allNames = array_keys($this->listeners); |
55 | 55 | if ($scope and $method) { |
56 | - $name = $scope . '::' . $method; |
|
56 | + $name = $scope.'::'.$method; |
|
57 | 57 | if (isset($this->listeners[$name])) { |
58 | 58 | $names[] = $name; |
59 | 59 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param array $arguments optional |
94 | 94 | */ |
95 | 95 | protected function emit($scope, $method, array $arguments = []) { |
96 | - $eventName = $scope . '::' . $method; |
|
96 | + $eventName = $scope.'::'.$method; |
|
97 | 97 | if (isset($this->listeners[$eventName])) { |
98 | 98 | foreach ($this->listeners[$eventName] as $callback) { |
99 | 99 | call_user_func_array($callback, $arguments); |
@@ -25,80 +25,80 @@ |
||
25 | 25 | |
26 | 26 | trait EmitterTrait { |
27 | 27 | |
28 | - /** |
|
29 | - * @var callable[][] $listeners |
|
30 | - */ |
|
31 | - protected $listeners = []; |
|
28 | + /** |
|
29 | + * @var callable[][] $listeners |
|
30 | + */ |
|
31 | + protected $listeners = []; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param string $scope |
|
35 | - * @param string $method |
|
36 | - * @param callable $callback |
|
37 | - */ |
|
38 | - public function listen($scope, $method, callable $callback) { |
|
39 | - $eventName = $scope . '::' . $method; |
|
40 | - if (!isset($this->listeners[$eventName])) { |
|
41 | - $this->listeners[$eventName] = []; |
|
42 | - } |
|
43 | - if (array_search($callback, $this->listeners[$eventName], true) === false) { |
|
44 | - $this->listeners[$eventName][] = $callback; |
|
45 | - } |
|
46 | - } |
|
33 | + /** |
|
34 | + * @param string $scope |
|
35 | + * @param string $method |
|
36 | + * @param callable $callback |
|
37 | + */ |
|
38 | + public function listen($scope, $method, callable $callback) { |
|
39 | + $eventName = $scope . '::' . $method; |
|
40 | + if (!isset($this->listeners[$eventName])) { |
|
41 | + $this->listeners[$eventName] = []; |
|
42 | + } |
|
43 | + if (array_search($callback, $this->listeners[$eventName], true) === false) { |
|
44 | + $this->listeners[$eventName][] = $callback; |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $scope optional |
|
50 | - * @param string $method optional |
|
51 | - * @param callable $callback optional |
|
52 | - */ |
|
53 | - public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
54 | - $names = []; |
|
55 | - $allNames = array_keys($this->listeners); |
|
56 | - if ($scope and $method) { |
|
57 | - $name = $scope . '::' . $method; |
|
58 | - if (isset($this->listeners[$name])) { |
|
59 | - $names[] = $name; |
|
60 | - } |
|
61 | - } elseif ($scope) { |
|
62 | - foreach ($allNames as $name) { |
|
63 | - $parts = explode('::', $name, 2); |
|
64 | - if ($parts[0] == $scope) { |
|
65 | - $names[] = $name; |
|
66 | - } |
|
67 | - } |
|
68 | - } elseif ($method) { |
|
69 | - foreach ($allNames as $name) { |
|
70 | - $parts = explode('::', $name, 2); |
|
71 | - if ($parts[1] == $method) { |
|
72 | - $names[] = $name; |
|
73 | - } |
|
74 | - } |
|
75 | - } else { |
|
76 | - $names = $allNames; |
|
77 | - } |
|
48 | + /** |
|
49 | + * @param string $scope optional |
|
50 | + * @param string $method optional |
|
51 | + * @param callable $callback optional |
|
52 | + */ |
|
53 | + public function removeListener($scope = null, $method = null, callable $callback = null) { |
|
54 | + $names = []; |
|
55 | + $allNames = array_keys($this->listeners); |
|
56 | + if ($scope and $method) { |
|
57 | + $name = $scope . '::' . $method; |
|
58 | + if (isset($this->listeners[$name])) { |
|
59 | + $names[] = $name; |
|
60 | + } |
|
61 | + } elseif ($scope) { |
|
62 | + foreach ($allNames as $name) { |
|
63 | + $parts = explode('::', $name, 2); |
|
64 | + if ($parts[0] == $scope) { |
|
65 | + $names[] = $name; |
|
66 | + } |
|
67 | + } |
|
68 | + } elseif ($method) { |
|
69 | + foreach ($allNames as $name) { |
|
70 | + $parts = explode('::', $name, 2); |
|
71 | + if ($parts[1] == $method) { |
|
72 | + $names[] = $name; |
|
73 | + } |
|
74 | + } |
|
75 | + } else { |
|
76 | + $names = $allNames; |
|
77 | + } |
|
78 | 78 | |
79 | - foreach ($names as $name) { |
|
80 | - if ($callback) { |
|
81 | - $index = array_search($callback, $this->listeners[$name], true); |
|
82 | - if ($index !== false) { |
|
83 | - unset($this->listeners[$name][$index]); |
|
84 | - } |
|
85 | - } else { |
|
86 | - $this->listeners[$name] = []; |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
79 | + foreach ($names as $name) { |
|
80 | + if ($callback) { |
|
81 | + $index = array_search($callback, $this->listeners[$name], true); |
|
82 | + if ($index !== false) { |
|
83 | + unset($this->listeners[$name][$index]); |
|
84 | + } |
|
85 | + } else { |
|
86 | + $this->listeners[$name] = []; |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $scope |
|
93 | - * @param string $method |
|
94 | - * @param array $arguments optional |
|
95 | - */ |
|
96 | - protected function emit($scope, $method, array $arguments = []) { |
|
97 | - $eventName = $scope . '::' . $method; |
|
98 | - if (isset($this->listeners[$eventName])) { |
|
99 | - foreach ($this->listeners[$eventName] as $callback) { |
|
100 | - call_user_func_array($callback, $arguments); |
|
101 | - } |
|
102 | - } |
|
103 | - } |
|
91 | + /** |
|
92 | + * @param string $scope |
|
93 | + * @param string $method |
|
94 | + * @param array $arguments optional |
|
95 | + */ |
|
96 | + protected function emit($scope, $method, array $arguments = []) { |
|
97 | + $eventName = $scope . '::' . $method; |
|
98 | + if (isset($this->listeners[$eventName])) { |
|
99 | + foreach ($this->listeners[$eventName] as $callback) { |
|
100 | + call_user_func_array($callback, $arguments); |
|
101 | + } |
|
102 | + } |
|
103 | + } |
|
104 | 104 | } |
@@ -31,35 +31,35 @@ |
||
31 | 31 | * @package OC\Hooks |
32 | 32 | */ |
33 | 33 | abstract class ForwardingEmitter extends BasicEmitter { |
34 | - /** |
|
35 | - * @var \OC\Hooks\Emitter[] array |
|
36 | - */ |
|
37 | - private $forwardEmitters = []; |
|
34 | + /** |
|
35 | + * @var \OC\Hooks\Emitter[] array |
|
36 | + */ |
|
37 | + private $forwardEmitters = []; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $scope |
|
41 | - * @param string $method |
|
42 | - * @param callable $callback |
|
43 | - */ |
|
44 | - public function listen($scope, $method, callable $callback) { |
|
45 | - parent::listen($scope, $method, $callback); |
|
46 | - foreach ($this->forwardEmitters as $emitter) { |
|
47 | - $emitter->listen($scope, $method, $callback); |
|
48 | - } |
|
49 | - } |
|
39 | + /** |
|
40 | + * @param string $scope |
|
41 | + * @param string $method |
|
42 | + * @param callable $callback |
|
43 | + */ |
|
44 | + public function listen($scope, $method, callable $callback) { |
|
45 | + parent::listen($scope, $method, $callback); |
|
46 | + foreach ($this->forwardEmitters as $emitter) { |
|
47 | + $emitter->listen($scope, $method, $callback); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param \OC\Hooks\Emitter $emitter |
|
53 | - */ |
|
54 | - protected function forward(Emitter $emitter) { |
|
55 | - $this->forwardEmitters[] = $emitter; |
|
51 | + /** |
|
52 | + * @param \OC\Hooks\Emitter $emitter |
|
53 | + */ |
|
54 | + protected function forward(Emitter $emitter) { |
|
55 | + $this->forwardEmitters[] = $emitter; |
|
56 | 56 | |
57 | - //forward all previously connected hooks |
|
58 | - foreach ($this->listeners as $key => $listeners) { |
|
59 | - list($scope, $method) = explode('::', $key, 2); |
|
60 | - foreach ($listeners as $listener) { |
|
61 | - $emitter->listen($scope, $method, $listener); |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
57 | + //forward all previously connected hooks |
|
58 | + foreach ($this->listeners as $key => $listeners) { |
|
59 | + list($scope, $method) = explode('::', $key, 2); |
|
60 | + foreach ($listeners as $listener) { |
|
61 | + $emitter->listen($scope, $method, $listener); |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | 65 | } |
@@ -24,15 +24,15 @@ |
||
24 | 24 | namespace OC\Hooks; |
25 | 25 | |
26 | 26 | abstract class LegacyEmitter extends BasicEmitter { |
27 | - /** |
|
28 | - * @param string $scope |
|
29 | - * @param string $method |
|
30 | - * @param array $arguments |
|
31 | - * |
|
32 | - * @suppress PhanAccessMethodProtected |
|
33 | - */ |
|
34 | - protected function emit($scope, $method, array $arguments = []) { |
|
35 | - \OC_Hook::emit($scope, $method, $arguments); |
|
36 | - parent::emit($scope, $method, $arguments); |
|
37 | - } |
|
27 | + /** |
|
28 | + * @param string $scope |
|
29 | + * @param string $method |
|
30 | + * @param array $arguments |
|
31 | + * |
|
32 | + * @suppress PhanAccessMethodProtected |
|
33 | + */ |
|
34 | + protected function emit($scope, $method, array $arguments = []) { |
|
35 | + \OC_Hook::emit($scope, $method, $arguments); |
|
36 | + parent::emit($scope, $method, $arguments); |
|
37 | + } |
|
38 | 38 | } |
@@ -26,37 +26,37 @@ |
||
26 | 26 | namespace OC\Template; |
27 | 27 | |
28 | 28 | class TemplateFileLocator { |
29 | - protected $dirs; |
|
30 | - private $path; |
|
29 | + protected $dirs; |
|
30 | + private $path; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param string[] $dirs |
|
34 | - */ |
|
35 | - public function __construct($dirs) { |
|
36 | - $this->dirs = $dirs; |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param string[] $dirs |
|
34 | + */ |
|
35 | + public function __construct($dirs) { |
|
36 | + $this->dirs = $dirs; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $template |
|
41 | - * @return string |
|
42 | - * @throws \Exception |
|
43 | - */ |
|
44 | - public function find($template) { |
|
45 | - if ($template === '') { |
|
46 | - throw new \InvalidArgumentException('Empty template name'); |
|
47 | - } |
|
39 | + /** |
|
40 | + * @param string $template |
|
41 | + * @return string |
|
42 | + * @throws \Exception |
|
43 | + */ |
|
44 | + public function find($template) { |
|
45 | + if ($template === '') { |
|
46 | + throw new \InvalidArgumentException('Empty template name'); |
|
47 | + } |
|
48 | 48 | |
49 | - foreach ($this->dirs as $dir) { |
|
50 | - $file = $dir.$template.'.php'; |
|
51 | - if (is_file($file)) { |
|
52 | - $this->path = $dir; |
|
53 | - return $file; |
|
54 | - } |
|
55 | - } |
|
56 | - throw new \Exception('template file not found: template:'.$template); |
|
57 | - } |
|
49 | + foreach ($this->dirs as $dir) { |
|
50 | + $file = $dir.$template.'.php'; |
|
51 | + if (is_file($file)) { |
|
52 | + $this->path = $dir; |
|
53 | + return $file; |
|
54 | + } |
|
55 | + } |
|
56 | + throw new \Exception('template file not found: template:'.$template); |
|
57 | + } |
|
58 | 58 | |
59 | - public function getPath() { |
|
60 | - return $this->path; |
|
61 | - } |
|
59 | + public function getPath() { |
|
60 | + return $this->path; |
|
61 | + } |
|
62 | 62 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $this->doFind($resource); |
76 | 76 | } catch (ResourceNotFoundException $e) { |
77 | 77 | $resourceApp = substr($resource, 0, strpos($resource, '/')); |
78 | - $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
78 | + $this->logger->debug('Could not find resource file "'.$e->getResourcePath().'"', ['app' => $resourceApp]); |
|
79 | 79 | } |
80 | 80 | } |
81 | 81 | if (!empty($this->theme)) { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $this->doFindTheme($resource); |
85 | 85 | } catch (ResourceNotFoundException $e) { |
86 | 86 | $resourceApp = substr($resource, 0, strpos($resource, '/')); |
87 | - $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
87 | + $this->logger->debug('Could not find resource file in theme "'.$e->getResourcePath().'"', ['app' => $resourceApp]); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | } |
159 | 159 | $this->resources[] = [$root, $webRoot, $file]; |
160 | 160 | |
161 | - if ($throw && !is_file($root . '/' . $file)) { |
|
161 | + if ($throw && !is_file($root.'/'.$file)) { |
|
162 | 162 | throw new ResourceNotFoundException($file, $webRoot); |
163 | 163 | } |
164 | 164 | } |
@@ -31,172 +31,172 @@ |
||
31 | 31 | namespace OC\Template; |
32 | 32 | |
33 | 33 | abstract class ResourceLocator { |
34 | - protected $theme; |
|
35 | - |
|
36 | - protected $mapping; |
|
37 | - protected $serverroot; |
|
38 | - protected $thirdpartyroot; |
|
39 | - protected $webroot; |
|
40 | - |
|
41 | - protected $resources = []; |
|
42 | - |
|
43 | - /** @var \OCP\ILogger */ |
|
44 | - protected $logger; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param \OCP\ILogger $logger |
|
48 | - * @param string $theme |
|
49 | - * @param array $core_map |
|
50 | - * @param array $party_map |
|
51 | - */ |
|
52 | - public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) { |
|
53 | - $this->logger = $logger; |
|
54 | - $this->theme = $theme; |
|
55 | - $this->mapping = $core_map + $party_map; |
|
56 | - $this->serverroot = key($core_map); |
|
57 | - $this->thirdpartyroot = key($party_map); |
|
58 | - $this->webroot = $this->mapping[$this->serverroot]; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param string $resource |
|
63 | - */ |
|
64 | - abstract public function doFind($resource); |
|
65 | - |
|
66 | - /** |
|
67 | - * @param string $resource |
|
68 | - */ |
|
69 | - abstract public function doFindTheme($resource); |
|
70 | - |
|
71 | - /** |
|
72 | - * Finds the resources and adds them to the list |
|
73 | - * |
|
74 | - * @param array $resources |
|
75 | - */ |
|
76 | - public function find($resources) { |
|
77 | - foreach ($resources as $resource) { |
|
78 | - try { |
|
79 | - $this->doFind($resource); |
|
80 | - } catch (ResourceNotFoundException $e) { |
|
81 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
82 | - $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
83 | - } |
|
84 | - } |
|
85 | - if (!empty($this->theme)) { |
|
86 | - foreach ($resources as $resource) { |
|
87 | - try { |
|
88 | - $this->doFindTheme($resource); |
|
89 | - } catch (ResourceNotFoundException $e) { |
|
90 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
91 | - $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * append the $file resource if exist at $root |
|
99 | - * |
|
100 | - * @param string $root path to check |
|
101 | - * @param string $file the filename |
|
102 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
103 | - * @return bool True if the resource was found, false otherwise |
|
104 | - */ |
|
105 | - protected function appendIfExist($root, $file, $webRoot = null) { |
|
106 | - if (is_file($root.'/'.$file)) { |
|
107 | - $this->append($root, $file, $webRoot, false); |
|
108 | - return true; |
|
109 | - } |
|
110 | - return false; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Attempt to find the webRoot |
|
115 | - * |
|
116 | - * traverse the potential web roots upwards in the path |
|
117 | - * |
|
118 | - * example: |
|
119 | - * - root: /srv/www/apps/myapp |
|
120 | - * - available mappings: ['/srv/www'] |
|
121 | - * |
|
122 | - * First we check if a mapping for /srv/www/apps/myapp is available, |
|
123 | - * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a |
|
124 | - * valid web root |
|
125 | - * |
|
126 | - * @param string $root |
|
127 | - * @return string|null The web root or null on failure |
|
128 | - */ |
|
129 | - protected function findWebRoot($root) { |
|
130 | - $webRoot = null; |
|
131 | - $tmpRoot = $root; |
|
132 | - |
|
133 | - while ($webRoot === null) { |
|
134 | - if (isset($this->mapping[$tmpRoot])) { |
|
135 | - $webRoot = $this->mapping[$tmpRoot]; |
|
136 | - break; |
|
137 | - } |
|
138 | - |
|
139 | - if ($tmpRoot === '/') { |
|
140 | - break; |
|
141 | - } |
|
142 | - |
|
143 | - $tmpRoot = dirname($tmpRoot); |
|
144 | - } |
|
145 | - |
|
146 | - if ($webRoot === null) { |
|
147 | - $realpath = realpath($root); |
|
148 | - |
|
149 | - if ($realpath && ($realpath !== $root)) { |
|
150 | - return $this->findWebRoot($realpath); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - return $webRoot; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * append the $file resource at $root |
|
159 | - * |
|
160 | - * @param string $root path to check |
|
161 | - * @param string $file the filename |
|
162 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
163 | - * @param bool $throw Throw an exception, when the route does not exist |
|
164 | - * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
165 | - */ |
|
166 | - protected function append($root, $file, $webRoot = null, $throw = true) { |
|
167 | - if (!is_string($root)) { |
|
168 | - if ($throw) { |
|
169 | - throw new ResourceNotFoundException($file, $webRoot); |
|
170 | - } |
|
171 | - return; |
|
172 | - } |
|
173 | - |
|
174 | - if (!$webRoot) { |
|
175 | - $webRoot = $this->findWebRoot($root); |
|
176 | - |
|
177 | - if ($webRoot === null) { |
|
178 | - $webRoot = ''; |
|
179 | - $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
180 | - 'app' => 'lib', |
|
181 | - 'root' => $root, |
|
182 | - 'file' => $file, |
|
183 | - 'webRoot' => $webRoot, |
|
184 | - 'throw' => $throw ? 'true' : 'false' |
|
185 | - ]); |
|
186 | - } |
|
187 | - } |
|
188 | - $this->resources[] = [$root, $webRoot, $file]; |
|
189 | - |
|
190 | - if ($throw && !is_file($root . '/' . $file)) { |
|
191 | - throw new ResourceNotFoundException($file, $webRoot); |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns the list of all resources that should be loaded |
|
197 | - * @return array |
|
198 | - */ |
|
199 | - public function getResources() { |
|
200 | - return $this->resources; |
|
201 | - } |
|
34 | + protected $theme; |
|
35 | + |
|
36 | + protected $mapping; |
|
37 | + protected $serverroot; |
|
38 | + protected $thirdpartyroot; |
|
39 | + protected $webroot; |
|
40 | + |
|
41 | + protected $resources = []; |
|
42 | + |
|
43 | + /** @var \OCP\ILogger */ |
|
44 | + protected $logger; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param \OCP\ILogger $logger |
|
48 | + * @param string $theme |
|
49 | + * @param array $core_map |
|
50 | + * @param array $party_map |
|
51 | + */ |
|
52 | + public function __construct(\OCP\ILogger $logger, $theme, $core_map, $party_map) { |
|
53 | + $this->logger = $logger; |
|
54 | + $this->theme = $theme; |
|
55 | + $this->mapping = $core_map + $party_map; |
|
56 | + $this->serverroot = key($core_map); |
|
57 | + $this->thirdpartyroot = key($party_map); |
|
58 | + $this->webroot = $this->mapping[$this->serverroot]; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param string $resource |
|
63 | + */ |
|
64 | + abstract public function doFind($resource); |
|
65 | + |
|
66 | + /** |
|
67 | + * @param string $resource |
|
68 | + */ |
|
69 | + abstract public function doFindTheme($resource); |
|
70 | + |
|
71 | + /** |
|
72 | + * Finds the resources and adds them to the list |
|
73 | + * |
|
74 | + * @param array $resources |
|
75 | + */ |
|
76 | + public function find($resources) { |
|
77 | + foreach ($resources as $resource) { |
|
78 | + try { |
|
79 | + $this->doFind($resource); |
|
80 | + } catch (ResourceNotFoundException $e) { |
|
81 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
82 | + $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
83 | + } |
|
84 | + } |
|
85 | + if (!empty($this->theme)) { |
|
86 | + foreach ($resources as $resource) { |
|
87 | + try { |
|
88 | + $this->doFindTheme($resource); |
|
89 | + } catch (ResourceNotFoundException $e) { |
|
90 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
91 | + $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * append the $file resource if exist at $root |
|
99 | + * |
|
100 | + * @param string $root path to check |
|
101 | + * @param string $file the filename |
|
102 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
103 | + * @return bool True if the resource was found, false otherwise |
|
104 | + */ |
|
105 | + protected function appendIfExist($root, $file, $webRoot = null) { |
|
106 | + if (is_file($root.'/'.$file)) { |
|
107 | + $this->append($root, $file, $webRoot, false); |
|
108 | + return true; |
|
109 | + } |
|
110 | + return false; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Attempt to find the webRoot |
|
115 | + * |
|
116 | + * traverse the potential web roots upwards in the path |
|
117 | + * |
|
118 | + * example: |
|
119 | + * - root: /srv/www/apps/myapp |
|
120 | + * - available mappings: ['/srv/www'] |
|
121 | + * |
|
122 | + * First we check if a mapping for /srv/www/apps/myapp is available, |
|
123 | + * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a |
|
124 | + * valid web root |
|
125 | + * |
|
126 | + * @param string $root |
|
127 | + * @return string|null The web root or null on failure |
|
128 | + */ |
|
129 | + protected function findWebRoot($root) { |
|
130 | + $webRoot = null; |
|
131 | + $tmpRoot = $root; |
|
132 | + |
|
133 | + while ($webRoot === null) { |
|
134 | + if (isset($this->mapping[$tmpRoot])) { |
|
135 | + $webRoot = $this->mapping[$tmpRoot]; |
|
136 | + break; |
|
137 | + } |
|
138 | + |
|
139 | + if ($tmpRoot === '/') { |
|
140 | + break; |
|
141 | + } |
|
142 | + |
|
143 | + $tmpRoot = dirname($tmpRoot); |
|
144 | + } |
|
145 | + |
|
146 | + if ($webRoot === null) { |
|
147 | + $realpath = realpath($root); |
|
148 | + |
|
149 | + if ($realpath && ($realpath !== $root)) { |
|
150 | + return $this->findWebRoot($realpath); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + return $webRoot; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * append the $file resource at $root |
|
159 | + * |
|
160 | + * @param string $root path to check |
|
161 | + * @param string $file the filename |
|
162 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
163 | + * @param bool $throw Throw an exception, when the route does not exist |
|
164 | + * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
165 | + */ |
|
166 | + protected function append($root, $file, $webRoot = null, $throw = true) { |
|
167 | + if (!is_string($root)) { |
|
168 | + if ($throw) { |
|
169 | + throw new ResourceNotFoundException($file, $webRoot); |
|
170 | + } |
|
171 | + return; |
|
172 | + } |
|
173 | + |
|
174 | + if (!$webRoot) { |
|
175 | + $webRoot = $this->findWebRoot($root); |
|
176 | + |
|
177 | + if ($webRoot === null) { |
|
178 | + $webRoot = ''; |
|
179 | + $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
180 | + 'app' => 'lib', |
|
181 | + 'root' => $root, |
|
182 | + 'file' => $file, |
|
183 | + 'webRoot' => $webRoot, |
|
184 | + 'throw' => $throw ? 'true' : 'false' |
|
185 | + ]); |
|
186 | + } |
|
187 | + } |
|
188 | + $this->resources[] = [$root, $webRoot, $file]; |
|
189 | + |
|
190 | + if ($throw && !is_file($root . '/' . $file)) { |
|
191 | + throw new ResourceNotFoundException($file, $webRoot); |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns the list of all resources that should be loaded |
|
197 | + * @return array |
|
198 | + */ |
|
199 | + public function getResources() { |
|
200 | + return $this->resources; |
|
201 | + } |
|
202 | 202 | } |