@@ -67,7 +67,7 @@ |
||
| 67 | 67 | * compared with \OC\Group\Backend::CREATE_GROUP etc. |
| 68 | 68 | */ |
| 69 | 69 | public function implementsActions($actions) { |
| 70 | - return (bool)($this->getSupportedActions() & $actions); |
|
| 70 | + return (bool) ($this->getSupportedActions() & $actions); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -29,107 +29,107 @@ |
||
| 29 | 29 | * Abstract base class for user management |
| 30 | 30 | */ |
| 31 | 31 | abstract class Backend implements \OCP\GroupInterface { |
| 32 | - /** |
|
| 33 | - * error code for functions not provided by the group backend |
|
| 34 | - */ |
|
| 35 | - public const NOT_IMPLEMENTED = -501; |
|
| 32 | + /** |
|
| 33 | + * error code for functions not provided by the group backend |
|
| 34 | + */ |
|
| 35 | + public const NOT_IMPLEMENTED = -501; |
|
| 36 | 36 | |
| 37 | - protected $possibleActions = [ |
|
| 38 | - self::CREATE_GROUP => 'createGroup', |
|
| 39 | - self::DELETE_GROUP => 'deleteGroup', |
|
| 40 | - self::ADD_TO_GROUP => 'addToGroup', |
|
| 41 | - self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
| 42 | - self::COUNT_USERS => 'countUsersInGroup', |
|
| 43 | - self::GROUP_DETAILS => 'getGroupDetails', |
|
| 44 | - self::IS_ADMIN => 'isAdmin', |
|
| 45 | - ]; |
|
| 37 | + protected $possibleActions = [ |
|
| 38 | + self::CREATE_GROUP => 'createGroup', |
|
| 39 | + self::DELETE_GROUP => 'deleteGroup', |
|
| 40 | + self::ADD_TO_GROUP => 'addToGroup', |
|
| 41 | + self::REMOVE_FROM_GOUP => 'removeFromGroup', |
|
| 42 | + self::COUNT_USERS => 'countUsersInGroup', |
|
| 43 | + self::GROUP_DETAILS => 'getGroupDetails', |
|
| 44 | + self::IS_ADMIN => 'isAdmin', |
|
| 45 | + ]; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get all supported actions |
|
| 49 | - * @return int bitwise-or'ed actions |
|
| 50 | - * |
|
| 51 | - * Returns the supported actions as int to be |
|
| 52 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 53 | - */ |
|
| 54 | - public function getSupportedActions() { |
|
| 55 | - $actions = 0; |
|
| 56 | - foreach ($this->possibleActions as $action => $methodName) { |
|
| 57 | - if (method_exists($this, $methodName)) { |
|
| 58 | - $actions |= $action; |
|
| 59 | - } |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * Get all supported actions |
|
| 49 | + * @return int bitwise-or'ed actions |
|
| 50 | + * |
|
| 51 | + * Returns the supported actions as int to be |
|
| 52 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 53 | + */ |
|
| 54 | + public function getSupportedActions() { |
|
| 55 | + $actions = 0; |
|
| 56 | + foreach ($this->possibleActions as $action => $methodName) { |
|
| 57 | + if (method_exists($this, $methodName)) { |
|
| 58 | + $actions |= $action; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return $actions; |
|
| 63 | - } |
|
| 62 | + return $actions; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Check if backend implements actions |
|
| 67 | - * @param int $actions bitwise-or'ed actions |
|
| 68 | - * @return bool |
|
| 69 | - * |
|
| 70 | - * Returns the supported actions as int to be |
|
| 71 | - * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 72 | - */ |
|
| 73 | - public function implementsActions($actions) { |
|
| 74 | - return (bool)($this->getSupportedActions() & $actions); |
|
| 75 | - } |
|
| 65 | + /** |
|
| 66 | + * Check if backend implements actions |
|
| 67 | + * @param int $actions bitwise-or'ed actions |
|
| 68 | + * @return bool |
|
| 69 | + * |
|
| 70 | + * Returns the supported actions as int to be |
|
| 71 | + * compared with \OC\Group\Backend::CREATE_GROUP etc. |
|
| 72 | + */ |
|
| 73 | + public function implementsActions($actions) { |
|
| 74 | + return (bool)($this->getSupportedActions() & $actions); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * is user in group? |
|
| 79 | - * @param string $uid uid of the user |
|
| 80 | - * @param string $gid gid of the group |
|
| 81 | - * @return bool |
|
| 82 | - * |
|
| 83 | - * Checks whether the user is member of a group or not. |
|
| 84 | - */ |
|
| 85 | - public function inGroup($uid, $gid) { |
|
| 86 | - return in_array($gid, $this->getUserGroups($uid)); |
|
| 87 | - } |
|
| 77 | + /** |
|
| 78 | + * is user in group? |
|
| 79 | + * @param string $uid uid of the user |
|
| 80 | + * @param string $gid gid of the group |
|
| 81 | + * @return bool |
|
| 82 | + * |
|
| 83 | + * Checks whether the user is member of a group or not. |
|
| 84 | + */ |
|
| 85 | + public function inGroup($uid, $gid) { |
|
| 86 | + return in_array($gid, $this->getUserGroups($uid)); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Get all groups a user belongs to |
|
| 91 | - * @param string $uid Name of the user |
|
| 92 | - * @return array an array of group names |
|
| 93 | - * |
|
| 94 | - * This function fetches all groups a user belongs to. It does not check |
|
| 95 | - * if the user exists at all. |
|
| 96 | - */ |
|
| 97 | - public function getUserGroups($uid) { |
|
| 98 | - return []; |
|
| 99 | - } |
|
| 89 | + /** |
|
| 90 | + * Get all groups a user belongs to |
|
| 91 | + * @param string $uid Name of the user |
|
| 92 | + * @return array an array of group names |
|
| 93 | + * |
|
| 94 | + * This function fetches all groups a user belongs to. It does not check |
|
| 95 | + * if the user exists at all. |
|
| 96 | + */ |
|
| 97 | + public function getUserGroups($uid) { |
|
| 98 | + return []; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * get a list of all groups |
|
| 103 | - * @param string $search |
|
| 104 | - * @param int $limit |
|
| 105 | - * @param int $offset |
|
| 106 | - * @return array an array of group names |
|
| 107 | - * |
|
| 108 | - * Returns a list with all groups |
|
| 109 | - */ |
|
| 101 | + /** |
|
| 102 | + * get a list of all groups |
|
| 103 | + * @param string $search |
|
| 104 | + * @param int $limit |
|
| 105 | + * @param int $offset |
|
| 106 | + * @return array an array of group names |
|
| 107 | + * |
|
| 108 | + * Returns a list with all groups |
|
| 109 | + */ |
|
| 110 | 110 | |
| 111 | - public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
| 112 | - return []; |
|
| 113 | - } |
|
| 111 | + public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
| 112 | + return []; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * check if a group exists |
|
| 117 | - * @param string $gid |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function groupExists($gid) { |
|
| 121 | - return in_array($gid, $this->getGroups($gid, 1)); |
|
| 122 | - } |
|
| 115 | + /** |
|
| 116 | + * check if a group exists |
|
| 117 | + * @param string $gid |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function groupExists($gid) { |
|
| 121 | + return in_array($gid, $this->getGroups($gid, 1)); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * get a list of all users in a group |
|
| 126 | - * @param string $gid |
|
| 127 | - * @param string $search |
|
| 128 | - * @param int $limit |
|
| 129 | - * @param int $offset |
|
| 130 | - * @return array an array of user ids |
|
| 131 | - */ |
|
| 132 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
| 133 | - return []; |
|
| 134 | - } |
|
| 124 | + /** |
|
| 125 | + * get a list of all users in a group |
|
| 126 | + * @param string $gid |
|
| 127 | + * @param string $search |
|
| 128 | + * @param int $limit |
|
| 129 | + * @param int $offset |
|
| 130 | + * @return array an array of user ids |
|
| 131 | + */ |
|
| 132 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
| 133 | + return []; |
|
| 134 | + } |
|
| 135 | 135 | } |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | // Check that all parameters from $event exist in $previousEvent |
| 135 | 135 | foreach ($params1 as $key => $parameter) { |
| 136 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 136 | + if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) { |
|
| 137 | 137 | if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
| 138 | 138 | $combined++; |
| 139 | - $params[$mergeParameter . $combined] = $parameter; |
|
| 139 | + $params[$mergeParameter.$combined] = $parameter; |
|
| 140 | 140 | } |
| 141 | 141 | continue; |
| 142 | 142 | } |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | // Check that all parameters from $previousEvent exist in $event |
| 153 | 153 | foreach ($params2 as $key => $parameter) { |
| 154 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 154 | + if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) { |
|
| 155 | 155 | if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
| 156 | 156 | $combined++; |
| 157 | - $params[$mergeParameter . $combined] = $parameter; |
|
| 157 | + $params[$mergeParameter.$combined] = $parameter; |
|
| 158 | 158 | } |
| 159 | 159 | continue; |
| 160 | 160 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
| 180 | 180 | foreach ($parameters as $key => $param) { |
| 181 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 181 | + if (preg_match('/^'.$mergeParameter.'(\d+)?$/', $key)) { |
|
| 182 | 182 | if ($param === $parameter) { |
| 183 | 183 | return true; |
| 184 | 184 | } |
@@ -196,30 +196,30 @@ discard block |
||
| 196 | 196 | protected function getExtendedSubject($subject, $parameter, $counter) { |
| 197 | 197 | switch ($counter) { |
| 198 | 198 | case 1: |
| 199 | - $replacement = '{' . $parameter . '1}'; |
|
| 199 | + $replacement = '{'.$parameter.'1}'; |
|
| 200 | 200 | break; |
| 201 | 201 | case 2: |
| 202 | 202 | $replacement = $this->l10n->t( |
| 203 | 203 | '%1$s and %2$s', |
| 204 | - ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 204 | + ['{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
| 205 | 205 | ); |
| 206 | 206 | break; |
| 207 | 207 | case 3: |
| 208 | 208 | $replacement = $this->l10n->t( |
| 209 | 209 | '%1$s, %2$s and %3$s', |
| 210 | - ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 210 | + ['{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
| 211 | 211 | ); |
| 212 | 212 | break; |
| 213 | 213 | case 4: |
| 214 | 214 | $replacement = $this->l10n->t( |
| 215 | 215 | '%1$s, %2$s, %3$s and %4$s', |
| 216 | - ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 216 | + ['{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
| 217 | 217 | ); |
| 218 | 218 | break; |
| 219 | 219 | case 5: |
| 220 | 220 | $replacement = $this->l10n->t( |
| 221 | 221 | '%1$s, %2$s, %3$s, %4$s and %5$s', |
| 222 | - ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 222 | + ['{'.$parameter.'5}', '{'.$parameter.'4}', '{'.$parameter.'3}', '{'.$parameter.'2}', '{'.$parameter.'1}'] |
|
| 223 | 223 | ); |
| 224 | 224 | break; |
| 225 | 225 | default: |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | return str_replace( |
| 230 | - '{' . $parameter . '}', |
|
| 230 | + '{'.$parameter.'}', |
|
| 231 | 231 | $replacement, |
| 232 | 232 | $subject |
| 233 | 233 | ); |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | protected function generateParsedSubject($subject, $parameters) { |
| 242 | 242 | $placeholders = $replacements = []; |
| 243 | 243 | foreach ($parameters as $placeholder => $parameter) { |
| 244 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 244 | + $placeholders[] = '{'.$placeholder.'}'; |
|
| 245 | 245 | if ($parameter['type'] === 'file') { |
| 246 | 246 | $replacements[] = trim($parameter['path'], '/'); |
| 247 | 247 | } elseif (isset($parameter['name'])) { |
@@ -29,231 +29,231 @@ |
||
| 29 | 29 | use OCP\IL10N; |
| 30 | 30 | |
| 31 | 31 | class EventMerger implements IEventMerger { |
| 32 | - /** @var IL10N */ |
|
| 33 | - protected $l10n; |
|
| 32 | + /** @var IL10N */ |
|
| 33 | + protected $l10n; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param IL10N $l10n |
|
| 37 | - */ |
|
| 38 | - public function __construct(IL10N $l10n) { |
|
| 39 | - $this->l10n = $l10n; |
|
| 40 | - } |
|
| 35 | + /** |
|
| 36 | + * @param IL10N $l10n |
|
| 37 | + */ |
|
| 38 | + public function __construct(IL10N $l10n) { |
|
| 39 | + $this->l10n = $l10n; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Combines two events when possible to have grouping: |
|
| 44 | - * |
|
| 45 | - * Example1: Two events with subject '{user} created {file}' and |
|
| 46 | - * $mergeParameter file with different file and same user will be merged |
|
| 47 | - * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
| 48 | - * will be set, if the events have been merged. |
|
| 49 | - * |
|
| 50 | - * Example2: Two events with subject '{user} created {file}' and |
|
| 51 | - * $mergeParameter file with same file and same user will be merged to |
|
| 52 | - * '{user} created {file1}' and the childEvent on the return will be set, if |
|
| 53 | - * the events have been merged. |
|
| 54 | - * |
|
| 55 | - * The following requirements have to be met, in order to be merged: |
|
| 56 | - * - Both events need to have the same `getApp()` |
|
| 57 | - * - Both events must not have a message `getMessage()` |
|
| 58 | - * - Both events need to have the same subject `getSubject()` |
|
| 59 | - * - Both events need to have the same object type `getObjectType()` |
|
| 60 | - * - The time difference between both events must not be bigger then 3 hours |
|
| 61 | - * - Only up to 5 events can be merged. |
|
| 62 | - * - All parameters apart from such starting with $mergeParameter must be |
|
| 63 | - * the same for both events. |
|
| 64 | - * |
|
| 65 | - * @param string $mergeParameter |
|
| 66 | - * @param IEvent $event |
|
| 67 | - * @param IEvent|null $previousEvent |
|
| 68 | - * @return IEvent |
|
| 69 | - */ |
|
| 70 | - public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
| 71 | - // No second event => can not combine |
|
| 72 | - if (!$previousEvent instanceof IEvent) { |
|
| 73 | - return $event; |
|
| 74 | - } |
|
| 42 | + /** |
|
| 43 | + * Combines two events when possible to have grouping: |
|
| 44 | + * |
|
| 45 | + * Example1: Two events with subject '{user} created {file}' and |
|
| 46 | + * $mergeParameter file with different file and same user will be merged |
|
| 47 | + * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
| 48 | + * will be set, if the events have been merged. |
|
| 49 | + * |
|
| 50 | + * Example2: Two events with subject '{user} created {file}' and |
|
| 51 | + * $mergeParameter file with same file and same user will be merged to |
|
| 52 | + * '{user} created {file1}' and the childEvent on the return will be set, if |
|
| 53 | + * the events have been merged. |
|
| 54 | + * |
|
| 55 | + * The following requirements have to be met, in order to be merged: |
|
| 56 | + * - Both events need to have the same `getApp()` |
|
| 57 | + * - Both events must not have a message `getMessage()` |
|
| 58 | + * - Both events need to have the same subject `getSubject()` |
|
| 59 | + * - Both events need to have the same object type `getObjectType()` |
|
| 60 | + * - The time difference between both events must not be bigger then 3 hours |
|
| 61 | + * - Only up to 5 events can be merged. |
|
| 62 | + * - All parameters apart from such starting with $mergeParameter must be |
|
| 63 | + * the same for both events. |
|
| 64 | + * |
|
| 65 | + * @param string $mergeParameter |
|
| 66 | + * @param IEvent $event |
|
| 67 | + * @param IEvent|null $previousEvent |
|
| 68 | + * @return IEvent |
|
| 69 | + */ |
|
| 70 | + public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
| 71 | + // No second event => can not combine |
|
| 72 | + if (!$previousEvent instanceof IEvent) { |
|
| 73 | + return $event; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Different app => can not combine |
|
| 77 | - if ($event->getApp() !== $previousEvent->getApp()) { |
|
| 78 | - return $event; |
|
| 79 | - } |
|
| 76 | + // Different app => can not combine |
|
| 77 | + if ($event->getApp() !== $previousEvent->getApp()) { |
|
| 78 | + return $event; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // Message is set => can not combine |
|
| 82 | - if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
| 83 | - return $event; |
|
| 84 | - } |
|
| 81 | + // Message is set => can not combine |
|
| 82 | + if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
| 83 | + return $event; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // Different subject => can not combine |
|
| 87 | - if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
| 88 | - return $event; |
|
| 89 | - } |
|
| 86 | + // Different subject => can not combine |
|
| 87 | + if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
| 88 | + return $event; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - // Different object type => can not combine |
|
| 92 | - if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
| 93 | - return $event; |
|
| 94 | - } |
|
| 91 | + // Different object type => can not combine |
|
| 92 | + if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
| 93 | + return $event; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - // More than 3 hours difference => can not combine |
|
| 97 | - if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
| 98 | - return $event; |
|
| 99 | - } |
|
| 96 | + // More than 3 hours difference => can not combine |
|
| 97 | + if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
| 98 | + return $event; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - // Other parameters are not the same => can not combine |
|
| 102 | - try { |
|
| 103 | - [$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
| 104 | - } catch (\UnexpectedValueException $e) { |
|
| 105 | - return $event; |
|
| 106 | - } |
|
| 101 | + // Other parameters are not the same => can not combine |
|
| 102 | + try { |
|
| 103 | + [$combined, $parameters] = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
| 104 | + } catch (\UnexpectedValueException $e) { |
|
| 105 | + return $event; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - try { |
|
| 109 | - $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
| 110 | - $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
| 108 | + try { |
|
| 109 | + $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
| 110 | + $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
| 111 | 111 | |
| 112 | - $event->setRichSubject($newSubject, $parameters) |
|
| 113 | - ->setParsedSubject($parsedSubject) |
|
| 114 | - ->setChildEvent($previousEvent) |
|
| 115 | - ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp())); |
|
| 116 | - } catch (\UnexpectedValueException $e) { |
|
| 117 | - return $event; |
|
| 118 | - } |
|
| 112 | + $event->setRichSubject($newSubject, $parameters) |
|
| 113 | + ->setParsedSubject($parsedSubject) |
|
| 114 | + ->setChildEvent($previousEvent) |
|
| 115 | + ->setTimestamp(max($event->getTimestamp(), $previousEvent->getTimestamp())); |
|
| 116 | + } catch (\UnexpectedValueException $e) { |
|
| 117 | + return $event; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - return $event; |
|
| 121 | - } |
|
| 120 | + return $event; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * @param string $mergeParameter |
|
| 125 | - * @param IEvent $event |
|
| 126 | - * @param IEvent $previousEvent |
|
| 127 | - * @return array |
|
| 128 | - * @throws \UnexpectedValueException |
|
| 129 | - */ |
|
| 130 | - protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
| 131 | - $params1 = $event->getRichSubjectParameters(); |
|
| 132 | - $params2 = $previousEvent->getRichSubjectParameters(); |
|
| 133 | - $params = []; |
|
| 123 | + /** |
|
| 124 | + * @param string $mergeParameter |
|
| 125 | + * @param IEvent $event |
|
| 126 | + * @param IEvent $previousEvent |
|
| 127 | + * @return array |
|
| 128 | + * @throws \UnexpectedValueException |
|
| 129 | + */ |
|
| 130 | + protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
| 131 | + $params1 = $event->getRichSubjectParameters(); |
|
| 132 | + $params2 = $previousEvent->getRichSubjectParameters(); |
|
| 133 | + $params = []; |
|
| 134 | 134 | |
| 135 | - $combined = 0; |
|
| 135 | + $combined = 0; |
|
| 136 | 136 | |
| 137 | - // Check that all parameters from $event exist in $previousEvent |
|
| 138 | - foreach ($params1 as $key => $parameter) { |
|
| 139 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 140 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 141 | - $combined++; |
|
| 142 | - $params[$mergeParameter . $combined] = $parameter; |
|
| 143 | - } |
|
| 144 | - continue; |
|
| 145 | - } |
|
| 137 | + // Check that all parameters from $event exist in $previousEvent |
|
| 138 | + foreach ($params1 as $key => $parameter) { |
|
| 139 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 140 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 141 | + $combined++; |
|
| 142 | + $params[$mergeParameter . $combined] = $parameter; |
|
| 143 | + } |
|
| 144 | + continue; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
| 148 | - // Parameter missing on $previousEvent or different => can not combine |
|
| 149 | - throw new \UnexpectedValueException(); |
|
| 150 | - } |
|
| 147 | + if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
| 148 | + // Parameter missing on $previousEvent or different => can not combine |
|
| 149 | + throw new \UnexpectedValueException(); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - $params[$key] = $parameter; |
|
| 153 | - } |
|
| 152 | + $params[$key] = $parameter; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - // Check that all parameters from $previousEvent exist in $event |
|
| 156 | - foreach ($params2 as $key => $parameter) { |
|
| 157 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 158 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 159 | - $combined++; |
|
| 160 | - $params[$mergeParameter . $combined] = $parameter; |
|
| 161 | - } |
|
| 162 | - continue; |
|
| 163 | - } |
|
| 155 | + // Check that all parameters from $previousEvent exist in $event |
|
| 156 | + foreach ($params2 as $key => $parameter) { |
|
| 157 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 158 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 159 | + $combined++; |
|
| 160 | + $params[$mergeParameter . $combined] = $parameter; |
|
| 161 | + } |
|
| 162 | + continue; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
| 166 | - // Parameter missing on $event or different => can not combine |
|
| 167 | - throw new \UnexpectedValueException(); |
|
| 168 | - } |
|
| 165 | + if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
| 166 | + // Parameter missing on $event or different => can not combine |
|
| 167 | + throw new \UnexpectedValueException(); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - $params[$key] = $parameter; |
|
| 171 | - } |
|
| 170 | + $params[$key] = $parameter; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - return [$combined, $params]; |
|
| 174 | - } |
|
| 173 | + return [$combined, $params]; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * @param array[] $parameters |
|
| 178 | - * @param string $mergeParameter |
|
| 179 | - * @param array $parameter |
|
| 180 | - * @return bool |
|
| 181 | - */ |
|
| 182 | - protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
| 183 | - foreach ($parameters as $key => $param) { |
|
| 184 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 185 | - if ($param === $parameter) { |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 176 | + /** |
|
| 177 | + * @param array[] $parameters |
|
| 178 | + * @param string $mergeParameter |
|
| 179 | + * @param array $parameter |
|
| 180 | + * @return bool |
|
| 181 | + */ |
|
| 182 | + protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
| 183 | + foreach ($parameters as $key => $param) { |
|
| 184 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 185 | + if ($param === $parameter) { |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * @param string $subject |
|
| 195 | - * @param string $parameter |
|
| 196 | - * @param int $counter |
|
| 197 | - * @return mixed |
|
| 198 | - */ |
|
| 199 | - protected function getExtendedSubject($subject, $parameter, $counter) { |
|
| 200 | - switch ($counter) { |
|
| 201 | - case 1: |
|
| 202 | - $replacement = '{' . $parameter . '1}'; |
|
| 203 | - break; |
|
| 204 | - case 2: |
|
| 205 | - $replacement = $this->l10n->t( |
|
| 206 | - '%1$s and %2$s', |
|
| 207 | - ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 208 | - ); |
|
| 209 | - break; |
|
| 210 | - case 3: |
|
| 211 | - $replacement = $this->l10n->t( |
|
| 212 | - '%1$s, %2$s and %3$s', |
|
| 213 | - ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 214 | - ); |
|
| 215 | - break; |
|
| 216 | - case 4: |
|
| 217 | - $replacement = $this->l10n->t( |
|
| 218 | - '%1$s, %2$s, %3$s and %4$s', |
|
| 219 | - ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 220 | - ); |
|
| 221 | - break; |
|
| 222 | - case 5: |
|
| 223 | - $replacement = $this->l10n->t( |
|
| 224 | - '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
| 225 | - ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 226 | - ); |
|
| 227 | - break; |
|
| 228 | - default: |
|
| 229 | - throw new \UnexpectedValueException(); |
|
| 230 | - } |
|
| 193 | + /** |
|
| 194 | + * @param string $subject |
|
| 195 | + * @param string $parameter |
|
| 196 | + * @param int $counter |
|
| 197 | + * @return mixed |
|
| 198 | + */ |
|
| 199 | + protected function getExtendedSubject($subject, $parameter, $counter) { |
|
| 200 | + switch ($counter) { |
|
| 201 | + case 1: |
|
| 202 | + $replacement = '{' . $parameter . '1}'; |
|
| 203 | + break; |
|
| 204 | + case 2: |
|
| 205 | + $replacement = $this->l10n->t( |
|
| 206 | + '%1$s and %2$s', |
|
| 207 | + ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 208 | + ); |
|
| 209 | + break; |
|
| 210 | + case 3: |
|
| 211 | + $replacement = $this->l10n->t( |
|
| 212 | + '%1$s, %2$s and %3$s', |
|
| 213 | + ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 214 | + ); |
|
| 215 | + break; |
|
| 216 | + case 4: |
|
| 217 | + $replacement = $this->l10n->t( |
|
| 218 | + '%1$s, %2$s, %3$s and %4$s', |
|
| 219 | + ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 220 | + ); |
|
| 221 | + break; |
|
| 222 | + case 5: |
|
| 223 | + $replacement = $this->l10n->t( |
|
| 224 | + '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
| 225 | + ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 226 | + ); |
|
| 227 | + break; |
|
| 228 | + default: |
|
| 229 | + throw new \UnexpectedValueException(); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - return str_replace( |
|
| 233 | - '{' . $parameter . '}', |
|
| 234 | - $replacement, |
|
| 235 | - $subject |
|
| 236 | - ); |
|
| 237 | - } |
|
| 232 | + return str_replace( |
|
| 233 | + '{' . $parameter . '}', |
|
| 234 | + $replacement, |
|
| 235 | + $subject |
|
| 236 | + ); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * @param string $subject |
|
| 241 | - * @param array[] $parameters |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - protected function generateParsedSubject($subject, $parameters) { |
|
| 245 | - $placeholders = $replacements = []; |
|
| 246 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 247 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 248 | - if ($parameter['type'] === 'file') { |
|
| 249 | - $replacements[] = trim($parameter['path'], '/'); |
|
| 250 | - } elseif (isset($parameter['name'])) { |
|
| 251 | - $replacements[] = $parameter['name']; |
|
| 252 | - } else { |
|
| 253 | - $replacements[] = $parameter['id']; |
|
| 254 | - } |
|
| 255 | - } |
|
| 239 | + /** |
|
| 240 | + * @param string $subject |
|
| 241 | + * @param array[] $parameters |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + protected function generateParsedSubject($subject, $parameters) { |
|
| 245 | + $placeholders = $replacements = []; |
|
| 246 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 247 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 248 | + if ($parameter['type'] === 'file') { |
|
| 249 | + $replacements[] = trim($parameter['path'], '/'); |
|
| 250 | + } elseif (isset($parameter['name'])) { |
|
| 251 | + $replacements[] = $parameter['name']; |
|
| 252 | + } else { |
|
| 253 | + $replacements[] = $parameter['id']; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - return str_replace($placeholders, $replacements, $subject); |
|
| 258 | - } |
|
| 257 | + return str_replace($placeholders, $replacements, $subject); |
|
| 258 | + } |
|
| 259 | 259 | } |
@@ -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 | } |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | |
| 66 | 66 | if ($app_path === false && $app_url === false) { |
| 67 | 67 | $this->logger->error('Could not find resource {resource} to load', [ |
| 68 | - 'resource' => $app . '/' . $style . '.css', |
|
| 68 | + 'resource' => $app.'/'.$style.'.css', |
|
| 69 | 69 | 'app' => 'cssresourceloader', |
| 70 | 70 | ]); |
| 71 | 71 | return; |
@@ -34,74 +34,74 @@ |
||
| 34 | 34 | use Psr\Log\LoggerInterface; |
| 35 | 35 | |
| 36 | 36 | class CSSResourceLocator extends ResourceLocator { |
| 37 | - public function __construct(LoggerInterface $logger) { |
|
| 38 | - parent::__construct($logger); |
|
| 39 | - } |
|
| 37 | + public function __construct(LoggerInterface $logger) { |
|
| 38 | + parent::__construct($logger); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $style |
|
| 43 | - */ |
|
| 44 | - public function doFind($style) { |
|
| 45 | - $app = substr($style, 0, strpos($style, '/')); |
|
| 46 | - if ($this->appendIfExist($this->serverroot, $style.'.css') |
|
| 47 | - || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') |
|
| 48 | - ) { |
|
| 49 | - return; |
|
| 50 | - } |
|
| 51 | - $style = substr($style, strpos($style, '/') + 1); |
|
| 52 | - $app_path = \OC_App::getAppPath($app); |
|
| 53 | - $app_url = \OC_App::getAppWebPath($app); |
|
| 41 | + /** |
|
| 42 | + * @param string $style |
|
| 43 | + */ |
|
| 44 | + public function doFind($style) { |
|
| 45 | + $app = substr($style, 0, strpos($style, '/')); |
|
| 46 | + if ($this->appendIfExist($this->serverroot, $style.'.css') |
|
| 47 | + || $this->appendIfExist($this->serverroot, 'core/'.$style.'.css') |
|
| 48 | + ) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | + $style = substr($style, strpos($style, '/') + 1); |
|
| 52 | + $app_path = \OC_App::getAppPath($app); |
|
| 53 | + $app_url = \OC_App::getAppWebPath($app); |
|
| 54 | 54 | |
| 55 | - if ($app_path === false && $app_url === false) { |
|
| 56 | - $this->logger->error('Could not find resource {resource} to load', [ |
|
| 57 | - 'resource' => $app . '/' . $style . '.css', |
|
| 58 | - 'app' => 'cssresourceloader', |
|
| 59 | - ]); |
|
| 60 | - return; |
|
| 61 | - } |
|
| 55 | + if ($app_path === false && $app_url === false) { |
|
| 56 | + $this->logger->error('Could not find resource {resource} to load', [ |
|
| 57 | + 'resource' => $app . '/' . $style . '.css', |
|
| 58 | + 'app' => 'cssresourceloader', |
|
| 59 | + ]); |
|
| 60 | + return; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - // Account for the possibility of having symlinks in app path. Doing |
|
| 64 | - // this here instead of above as an empty argument to realpath gets |
|
| 65 | - // turned into cwd. |
|
| 66 | - $app_path = realpath($app_path); |
|
| 63 | + // Account for the possibility of having symlinks in app path. Doing |
|
| 64 | + // this here instead of above as an empty argument to realpath gets |
|
| 65 | + // turned into cwd. |
|
| 66 | + $app_path = realpath($app_path); |
|
| 67 | 67 | |
| 68 | - $this->append($app_path, $style.'.css', $app_url); |
|
| 69 | - } |
|
| 68 | + $this->append($app_path, $style.'.css', $app_url); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $style |
|
| 73 | - */ |
|
| 74 | - public function doFindTheme($style) { |
|
| 75 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
| 76 | - $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css') |
|
| 77 | - || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css') |
|
| 78 | - || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css'); |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $style |
|
| 73 | + */ |
|
| 74 | + public function doFindTheme($style) { |
|
| 75 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
| 76 | + $this->appendIfExist($this->serverroot, $theme_dir.'apps/'.$style.'.css') |
|
| 77 | + || $this->appendIfExist($this->serverroot, $theme_dir.$style.'.css') |
|
| 78 | + || $this->appendIfExist($this->serverroot, $theme_dir.'core/'.$style.'.css'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function append($root, $file, $webRoot = null, $throw = true, $scss = false) { |
|
| 82 | - if (!$scss) { |
|
| 83 | - parent::append($root, $file, $webRoot, $throw); |
|
| 84 | - } else { |
|
| 85 | - if (!$webRoot) { |
|
| 86 | - $webRoot = $this->findWebRoot($root); |
|
| 81 | + public function append($root, $file, $webRoot = null, $throw = true, $scss = false) { |
|
| 82 | + if (!$scss) { |
|
| 83 | + parent::append($root, $file, $webRoot, $throw); |
|
| 84 | + } else { |
|
| 85 | + if (!$webRoot) { |
|
| 86 | + $webRoot = $this->findWebRoot($root); |
|
| 87 | 87 | |
| 88 | - if ($webRoot === null) { |
|
| 89 | - $webRoot = ''; |
|
| 90 | - $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
| 91 | - 'app' => 'lib', |
|
| 92 | - 'root' => $root, |
|
| 93 | - 'file' => $file, |
|
| 94 | - 'webRoot' => $webRoot, |
|
| 95 | - 'throw' => $throw ? 'true' : 'false' |
|
| 96 | - ]); |
|
| 88 | + if ($webRoot === null) { |
|
| 89 | + $webRoot = ''; |
|
| 90 | + $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
| 91 | + 'app' => 'lib', |
|
| 92 | + 'root' => $root, |
|
| 93 | + 'file' => $file, |
|
| 94 | + 'webRoot' => $webRoot, |
|
| 95 | + 'throw' => $throw ? 'true' : 'false' |
|
| 96 | + ]); |
|
| 97 | 97 | |
| 98 | - if ($throw && $root === '/') { |
|
| 99 | - throw new ResourceNotFoundException($file, $webRoot); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 98 | + if ($throw && $root === '/') { |
|
| 99 | + throw new ResourceNotFoundException($file, $webRoot); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $this->resources[] = [$webRoot ?: \OC::$WEBROOT, $webRoot, $file]; |
|
| 105 | - } |
|
| 106 | - } |
|
| 104 | + $this->resources[] = [$webRoot ?: \OC::$WEBROOT, $webRoot, $file]; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -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 | } |
@@ -32,165 +32,165 @@ |
||
| 32 | 32 | use Psr\Log\LoggerInterface; |
| 33 | 33 | |
| 34 | 34 | abstract class ResourceLocator { |
| 35 | - protected $theme; |
|
| 36 | - |
|
| 37 | - protected $mapping; |
|
| 38 | - protected $serverroot; |
|
| 39 | - protected $webroot; |
|
| 40 | - |
|
| 41 | - protected $resources = []; |
|
| 42 | - |
|
| 43 | - protected LoggerInterface $logger; |
|
| 44 | - |
|
| 45 | - public function __construct(LoggerInterface $logger) { |
|
| 46 | - $this->logger = $logger; |
|
| 47 | - $this->mapping = [ |
|
| 48 | - \OC::$SERVERROOT => \OC::$WEBROOT |
|
| 49 | - ]; |
|
| 50 | - $this->serverroot = \OC::$SERVERROOT; |
|
| 51 | - $this->webroot = \OC::$WEBROOT; |
|
| 52 | - $this->theme = \OC_Util::getTheme(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $resource |
|
| 57 | - */ |
|
| 58 | - abstract public function doFind($resource); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param string $resource |
|
| 62 | - */ |
|
| 63 | - abstract public function doFindTheme($resource); |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Finds the resources and adds them to the list |
|
| 67 | - * |
|
| 68 | - * @param array $resources |
|
| 69 | - */ |
|
| 70 | - public function find($resources) { |
|
| 71 | - foreach ($resources as $resource) { |
|
| 72 | - try { |
|
| 73 | - $this->doFind($resource); |
|
| 74 | - } catch (ResourceNotFoundException $e) { |
|
| 75 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
| 76 | - $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - if (!empty($this->theme)) { |
|
| 80 | - foreach ($resources as $resource) { |
|
| 81 | - try { |
|
| 82 | - $this->doFindTheme($resource); |
|
| 83 | - } catch (ResourceNotFoundException $e) { |
|
| 84 | - $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
| 85 | - $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * append the $file resource if exist at $root |
|
| 93 | - * |
|
| 94 | - * @param string $root path to check |
|
| 95 | - * @param string $file the filename |
|
| 96 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
| 97 | - * @return bool True if the resource was found, false otherwise |
|
| 98 | - */ |
|
| 99 | - protected function appendIfExist($root, $file, $webRoot = null) { |
|
| 100 | - if ($root !== false && is_file($root.'/'.$file)) { |
|
| 101 | - $this->append($root, $file, $webRoot, false); |
|
| 102 | - return true; |
|
| 103 | - } |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Attempt to find the webRoot |
|
| 109 | - * |
|
| 110 | - * traverse the potential web roots upwards in the path |
|
| 111 | - * |
|
| 112 | - * example: |
|
| 113 | - * - root: /srv/www/apps/myapp |
|
| 114 | - * - available mappings: ['/srv/www'] |
|
| 115 | - * |
|
| 116 | - * First we check if a mapping for /srv/www/apps/myapp is available, |
|
| 117 | - * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a |
|
| 118 | - * valid web root |
|
| 119 | - * |
|
| 120 | - * @param string $root |
|
| 121 | - * @return string|null The web root or null on failure |
|
| 122 | - */ |
|
| 123 | - protected function findWebRoot($root) { |
|
| 124 | - $webRoot = null; |
|
| 125 | - $tmpRoot = $root; |
|
| 126 | - |
|
| 127 | - while ($webRoot === null) { |
|
| 128 | - if (isset($this->mapping[$tmpRoot])) { |
|
| 129 | - $webRoot = $this->mapping[$tmpRoot]; |
|
| 130 | - break; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ($tmpRoot === '/') { |
|
| 134 | - break; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $tmpRoot = dirname($tmpRoot); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if ($webRoot === null) { |
|
| 141 | - $realpath = realpath($root); |
|
| 142 | - |
|
| 143 | - if ($realpath && ($realpath !== $root)) { |
|
| 144 | - return $this->findWebRoot($realpath); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $webRoot; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * append the $file resource at $root |
|
| 153 | - * |
|
| 154 | - * @param string $root path to check |
|
| 155 | - * @param string $file the filename |
|
| 156 | - * @param string|null $webRoot base for path, default map $root to $webRoot |
|
| 157 | - * @param bool $throw Throw an exception, when the route does not exist |
|
| 158 | - * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
| 159 | - */ |
|
| 160 | - protected function append($root, $file, $webRoot = null, $throw = true) { |
|
| 161 | - if (!is_string($root)) { |
|
| 162 | - if ($throw) { |
|
| 163 | - throw new ResourceNotFoundException($file, $webRoot); |
|
| 164 | - } |
|
| 165 | - return; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if (!$webRoot) { |
|
| 169 | - $webRoot = $this->findWebRoot($root); |
|
| 170 | - |
|
| 171 | - if ($webRoot === null) { |
|
| 172 | - $webRoot = ''; |
|
| 173 | - $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
| 174 | - 'app' => 'lib', |
|
| 175 | - 'root' => $root, |
|
| 176 | - 'file' => $file, |
|
| 177 | - 'webRoot' => $webRoot, |
|
| 178 | - 'throw' => $throw ? 'true' : 'false' |
|
| 179 | - ]); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - $this->resources[] = [$root, $webRoot, $file]; |
|
| 183 | - |
|
| 184 | - if ($throw && !is_file($root . '/' . $file)) { |
|
| 185 | - throw new ResourceNotFoundException($file, $webRoot); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Returns the list of all resources that should be loaded |
|
| 191 | - * @return array |
|
| 192 | - */ |
|
| 193 | - public function getResources() { |
|
| 194 | - return $this->resources; |
|
| 195 | - } |
|
| 35 | + protected $theme; |
|
| 36 | + |
|
| 37 | + protected $mapping; |
|
| 38 | + protected $serverroot; |
|
| 39 | + protected $webroot; |
|
| 40 | + |
|
| 41 | + protected $resources = []; |
|
| 42 | + |
|
| 43 | + protected LoggerInterface $logger; |
|
| 44 | + |
|
| 45 | + public function __construct(LoggerInterface $logger) { |
|
| 46 | + $this->logger = $logger; |
|
| 47 | + $this->mapping = [ |
|
| 48 | + \OC::$SERVERROOT => \OC::$WEBROOT |
|
| 49 | + ]; |
|
| 50 | + $this->serverroot = \OC::$SERVERROOT; |
|
| 51 | + $this->webroot = \OC::$WEBROOT; |
|
| 52 | + $this->theme = \OC_Util::getTheme(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $resource |
|
| 57 | + */ |
|
| 58 | + abstract public function doFind($resource); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param string $resource |
|
| 62 | + */ |
|
| 63 | + abstract public function doFindTheme($resource); |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Finds the resources and adds them to the list |
|
| 67 | + * |
|
| 68 | + * @param array $resources |
|
| 69 | + */ |
|
| 70 | + public function find($resources) { |
|
| 71 | + foreach ($resources as $resource) { |
|
| 72 | + try { |
|
| 73 | + $this->doFind($resource); |
|
| 74 | + } catch (ResourceNotFoundException $e) { |
|
| 75 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
| 76 | + $this->logger->debug('Could not find resource file "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + if (!empty($this->theme)) { |
|
| 80 | + foreach ($resources as $resource) { |
|
| 81 | + try { |
|
| 82 | + $this->doFindTheme($resource); |
|
| 83 | + } catch (ResourceNotFoundException $e) { |
|
| 84 | + $resourceApp = substr($resource, 0, strpos($resource, '/')); |
|
| 85 | + $this->logger->debug('Could not find resource file in theme "' . $e->getResourcePath() . '"', ['app' => $resourceApp]); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * append the $file resource if exist at $root |
|
| 93 | + * |
|
| 94 | + * @param string $root path to check |
|
| 95 | + * @param string $file the filename |
|
| 96 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
| 97 | + * @return bool True if the resource was found, false otherwise |
|
| 98 | + */ |
|
| 99 | + protected function appendIfExist($root, $file, $webRoot = null) { |
|
| 100 | + if ($root !== false && is_file($root.'/'.$file)) { |
|
| 101 | + $this->append($root, $file, $webRoot, false); |
|
| 102 | + return true; |
|
| 103 | + } |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Attempt to find the webRoot |
|
| 109 | + * |
|
| 110 | + * traverse the potential web roots upwards in the path |
|
| 111 | + * |
|
| 112 | + * example: |
|
| 113 | + * - root: /srv/www/apps/myapp |
|
| 114 | + * - available mappings: ['/srv/www'] |
|
| 115 | + * |
|
| 116 | + * First we check if a mapping for /srv/www/apps/myapp is available, |
|
| 117 | + * then /srv/www/apps, /srv/www/apps, /srv/www, ... until we find a |
|
| 118 | + * valid web root |
|
| 119 | + * |
|
| 120 | + * @param string $root |
|
| 121 | + * @return string|null The web root or null on failure |
|
| 122 | + */ |
|
| 123 | + protected function findWebRoot($root) { |
|
| 124 | + $webRoot = null; |
|
| 125 | + $tmpRoot = $root; |
|
| 126 | + |
|
| 127 | + while ($webRoot === null) { |
|
| 128 | + if (isset($this->mapping[$tmpRoot])) { |
|
| 129 | + $webRoot = $this->mapping[$tmpRoot]; |
|
| 130 | + break; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ($tmpRoot === '/') { |
|
| 134 | + break; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $tmpRoot = dirname($tmpRoot); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if ($webRoot === null) { |
|
| 141 | + $realpath = realpath($root); |
|
| 142 | + |
|
| 143 | + if ($realpath && ($realpath !== $root)) { |
|
| 144 | + return $this->findWebRoot($realpath); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $webRoot; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * append the $file resource at $root |
|
| 153 | + * |
|
| 154 | + * @param string $root path to check |
|
| 155 | + * @param string $file the filename |
|
| 156 | + * @param string|null $webRoot base for path, default map $root to $webRoot |
|
| 157 | + * @param bool $throw Throw an exception, when the route does not exist |
|
| 158 | + * @throws ResourceNotFoundException Only thrown when $throw is true and the resource is missing |
|
| 159 | + */ |
|
| 160 | + protected function append($root, $file, $webRoot = null, $throw = true) { |
|
| 161 | + if (!is_string($root)) { |
|
| 162 | + if ($throw) { |
|
| 163 | + throw new ResourceNotFoundException($file, $webRoot); |
|
| 164 | + } |
|
| 165 | + return; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if (!$webRoot) { |
|
| 169 | + $webRoot = $this->findWebRoot($root); |
|
| 170 | + |
|
| 171 | + if ($webRoot === null) { |
|
| 172 | + $webRoot = ''; |
|
| 173 | + $this->logger->error('ResourceLocator can not find a web root (root: {root}, file: {file}, webRoot: {webRoot}, throw: {throw})', [ |
|
| 174 | + 'app' => 'lib', |
|
| 175 | + 'root' => $root, |
|
| 176 | + 'file' => $file, |
|
| 177 | + 'webRoot' => $webRoot, |
|
| 178 | + 'throw' => $throw ? 'true' : 'false' |
|
| 179 | + ]); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + $this->resources[] = [$root, $webRoot, $file]; |
|
| 183 | + |
|
| 184 | + if ($throw && !is_file($root . '/' . $file)) { |
|
| 185 | + throw new ResourceNotFoundException($file, $webRoot); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Returns the list of all resources that should be loaded |
|
| 191 | + * @return array |
|
| 192 | + */ |
|
| 193 | + public function getResources() { |
|
| 194 | + return $this->resources; |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -117,7 +117,7 @@ |
||
| 117 | 117 | if (array_key_exists($key, $this->vars)) { |
| 118 | 118 | $this->vars[$key][] = $value; |
| 119 | 119 | } else { |
| 120 | - $this->vars[$key] = [ $value ]; |
|
| 120 | + $this->vars[$key] = [$value]; |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -33,159 +33,159 @@ |
||
| 33 | 33 | use Throwable; |
| 34 | 34 | |
| 35 | 35 | class Base { |
| 36 | - private $template; // The template |
|
| 37 | - private $vars; // Vars |
|
| 36 | + private $template; // The template |
|
| 37 | + private $vars; // Vars |
|
| 38 | 38 | |
| 39 | - /** @var \OCP\IL10N */ |
|
| 40 | - private $l10n; |
|
| 39 | + /** @var \OCP\IL10N */ |
|
| 40 | + private $l10n; |
|
| 41 | 41 | |
| 42 | - /** @var Defaults */ |
|
| 43 | - private $theme; |
|
| 42 | + /** @var Defaults */ |
|
| 43 | + private $theme; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $template |
|
| 47 | - * @param string $requestToken |
|
| 48 | - * @param \OCP\IL10N $l10n |
|
| 49 | - * @param Defaults $theme |
|
| 50 | - */ |
|
| 51 | - public function __construct($template, $requestToken, $l10n, $theme) { |
|
| 52 | - $this->vars = []; |
|
| 53 | - $this->vars['requesttoken'] = $requestToken; |
|
| 54 | - $this->l10n = $l10n; |
|
| 55 | - $this->template = $template; |
|
| 56 | - $this->theme = $theme; |
|
| 57 | - } |
|
| 45 | + /** |
|
| 46 | + * @param string $template |
|
| 47 | + * @param string $requestToken |
|
| 48 | + * @param \OCP\IL10N $l10n |
|
| 49 | + * @param Defaults $theme |
|
| 50 | + */ |
|
| 51 | + public function __construct($template, $requestToken, $l10n, $theme) { |
|
| 52 | + $this->vars = []; |
|
| 53 | + $this->vars['requesttoken'] = $requestToken; |
|
| 54 | + $this->l10n = $l10n; |
|
| 55 | + $this->template = $template; |
|
| 56 | + $this->theme = $theme; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param string $serverRoot |
|
| 61 | - * @param string|false $app_dir |
|
| 62 | - * @param string $theme |
|
| 63 | - * @param string $app |
|
| 64 | - * @return string[] |
|
| 65 | - */ |
|
| 66 | - protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) { |
|
| 67 | - // Check if the app is in the app folder or in the root |
|
| 68 | - if ($app_dir !== false && file_exists($app_dir.'/templates/')) { |
|
| 69 | - return [ |
|
| 70 | - $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/', |
|
| 71 | - $app_dir.'/templates/', |
|
| 72 | - ]; |
|
| 73 | - } |
|
| 74 | - return [ |
|
| 75 | - $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/', |
|
| 76 | - $serverRoot.'/'.$app.'/templates/', |
|
| 77 | - ]; |
|
| 78 | - } |
|
| 59 | + /** |
|
| 60 | + * @param string $serverRoot |
|
| 61 | + * @param string|false $app_dir |
|
| 62 | + * @param string $theme |
|
| 63 | + * @param string $app |
|
| 64 | + * @return string[] |
|
| 65 | + */ |
|
| 66 | + protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) { |
|
| 67 | + // Check if the app is in the app folder or in the root |
|
| 68 | + if ($app_dir !== false && file_exists($app_dir.'/templates/')) { |
|
| 69 | + return [ |
|
| 70 | + $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/', |
|
| 71 | + $app_dir.'/templates/', |
|
| 72 | + ]; |
|
| 73 | + } |
|
| 74 | + return [ |
|
| 75 | + $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/', |
|
| 76 | + $serverRoot.'/'.$app.'/templates/', |
|
| 77 | + ]; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @param string $serverRoot |
|
| 82 | - * @param string $theme |
|
| 83 | - * @return string[] |
|
| 84 | - */ |
|
| 85 | - protected function getCoreTemplateDirs($theme, $serverRoot) { |
|
| 86 | - return [ |
|
| 87 | - $serverRoot.'/themes/'.$theme.'/core/templates/', |
|
| 88 | - $serverRoot.'/core/templates/', |
|
| 89 | - ]; |
|
| 90 | - } |
|
| 80 | + /** |
|
| 81 | + * @param string $serverRoot |
|
| 82 | + * @param string $theme |
|
| 83 | + * @return string[] |
|
| 84 | + */ |
|
| 85 | + protected function getCoreTemplateDirs($theme, $serverRoot) { |
|
| 86 | + return [ |
|
| 87 | + $serverRoot.'/themes/'.$theme.'/core/templates/', |
|
| 88 | + $serverRoot.'/core/templates/', |
|
| 89 | + ]; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Assign variables |
|
| 94 | - * @param string $key key |
|
| 95 | - * @param float|array|bool|integer|string|Throwable $value value |
|
| 96 | - * @return bool |
|
| 97 | - * |
|
| 98 | - * This function assigns a variable. It can be accessed via $_[$key] in |
|
| 99 | - * the template. |
|
| 100 | - * |
|
| 101 | - * If the key existed before, it will be overwritten |
|
| 102 | - */ |
|
| 103 | - public function assign($key, $value) { |
|
| 104 | - $this->vars[$key] = $value; |
|
| 105 | - return true; |
|
| 106 | - } |
|
| 92 | + /** |
|
| 93 | + * Assign variables |
|
| 94 | + * @param string $key key |
|
| 95 | + * @param float|array|bool|integer|string|Throwable $value value |
|
| 96 | + * @return bool |
|
| 97 | + * |
|
| 98 | + * This function assigns a variable. It can be accessed via $_[$key] in |
|
| 99 | + * the template. |
|
| 100 | + * |
|
| 101 | + * If the key existed before, it will be overwritten |
|
| 102 | + */ |
|
| 103 | + public function assign($key, $value) { |
|
| 104 | + $this->vars[$key] = $value; |
|
| 105 | + return true; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Appends a variable |
|
| 110 | - * @param string $key key |
|
| 111 | - * @param mixed $value value |
|
| 112 | - * |
|
| 113 | - * This function assigns a variable in an array context. If the key already |
|
| 114 | - * exists, the value will be appended. It can be accessed via |
|
| 115 | - * $_[$key][$position] in the template. |
|
| 116 | - */ |
|
| 117 | - public function append($key, $value) { |
|
| 118 | - if (array_key_exists($key, $this->vars)) { |
|
| 119 | - $this->vars[$key][] = $value; |
|
| 120 | - } else { |
|
| 121 | - $this->vars[$key] = [ $value ]; |
|
| 122 | - } |
|
| 123 | - } |
|
| 108 | + /** |
|
| 109 | + * Appends a variable |
|
| 110 | + * @param string $key key |
|
| 111 | + * @param mixed $value value |
|
| 112 | + * |
|
| 113 | + * This function assigns a variable in an array context. If the key already |
|
| 114 | + * exists, the value will be appended. It can be accessed via |
|
| 115 | + * $_[$key][$position] in the template. |
|
| 116 | + */ |
|
| 117 | + public function append($key, $value) { |
|
| 118 | + if (array_key_exists($key, $this->vars)) { |
|
| 119 | + $this->vars[$key][] = $value; |
|
| 120 | + } else { |
|
| 121 | + $this->vars[$key] = [ $value ]; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Prints the proceeded template |
|
| 127 | - * @return bool |
|
| 128 | - * |
|
| 129 | - * This function proceeds the template and prints its output. |
|
| 130 | - */ |
|
| 131 | - public function printPage() { |
|
| 132 | - $data = $this->fetchPage(); |
|
| 133 | - if ($data === false) { |
|
| 134 | - return false; |
|
| 135 | - } else { |
|
| 136 | - print $data; |
|
| 137 | - return true; |
|
| 138 | - } |
|
| 139 | - } |
|
| 125 | + /** |
|
| 126 | + * Prints the proceeded template |
|
| 127 | + * @return bool |
|
| 128 | + * |
|
| 129 | + * This function proceeds the template and prints its output. |
|
| 130 | + */ |
|
| 131 | + public function printPage() { |
|
| 132 | + $data = $this->fetchPage(); |
|
| 133 | + if ($data === false) { |
|
| 134 | + return false; |
|
| 135 | + } else { |
|
| 136 | + print $data; |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Process the template |
|
| 143 | - * |
|
| 144 | - * @param array|null $additionalParams |
|
| 145 | - * @return string This function processes the template. |
|
| 146 | - * |
|
| 147 | - * This function processes the template. |
|
| 148 | - */ |
|
| 149 | - public function fetchPage($additionalParams = null) { |
|
| 150 | - return $this->load($this->template, $additionalParams); |
|
| 151 | - } |
|
| 141 | + /** |
|
| 142 | + * Process the template |
|
| 143 | + * |
|
| 144 | + * @param array|null $additionalParams |
|
| 145 | + * @return string This function processes the template. |
|
| 146 | + * |
|
| 147 | + * This function processes the template. |
|
| 148 | + */ |
|
| 149 | + public function fetchPage($additionalParams = null) { |
|
| 150 | + return $this->load($this->template, $additionalParams); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * doing the actual work |
|
| 155 | - * |
|
| 156 | - * @param string $file |
|
| 157 | - * @param array|null $additionalParams |
|
| 158 | - * @return string content |
|
| 159 | - * |
|
| 160 | - * Includes the template file, fetches its output |
|
| 161 | - */ |
|
| 162 | - protected function load($file, $additionalParams = null) { |
|
| 163 | - // Register the variables |
|
| 164 | - $_ = $this->vars; |
|
| 165 | - $l = $this->l10n; |
|
| 166 | - $theme = $this->theme; |
|
| 153 | + /** |
|
| 154 | + * doing the actual work |
|
| 155 | + * |
|
| 156 | + * @param string $file |
|
| 157 | + * @param array|null $additionalParams |
|
| 158 | + * @return string content |
|
| 159 | + * |
|
| 160 | + * Includes the template file, fetches its output |
|
| 161 | + */ |
|
| 162 | + protected function load($file, $additionalParams = null) { |
|
| 163 | + // Register the variables |
|
| 164 | + $_ = $this->vars; |
|
| 165 | + $l = $this->l10n; |
|
| 166 | + $theme = $this->theme; |
|
| 167 | 167 | |
| 168 | - if (!is_null($additionalParams)) { |
|
| 169 | - $_ = array_merge($additionalParams, $this->vars); |
|
| 170 | - foreach ($_ as $var => $value) { |
|
| 171 | - if (!isset(${$var})) { |
|
| 172 | - ${$var} = $value; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 168 | + if (!is_null($additionalParams)) { |
|
| 169 | + $_ = array_merge($additionalParams, $this->vars); |
|
| 170 | + foreach ($_ as $var => $value) { |
|
| 171 | + if (!isset(${$var})) { |
|
| 172 | + ${$var} = $value; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - // Include |
|
| 178 | - ob_start(); |
|
| 179 | - try { |
|
| 180 | - include $file; |
|
| 181 | - $data = ob_get_contents(); |
|
| 182 | - } catch (\Exception $e) { |
|
| 183 | - @ob_end_clean(); |
|
| 184 | - throw $e; |
|
| 185 | - } |
|
| 186 | - @ob_end_clean(); |
|
| 177 | + // Include |
|
| 178 | + ob_start(); |
|
| 179 | + try { |
|
| 180 | + include $file; |
|
| 181 | + $data = ob_get_contents(); |
|
| 182 | + } catch (\Exception $e) { |
|
| 183 | + @ob_end_clean(); |
|
| 184 | + throw $e; |
|
| 185 | + } |
|
| 186 | + @ob_end_clean(); |
|
| 187 | 187 | |
| 188 | - // Return data |
|
| 189 | - return $data; |
|
| 190 | - } |
|
| 188 | + // Return data |
|
| 189 | + return $data; |
|
| 190 | + } |
|
| 191 | 191 | } |
@@ -65,8 +65,8 @@ |
||
| 65 | 65 | |
| 66 | 66 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
| 67 | 67 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
| 68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
| 69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
| 68 | + $this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt); |
|
| 69 | + $this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt); |
|
| 70 | 70 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
| 71 | 71 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
| 72 | 72 | } |
@@ -31,104 +31,104 @@ |
||
| 31 | 31 | use OCP\ICertificate; |
| 32 | 32 | |
| 33 | 33 | class Certificate implements ICertificate { |
| 34 | - protected $name; |
|
| 35 | - |
|
| 36 | - protected $commonName; |
|
| 37 | - |
|
| 38 | - protected $organization; |
|
| 39 | - |
|
| 40 | - protected $serial; |
|
| 41 | - |
|
| 42 | - protected $issueDate; |
|
| 43 | - |
|
| 44 | - protected $expireDate; |
|
| 45 | - |
|
| 46 | - protected $issuerName; |
|
| 47 | - |
|
| 48 | - protected $issuerOrganization; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param string $data base64 encoded certificate |
|
| 52 | - * @param string $name |
|
| 53 | - * @throws \Exception If the certificate could not get parsed |
|
| 54 | - */ |
|
| 55 | - public function __construct(string $data, string $name) { |
|
| 56 | - $this->name = $name; |
|
| 57 | - $gmt = new \DateTimeZone('GMT'); |
|
| 58 | - |
|
| 59 | - // If string starts with "file://" ignore the certificate |
|
| 60 | - $query = 'file://'; |
|
| 61 | - if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
| 62 | - throw new \Exception('Certificate could not get parsed.'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $info = openssl_x509_parse($data); |
|
| 66 | - if (!is_array($info)) { |
|
| 67 | - throw new \Exception('Certificate could not get parsed.'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
| 71 | - $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
| 72 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
| 73 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
| 74 | - $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
| 75 | - $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function getName(): string { |
|
| 82 | - return $this->name; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @return string|null |
|
| 87 | - */ |
|
| 88 | - public function getCommonName(): ?string { |
|
| 89 | - return $this->commonName; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return string|null |
|
| 94 | - */ |
|
| 95 | - public function getOrganization(): ?string { |
|
| 96 | - return $this->organization; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return \DateTime |
|
| 101 | - */ |
|
| 102 | - public function getIssueDate(): \DateTime { |
|
| 103 | - return $this->issueDate; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return \DateTime |
|
| 108 | - */ |
|
| 109 | - public function getExpireDate(): \DateTime { |
|
| 110 | - return $this->expireDate; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return bool |
|
| 115 | - */ |
|
| 116 | - public function isExpired(): bool { |
|
| 117 | - $now = new \DateTime(); |
|
| 118 | - return $this->issueDate > $now or $now > $this->expireDate; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return string|null |
|
| 123 | - */ |
|
| 124 | - public function getIssuerName(): ?string { |
|
| 125 | - return $this->issuerName; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @return string|null |
|
| 130 | - */ |
|
| 131 | - public function getIssuerOrganization(): ?string { |
|
| 132 | - return $this->issuerOrganization; |
|
| 133 | - } |
|
| 34 | + protected $name; |
|
| 35 | + |
|
| 36 | + protected $commonName; |
|
| 37 | + |
|
| 38 | + protected $organization; |
|
| 39 | + |
|
| 40 | + protected $serial; |
|
| 41 | + |
|
| 42 | + protected $issueDate; |
|
| 43 | + |
|
| 44 | + protected $expireDate; |
|
| 45 | + |
|
| 46 | + protected $issuerName; |
|
| 47 | + |
|
| 48 | + protected $issuerOrganization; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param string $data base64 encoded certificate |
|
| 52 | + * @param string $name |
|
| 53 | + * @throws \Exception If the certificate could not get parsed |
|
| 54 | + */ |
|
| 55 | + public function __construct(string $data, string $name) { |
|
| 56 | + $this->name = $name; |
|
| 57 | + $gmt = new \DateTimeZone('GMT'); |
|
| 58 | + |
|
| 59 | + // If string starts with "file://" ignore the certificate |
|
| 60 | + $query = 'file://'; |
|
| 61 | + if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
| 62 | + throw new \Exception('Certificate could not get parsed.'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $info = openssl_x509_parse($data); |
|
| 66 | + if (!is_array($info)) { |
|
| 67 | + throw new \Exception('Certificate could not get parsed.'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
| 71 | + $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
| 72 | + $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
| 73 | + $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
| 74 | + $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
| 75 | + $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function getName(): string { |
|
| 82 | + return $this->name; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @return string|null |
|
| 87 | + */ |
|
| 88 | + public function getCommonName(): ?string { |
|
| 89 | + return $this->commonName; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return string|null |
|
| 94 | + */ |
|
| 95 | + public function getOrganization(): ?string { |
|
| 96 | + return $this->organization; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return \DateTime |
|
| 101 | + */ |
|
| 102 | + public function getIssueDate(): \DateTime { |
|
| 103 | + return $this->issueDate; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return \DateTime |
|
| 108 | + */ |
|
| 109 | + public function getExpireDate(): \DateTime { |
|
| 110 | + return $this->expireDate; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return bool |
|
| 115 | + */ |
|
| 116 | + public function isExpired(): bool { |
|
| 117 | + $now = new \DateTime(); |
|
| 118 | + return $this->issueDate > $now or $now > $this->expireDate; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return string|null |
|
| 123 | + */ |
|
| 124 | + public function getIssuerName(): ?string { |
|
| 125 | + return $this->issuerName; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @return string|null |
|
| 130 | + */ |
|
| 131 | + public function getIssuerOrganization(): ?string { |
|
| 132 | + return $this->issuerOrganization; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -89,7 +89,7 @@ |
||
| 89 | 89 | $user = $this->userManager->get($userId); |
| 90 | 90 | if ($user !== null) { |
| 91 | 91 | $key = $this->keyManager->getKey($user); |
| 92 | - return (bool)openssl_verify( |
|
| 92 | + return (bool) openssl_verify( |
|
| 93 | 93 | json_encode($data['message']), |
| 94 | 94 | base64_decode($data['signature']), |
| 95 | 95 | $key->getPublic(), |
@@ -32,76 +32,76 @@ |
||
| 32 | 32 | use OCP\IUserManager; |
| 33 | 33 | |
| 34 | 34 | class Signer { |
| 35 | - /** @var Manager */ |
|
| 36 | - private $keyManager; |
|
| 37 | - /** @var ITimeFactory */ |
|
| 38 | - private $timeFactory; |
|
| 39 | - /** @var IUserManager */ |
|
| 40 | - private $userManager; |
|
| 35 | + /** @var Manager */ |
|
| 36 | + private $keyManager; |
|
| 37 | + /** @var ITimeFactory */ |
|
| 38 | + private $timeFactory; |
|
| 39 | + /** @var IUserManager */ |
|
| 40 | + private $userManager; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param Manager $keyManager |
|
| 44 | - * @param ITimeFactory $timeFactory |
|
| 45 | - * @param IUserManager $userManager |
|
| 46 | - */ |
|
| 47 | - public function __construct(Manager $keyManager, |
|
| 48 | - ITimeFactory $timeFactory, |
|
| 49 | - IUserManager $userManager) { |
|
| 50 | - $this->keyManager = $keyManager; |
|
| 51 | - $this->timeFactory = $timeFactory; |
|
| 52 | - $this->userManager = $userManager; |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * @param Manager $keyManager |
|
| 44 | + * @param ITimeFactory $timeFactory |
|
| 45 | + * @param IUserManager $userManager |
|
| 46 | + */ |
|
| 47 | + public function __construct(Manager $keyManager, |
|
| 48 | + ITimeFactory $timeFactory, |
|
| 49 | + IUserManager $userManager) { |
|
| 50 | + $this->keyManager = $keyManager; |
|
| 51 | + $this->timeFactory = $timeFactory; |
|
| 52 | + $this->userManager = $userManager; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Returns a signed blob for $data |
|
| 57 | - * |
|
| 58 | - * @param string $type |
|
| 59 | - * @param array $data |
|
| 60 | - * @param IUser $user |
|
| 61 | - * @return array ['message', 'signature'] |
|
| 62 | - */ |
|
| 63 | - public function sign(string $type, array $data, IUser $user): array { |
|
| 64 | - $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
| 65 | - $data = [ |
|
| 66 | - 'data' => $data, |
|
| 67 | - 'type' => $type, |
|
| 68 | - 'signer' => $user->getCloudId(), |
|
| 69 | - 'timestamp' => $this->timeFactory->getTime(), |
|
| 70 | - ]; |
|
| 71 | - openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
| 55 | + /** |
|
| 56 | + * Returns a signed blob for $data |
|
| 57 | + * |
|
| 58 | + * @param string $type |
|
| 59 | + * @param array $data |
|
| 60 | + * @param IUser $user |
|
| 61 | + * @return array ['message', 'signature'] |
|
| 62 | + */ |
|
| 63 | + public function sign(string $type, array $data, IUser $user): array { |
|
| 64 | + $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
| 65 | + $data = [ |
|
| 66 | + 'data' => $data, |
|
| 67 | + 'type' => $type, |
|
| 68 | + 'signer' => $user->getCloudId(), |
|
| 69 | + 'timestamp' => $this->timeFactory->getTime(), |
|
| 70 | + ]; |
|
| 71 | + openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
| 72 | 72 | |
| 73 | - return [ |
|
| 74 | - 'message' => $data, |
|
| 75 | - 'signature' => base64_encode($signature), |
|
| 76 | - ]; |
|
| 77 | - } |
|
| 73 | + return [ |
|
| 74 | + 'message' => $data, |
|
| 75 | + 'signature' => base64_encode($signature), |
|
| 76 | + ]; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Whether the data is signed properly |
|
| 81 | - * |
|
| 82 | - * @param array $data |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function verify(array $data): bool { |
|
| 86 | - if (isset($data['message']) |
|
| 87 | - && isset($data['signature']) |
|
| 88 | - && isset($data['message']['signer']) |
|
| 89 | - ) { |
|
| 90 | - $location = strrpos($data['message']['signer'], '@'); |
|
| 91 | - $userId = substr($data['message']['signer'], 0, $location); |
|
| 79 | + /** |
|
| 80 | + * Whether the data is signed properly |
|
| 81 | + * |
|
| 82 | + * @param array $data |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function verify(array $data): bool { |
|
| 86 | + if (isset($data['message']) |
|
| 87 | + && isset($data['signature']) |
|
| 88 | + && isset($data['message']['signer']) |
|
| 89 | + ) { |
|
| 90 | + $location = strrpos($data['message']['signer'], '@'); |
|
| 91 | + $userId = substr($data['message']['signer'], 0, $location); |
|
| 92 | 92 | |
| 93 | - $user = $this->userManager->get($userId); |
|
| 94 | - if ($user !== null) { |
|
| 95 | - $key = $this->keyManager->getKey($user); |
|
| 96 | - return (bool)openssl_verify( |
|
| 97 | - json_encode($data['message']), |
|
| 98 | - base64_decode($data['signature']), |
|
| 99 | - $key->getPublic(), |
|
| 100 | - OPENSSL_ALGO_SHA512 |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - } |
|
| 93 | + $user = $this->userManager->get($userId); |
|
| 94 | + if ($user !== null) { |
|
| 95 | + $key = $this->keyManager->getKey($user); |
|
| 96 | + return (bool)openssl_verify( |
|
| 97 | + json_encode($data['message']), |
|
| 98 | + base64_decode($data['signature']), |
|
| 99 | + $key->getPublic(), |
|
| 100 | + OPENSSL_ALGO_SHA512 |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return false; |
|
| 106 | - } |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | use OCP\Encryption\Exceptions\GenericEncryptionException; |
| 28 | 28 | |
| 29 | 29 | class EncryptionHeaderToLargeException extends GenericEncryptionException { |
| 30 | - public function __construct() { |
|
| 31 | - parent::__construct('max header size exceeded'); |
|
| 32 | - } |
|
| 30 | + public function __construct() { |
|
| 31 | + parent::__construct('max header size exceeded'); |
|
| 32 | + } |
|
| 33 | 33 | } |