@@ -28,76 +28,76 @@ |
||
28 | 28 | */ |
29 | 29 | trait IdentifierTrait { |
30 | 30 | |
31 | - /** @var string */ |
|
32 | - protected $identifier; |
|
31 | + /** @var string */ |
|
32 | + protected $identifier; |
|
33 | 33 | |
34 | - /** @var string[] */ |
|
35 | - protected $identifierAliases = []; |
|
34 | + /** @var string[] */ |
|
35 | + protected $identifierAliases = []; |
|
36 | 36 | |
37 | - /** @var IdentifierTrait */ |
|
38 | - protected $deprecateTo = null; |
|
37 | + /** @var IdentifierTrait */ |
|
38 | + protected $deprecateTo = null; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function getIdentifier() { |
|
44 | - return $this->identifier; |
|
45 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function getIdentifier() { |
|
44 | + return $this->identifier; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $identifier |
|
49 | - * @return $this |
|
50 | - */ |
|
51 | - public function setIdentifier($identifier) { |
|
52 | - $this->identifier = $identifier; |
|
53 | - $this->identifierAliases[] = $identifier; |
|
54 | - return $this; |
|
55 | - } |
|
47 | + /** |
|
48 | + * @param string $identifier |
|
49 | + * @return $this |
|
50 | + */ |
|
51 | + public function setIdentifier($identifier) { |
|
52 | + $this->identifier = $identifier; |
|
53 | + $this->identifierAliases[] = $identifier; |
|
54 | + return $this; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return string[] |
|
59 | - */ |
|
60 | - public function getIdentifierAliases() { |
|
61 | - return $this->identifierAliases; |
|
62 | - } |
|
57 | + /** |
|
58 | + * @return string[] |
|
59 | + */ |
|
60 | + public function getIdentifierAliases() { |
|
61 | + return $this->identifierAliases; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $alias |
|
66 | - * @return $this |
|
67 | - */ |
|
68 | - public function addIdentifierAlias($alias) { |
|
69 | - $this->identifierAliases[] = $alias; |
|
70 | - return $this; |
|
71 | - } |
|
64 | + /** |
|
65 | + * @param string $alias |
|
66 | + * @return $this |
|
67 | + */ |
|
68 | + public function addIdentifierAlias($alias) { |
|
69 | + $this->identifierAliases[] = $alias; |
|
70 | + return $this; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return object|null |
|
75 | - */ |
|
76 | - public function getDeprecateTo() { |
|
77 | - return $this->deprecateTo; |
|
78 | - } |
|
73 | + /** |
|
74 | + * @return object|null |
|
75 | + */ |
|
76 | + public function getDeprecateTo() { |
|
77 | + return $this->deprecateTo; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param object $destinationObject |
|
82 | - * @return self |
|
83 | - */ |
|
84 | - public function deprecateTo($destinationObject) { |
|
85 | - $this->deprecateTo = $destinationObject; |
|
86 | - return $this; |
|
87 | - } |
|
80 | + /** |
|
81 | + * @param object $destinationObject |
|
82 | + * @return self |
|
83 | + */ |
|
84 | + public function deprecateTo($destinationObject) { |
|
85 | + $this->deprecateTo = $destinationObject; |
|
86 | + return $this; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function jsonSerializeIdentifier() { |
|
93 | - $data = [ |
|
94 | - 'identifier' => $this->identifier, |
|
95 | - 'identifierAliases' => $this->identifierAliases, |
|
96 | - ]; |
|
97 | - if ($this->deprecateTo) { |
|
98 | - $data['deprecateTo'] = $this->deprecateTo->getIdentifier(); |
|
99 | - } |
|
100 | - return $data; |
|
101 | - } |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function jsonSerializeIdentifier() { |
|
93 | + $data = [ |
|
94 | + 'identifier' => $this->identifier, |
|
95 | + 'identifierAliases' => $this->identifierAliases, |
|
96 | + ]; |
|
97 | + if ($this->deprecateTo) { |
|
98 | + $data['deprecateTo'] = $this->deprecateTo->getIdentifier(); |
|
99 | + } |
|
100 | + return $data; |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -36,27 +36,27 @@ |
||
36 | 36 | * @since 7.0.0 |
37 | 37 | */ |
38 | 38 | class LockNotAcquiredException extends \Exception { |
39 | - /** @var string $path The path that could not be locked */ |
|
40 | - public $path; |
|
39 | + /** @var string $path The path that could not be locked */ |
|
40 | + public $path; |
|
41 | 41 | |
42 | - /** @var integer $lockType The type of the lock that was attempted */ |
|
43 | - public $lockType; |
|
42 | + /** @var integer $lockType The type of the lock that was attempted */ |
|
43 | + public $lockType; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @since 7.0.0 |
|
47 | - */ |
|
48 | - public function __construct($path, $lockType, $code = 0, \Exception $previous = null) { |
|
49 | - $message = \OC::$server->getL10N('core')->t('Could not obtain lock type %d on "%s".', [$lockType, $path]); |
|
50 | - parent::__construct($message, $code, $previous); |
|
51 | - } |
|
45 | + /** |
|
46 | + * @since 7.0.0 |
|
47 | + */ |
|
48 | + public function __construct($path, $lockType, $code = 0, \Exception $previous = null) { |
|
49 | + $message = \OC::$server->getL10N('core')->t('Could not obtain lock type %d on "%s".', [$lockType, $path]); |
|
50 | + parent::__construct($message, $code, $previous); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * custom string representation of object |
|
55 | - * |
|
56 | - * @return string |
|
57 | - * @since 7.0.0 |
|
58 | - */ |
|
59 | - public function __toString() { |
|
60 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
61 | - } |
|
53 | + /** |
|
54 | + * custom string representation of object |
|
55 | + * |
|
56 | + * @return string |
|
57 | + * @since 7.0.0 |
|
58 | + */ |
|
59 | + public function __toString() { |
|
60 | + return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
61 | + } |
|
62 | 62 | } |
@@ -42,67 +42,67 @@ |
||
42 | 42 | abstract class Middleware { |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * This is being run in normal order before the controller is being |
|
47 | - * called which allows several modifications and checks |
|
48 | - * |
|
49 | - * @param Controller $controller the controller that is being called |
|
50 | - * @param string $methodName the name of the method that will be called on |
|
51 | - * the controller |
|
52 | - * @since 6.0.0 |
|
53 | - */ |
|
54 | - public function beforeController($controller, $methodName) { |
|
55 | - } |
|
45 | + /** |
|
46 | + * This is being run in normal order before the controller is being |
|
47 | + * called which allows several modifications and checks |
|
48 | + * |
|
49 | + * @param Controller $controller the controller that is being called |
|
50 | + * @param string $methodName the name of the method that will be called on |
|
51 | + * the controller |
|
52 | + * @since 6.0.0 |
|
53 | + */ |
|
54 | + public function beforeController($controller, $methodName) { |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * This is being run when either the beforeController method or the |
|
60 | - * controller method itself is throwing an exception. The middleware is |
|
61 | - * asked in reverse order to handle the exception and to return a response. |
|
62 | - * If the response is null, it is assumed that the exception could not be |
|
63 | - * handled and the error will be thrown again |
|
64 | - * |
|
65 | - * @param Controller $controller the controller that is being called |
|
66 | - * @param string $methodName the name of the method that will be called on |
|
67 | - * the controller |
|
68 | - * @param \Exception $exception the thrown exception |
|
69 | - * @throws \Exception the passed in exception if it can't handle it |
|
70 | - * @return Response a Response object in case that the exception was handled |
|
71 | - * @since 6.0.0 |
|
72 | - */ |
|
73 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
74 | - throw $exception; |
|
75 | - } |
|
58 | + /** |
|
59 | + * This is being run when either the beforeController method or the |
|
60 | + * controller method itself is throwing an exception. The middleware is |
|
61 | + * asked in reverse order to handle the exception and to return a response. |
|
62 | + * If the response is null, it is assumed that the exception could not be |
|
63 | + * handled and the error will be thrown again |
|
64 | + * |
|
65 | + * @param Controller $controller the controller that is being called |
|
66 | + * @param string $methodName the name of the method that will be called on |
|
67 | + * the controller |
|
68 | + * @param \Exception $exception the thrown exception |
|
69 | + * @throws \Exception the passed in exception if it can't handle it |
|
70 | + * @return Response a Response object in case that the exception was handled |
|
71 | + * @since 6.0.0 |
|
72 | + */ |
|
73 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
74 | + throw $exception; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * This is being run after a successful controllermethod call and allows |
|
80 | - * the manipulation of a Response object. The middleware is run in reverse order |
|
81 | - * |
|
82 | - * @param Controller $controller the controller that is being called |
|
83 | - * @param string $methodName the name of the method that will be called on |
|
84 | - * the controller |
|
85 | - * @param Response $response the generated response from the controller |
|
86 | - * @return Response a Response object |
|
87 | - * @since 6.0.0 |
|
88 | - */ |
|
89 | - public function afterController($controller, $methodName, Response $response) { |
|
90 | - return $response; |
|
91 | - } |
|
78 | + /** |
|
79 | + * This is being run after a successful controllermethod call and allows |
|
80 | + * the manipulation of a Response object. The middleware is run in reverse order |
|
81 | + * |
|
82 | + * @param Controller $controller the controller that is being called |
|
83 | + * @param string $methodName the name of the method that will be called on |
|
84 | + * the controller |
|
85 | + * @param Response $response the generated response from the controller |
|
86 | + * @return Response a Response object |
|
87 | + * @since 6.0.0 |
|
88 | + */ |
|
89 | + public function afterController($controller, $methodName, Response $response) { |
|
90 | + return $response; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * This is being run after the response object has been rendered and |
|
96 | - * allows the manipulation of the output. The middleware is run in reverse order |
|
97 | - * |
|
98 | - * @param Controller $controller the controller that is being called |
|
99 | - * @param string $methodName the name of the method that will be called on |
|
100 | - * the controller |
|
101 | - * @param string $output the generated output from a response |
|
102 | - * @return string the output that should be printed |
|
103 | - * @since 6.0.0 |
|
104 | - */ |
|
105 | - public function beforeOutput($controller, $methodName, $output) { |
|
106 | - return $output; |
|
107 | - } |
|
94 | + /** |
|
95 | + * This is being run after the response object has been rendered and |
|
96 | + * allows the manipulation of the output. The middleware is run in reverse order |
|
97 | + * |
|
98 | + * @param Controller $controller the controller that is being called |
|
99 | + * @param string $methodName the name of the method that will be called on |
|
100 | + * the controller |
|
101 | + * @param string $output the generated output from a response |
|
102 | + * @return string the output that should be printed |
|
103 | + * @since 6.0.0 |
|
104 | + */ |
|
105 | + public function beforeOutput($controller, $methodName, $output) { |
|
106 | + return $output; |
|
107 | + } |
|
108 | 108 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSNotFoundException extends OCSException { |
35 | - /** |
|
36 | - * OCSNotFoundException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_NOT_FOUND, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSNotFoundException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_NOT_FOUND, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSForbiddenException extends OCSException { |
35 | - /** |
|
36 | - * OCSForbiddenException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_FORBIDDEN, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSForbiddenException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_FORBIDDEN, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSBadRequestException extends OCSException { |
35 | - /** |
|
36 | - * OCSBadRequestException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSBadRequestException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -30,200 +30,200 @@ |
||
30 | 30 | * @package OC\App |
31 | 31 | */ |
32 | 32 | class PlatformRepository { |
33 | - public function __construct() { |
|
34 | - $this->packages = $this->initialize(); |
|
35 | - } |
|
36 | - |
|
37 | - protected function initialize() { |
|
38 | - $loadedExtensions = get_loaded_extensions(); |
|
39 | - $packages = []; |
|
40 | - |
|
41 | - // Extensions scanning |
|
42 | - foreach ($loadedExtensions as $name) { |
|
43 | - if (in_array($name, ['standard', 'Core'])) { |
|
44 | - continue; |
|
45 | - } |
|
46 | - |
|
47 | - $ext = new \ReflectionExtension($name); |
|
48 | - try { |
|
49 | - $prettyVersion = $ext->getVersion(); |
|
50 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
51 | - } catch (\UnexpectedValueException $e) { |
|
52 | - $prettyVersion = '0'; |
|
53 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
54 | - } |
|
55 | - |
|
56 | - $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
57 | - } |
|
58 | - |
|
59 | - foreach ($loadedExtensions as $name) { |
|
60 | - $prettyVersion = null; |
|
61 | - switch ($name) { |
|
62 | - case 'curl': |
|
63 | - $curlVersion = curl_version(); |
|
64 | - $prettyVersion = $curlVersion['version']; |
|
65 | - break; |
|
66 | - |
|
67 | - case 'iconv': |
|
68 | - $prettyVersion = ICONV_VERSION; |
|
69 | - break; |
|
70 | - |
|
71 | - case 'intl': |
|
72 | - $name = 'ICU'; |
|
73 | - if (defined('INTL_ICU_VERSION')) { |
|
74 | - $prettyVersion = INTL_ICU_VERSION; |
|
75 | - } else { |
|
76 | - $reflector = new \ReflectionExtension('intl'); |
|
77 | - |
|
78 | - ob_start(); |
|
79 | - $reflector->info(); |
|
80 | - $output = ob_get_clean(); |
|
81 | - |
|
82 | - preg_match('/^ICU version => (.*)$/m', $output, $matches); |
|
83 | - $prettyVersion = $matches[1]; |
|
84 | - } |
|
85 | - |
|
86 | - break; |
|
87 | - |
|
88 | - case 'libxml': |
|
89 | - $prettyVersion = LIBXML_DOTTED_VERSION; |
|
90 | - break; |
|
91 | - |
|
92 | - case 'openssl': |
|
93 | - $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
94 | - return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
95 | - }, OPENSSL_VERSION_TEXT); |
|
96 | - break; |
|
97 | - |
|
98 | - case 'pcre': |
|
99 | - $prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION); |
|
100 | - break; |
|
101 | - |
|
102 | - case 'uuid': |
|
103 | - $prettyVersion = phpversion('uuid'); |
|
104 | - break; |
|
105 | - |
|
106 | - case 'xsl': |
|
107 | - $prettyVersion = LIBXSLT_DOTTED_VERSION; |
|
108 | - break; |
|
109 | - |
|
110 | - default: |
|
111 | - // None handled extensions have no special cases, skip |
|
112 | - continue 2; |
|
113 | - } |
|
114 | - |
|
115 | - try { |
|
116 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
117 | - } catch (\UnexpectedValueException $e) { |
|
118 | - continue; |
|
119 | - } |
|
120 | - |
|
121 | - $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
122 | - } |
|
123 | - |
|
124 | - return $packages; |
|
125 | - } |
|
126 | - |
|
127 | - private function buildPackageName($name) { |
|
128 | - return str_replace(' ', '-', $name); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @param $name |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function findLibrary($name) { |
|
136 | - $extName = $this->buildPackageName($name); |
|
137 | - if (isset($this->packages[$extName])) { |
|
138 | - return $this->packages[$extName]; |
|
139 | - } |
|
140 | - return null; |
|
141 | - } |
|
142 | - |
|
143 | - private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; |
|
144 | - |
|
145 | - /** |
|
146 | - * Normalizes a version string to be able to perform comparisons on it |
|
147 | - * |
|
148 | - * https://github.com/composer/composer/blob/master/src/Composer/Package/Version/VersionParser.php#L94 |
|
149 | - * |
|
150 | - * @param string $version |
|
151 | - * @param string $fullVersion optional complete version string to give more context |
|
152 | - * @throws \UnexpectedValueException |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function normalizeVersion($version, $fullVersion = null) { |
|
156 | - $version = trim($version); |
|
157 | - if (null === $fullVersion) { |
|
158 | - $fullVersion = $version; |
|
159 | - } |
|
160 | - // ignore aliases and just assume the alias is required instead of the source |
|
161 | - if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) { |
|
162 | - $version = $match[1]; |
|
163 | - } |
|
164 | - // match master-like branches |
|
165 | - if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) { |
|
166 | - return '9999999-dev'; |
|
167 | - } |
|
168 | - if ('dev-' === strtolower(substr($version, 0, 4))) { |
|
169 | - return 'dev-' . substr($version, 4); |
|
170 | - } |
|
171 | - // match classical versioning |
|
172 | - if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
173 | - $version = $matches[1] |
|
174 | - . (!empty($matches[2]) ? $matches[2] : '.0') |
|
175 | - . (!empty($matches[3]) ? $matches[3] : '.0') |
|
176 | - . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
177 | - $index = 5; |
|
178 | - } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
179 | - $version = preg_replace('{\D}', '-', $matches[1]); |
|
180 | - $index = 2; |
|
181 | - } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
182 | - $version = $matches[1] |
|
183 | - . (!empty($matches[2]) ? $matches[2] : '.0') |
|
184 | - . (!empty($matches[3]) ? $matches[3] : '.0') |
|
185 | - . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
186 | - $index = 5; |
|
187 | - } |
|
188 | - // add version modifiers if a version was matched |
|
189 | - if (isset($index)) { |
|
190 | - if (!empty($matches[$index])) { |
|
191 | - if ('stable' === $matches[$index]) { |
|
192 | - return $version; |
|
193 | - } |
|
194 | - $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
195 | - } |
|
196 | - if (!empty($matches[$index + 2])) { |
|
197 | - $version .= '-dev'; |
|
198 | - } |
|
199 | - return $version; |
|
200 | - } |
|
201 | - $extraMessage = ''; |
|
202 | - if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
203 | - $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
204 | - } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
205 | - $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
206 | - } |
|
207 | - throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $stability |
|
212 | - */ |
|
213 | - private function expandStability($stability) { |
|
214 | - $stability = strtolower($stability); |
|
215 | - switch ($stability) { |
|
216 | - case 'a': |
|
217 | - return 'alpha'; |
|
218 | - case 'b': |
|
219 | - return 'beta'; |
|
220 | - case 'p': |
|
221 | - case 'pl': |
|
222 | - return 'patch'; |
|
223 | - case 'rc': |
|
224 | - return 'RC'; |
|
225 | - default: |
|
226 | - return $stability; |
|
227 | - } |
|
228 | - } |
|
33 | + public function __construct() { |
|
34 | + $this->packages = $this->initialize(); |
|
35 | + } |
|
36 | + |
|
37 | + protected function initialize() { |
|
38 | + $loadedExtensions = get_loaded_extensions(); |
|
39 | + $packages = []; |
|
40 | + |
|
41 | + // Extensions scanning |
|
42 | + foreach ($loadedExtensions as $name) { |
|
43 | + if (in_array($name, ['standard', 'Core'])) { |
|
44 | + continue; |
|
45 | + } |
|
46 | + |
|
47 | + $ext = new \ReflectionExtension($name); |
|
48 | + try { |
|
49 | + $prettyVersion = $ext->getVersion(); |
|
50 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
51 | + } catch (\UnexpectedValueException $e) { |
|
52 | + $prettyVersion = '0'; |
|
53 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
54 | + } |
|
55 | + |
|
56 | + $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
57 | + } |
|
58 | + |
|
59 | + foreach ($loadedExtensions as $name) { |
|
60 | + $prettyVersion = null; |
|
61 | + switch ($name) { |
|
62 | + case 'curl': |
|
63 | + $curlVersion = curl_version(); |
|
64 | + $prettyVersion = $curlVersion['version']; |
|
65 | + break; |
|
66 | + |
|
67 | + case 'iconv': |
|
68 | + $prettyVersion = ICONV_VERSION; |
|
69 | + break; |
|
70 | + |
|
71 | + case 'intl': |
|
72 | + $name = 'ICU'; |
|
73 | + if (defined('INTL_ICU_VERSION')) { |
|
74 | + $prettyVersion = INTL_ICU_VERSION; |
|
75 | + } else { |
|
76 | + $reflector = new \ReflectionExtension('intl'); |
|
77 | + |
|
78 | + ob_start(); |
|
79 | + $reflector->info(); |
|
80 | + $output = ob_get_clean(); |
|
81 | + |
|
82 | + preg_match('/^ICU version => (.*)$/m', $output, $matches); |
|
83 | + $prettyVersion = $matches[1]; |
|
84 | + } |
|
85 | + |
|
86 | + break; |
|
87 | + |
|
88 | + case 'libxml': |
|
89 | + $prettyVersion = LIBXML_DOTTED_VERSION; |
|
90 | + break; |
|
91 | + |
|
92 | + case 'openssl': |
|
93 | + $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
94 | + return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
95 | + }, OPENSSL_VERSION_TEXT); |
|
96 | + break; |
|
97 | + |
|
98 | + case 'pcre': |
|
99 | + $prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION); |
|
100 | + break; |
|
101 | + |
|
102 | + case 'uuid': |
|
103 | + $prettyVersion = phpversion('uuid'); |
|
104 | + break; |
|
105 | + |
|
106 | + case 'xsl': |
|
107 | + $prettyVersion = LIBXSLT_DOTTED_VERSION; |
|
108 | + break; |
|
109 | + |
|
110 | + default: |
|
111 | + // None handled extensions have no special cases, skip |
|
112 | + continue 2; |
|
113 | + } |
|
114 | + |
|
115 | + try { |
|
116 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
117 | + } catch (\UnexpectedValueException $e) { |
|
118 | + continue; |
|
119 | + } |
|
120 | + |
|
121 | + $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
122 | + } |
|
123 | + |
|
124 | + return $packages; |
|
125 | + } |
|
126 | + |
|
127 | + private function buildPackageName($name) { |
|
128 | + return str_replace(' ', '-', $name); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @param $name |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function findLibrary($name) { |
|
136 | + $extName = $this->buildPackageName($name); |
|
137 | + if (isset($this->packages[$extName])) { |
|
138 | + return $this->packages[$extName]; |
|
139 | + } |
|
140 | + return null; |
|
141 | + } |
|
142 | + |
|
143 | + private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; |
|
144 | + |
|
145 | + /** |
|
146 | + * Normalizes a version string to be able to perform comparisons on it |
|
147 | + * |
|
148 | + * https://github.com/composer/composer/blob/master/src/Composer/Package/Version/VersionParser.php#L94 |
|
149 | + * |
|
150 | + * @param string $version |
|
151 | + * @param string $fullVersion optional complete version string to give more context |
|
152 | + * @throws \UnexpectedValueException |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function normalizeVersion($version, $fullVersion = null) { |
|
156 | + $version = trim($version); |
|
157 | + if (null === $fullVersion) { |
|
158 | + $fullVersion = $version; |
|
159 | + } |
|
160 | + // ignore aliases and just assume the alias is required instead of the source |
|
161 | + if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) { |
|
162 | + $version = $match[1]; |
|
163 | + } |
|
164 | + // match master-like branches |
|
165 | + if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) { |
|
166 | + return '9999999-dev'; |
|
167 | + } |
|
168 | + if ('dev-' === strtolower(substr($version, 0, 4))) { |
|
169 | + return 'dev-' . substr($version, 4); |
|
170 | + } |
|
171 | + // match classical versioning |
|
172 | + if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
173 | + $version = $matches[1] |
|
174 | + . (!empty($matches[2]) ? $matches[2] : '.0') |
|
175 | + . (!empty($matches[3]) ? $matches[3] : '.0') |
|
176 | + . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
177 | + $index = 5; |
|
178 | + } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
179 | + $version = preg_replace('{\D}', '-', $matches[1]); |
|
180 | + $index = 2; |
|
181 | + } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
182 | + $version = $matches[1] |
|
183 | + . (!empty($matches[2]) ? $matches[2] : '.0') |
|
184 | + . (!empty($matches[3]) ? $matches[3] : '.0') |
|
185 | + . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
186 | + $index = 5; |
|
187 | + } |
|
188 | + // add version modifiers if a version was matched |
|
189 | + if (isset($index)) { |
|
190 | + if (!empty($matches[$index])) { |
|
191 | + if ('stable' === $matches[$index]) { |
|
192 | + return $version; |
|
193 | + } |
|
194 | + $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
195 | + } |
|
196 | + if (!empty($matches[$index + 2])) { |
|
197 | + $version .= '-dev'; |
|
198 | + } |
|
199 | + return $version; |
|
200 | + } |
|
201 | + $extraMessage = ''; |
|
202 | + if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
203 | + $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
204 | + } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
205 | + $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
206 | + } |
|
207 | + throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $stability |
|
212 | + */ |
|
213 | + private function expandStability($stability) { |
|
214 | + $stability = strtolower($stability); |
|
215 | + switch ($stability) { |
|
216 | + case 'a': |
|
217 | + return 'alpha'; |
|
218 | + case 'b': |
|
219 | + return 'beta'; |
|
220 | + case 'p': |
|
221 | + case 'pl': |
|
222 | + return 'patch'; |
|
223 | + case 'rc': |
|
224 | + return 'RC'; |
|
225 | + default: |
|
226 | + return $stability; |
|
227 | + } |
|
228 | + } |
|
229 | 229 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | use OCP\IL10N; |
25 | 25 | |
26 | 26 | abstract class Bundle { |
27 | - /** @var IL10N */ |
|
28 | - protected $l10n; |
|
27 | + /** @var IL10N */ |
|
28 | + protected $l10n; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param IL10N $l10n |
|
32 | - */ |
|
33 | - public function __construct(IL10N $l10n) { |
|
34 | - $this->l10n = $l10n; |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param IL10N $l10n |
|
32 | + */ |
|
33 | + public function __construct(IL10N $l10n) { |
|
34 | + $this->l10n = $l10n; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the identifier of the bundle |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - final public function getIdentifier() { |
|
43 | - return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | - } |
|
37 | + /** |
|
38 | + * Get the identifier of the bundle |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + final public function getIdentifier() { |
|
43 | + return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the name of the bundle |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - abstract public function getName(); |
|
46 | + /** |
|
47 | + * Get the name of the bundle |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + abstract public function getName(); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the list of app identifiers in the bundle |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - abstract public function getAppIdentifiers(); |
|
53 | + /** |
|
54 | + * Get the list of app identifiers in the bundle |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + abstract public function getAppIdentifiers(); |
|
59 | 59 | } |
@@ -28,51 +28,51 @@ |
||
28 | 28 | |
29 | 29 | class MoveUpdaterStepFile implements IRepairStep { |
30 | 30 | |
31 | - /** @var \OCP\IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var \OCP\IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param \OCP\IConfig $config |
|
36 | - */ |
|
37 | - public function __construct($config) { |
|
38 | - $this->config = $config; |
|
39 | - } |
|
34 | + /** |
|
35 | + * @param \OCP\IConfig $config |
|
36 | + */ |
|
37 | + public function __construct($config) { |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | 40 | |
41 | - public function getName() { |
|
42 | - return 'Move .step file of updater to backup location'; |
|
43 | - } |
|
41 | + public function getName() { |
|
42 | + return 'Move .step file of updater to backup location'; |
|
43 | + } |
|
44 | 44 | |
45 | - public function run(IOutput $output) { |
|
46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
45 | + public function run(IOutput $output) { |
|
46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
48 | 48 | |
49 | - if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | - return; |
|
51 | - } |
|
49 | + if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | + return; |
|
51 | + } |
|
52 | 52 | |
53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
55 | - if (file_exists($stepFile)) { |
|
56 | - $output->info('.step file exists'); |
|
53 | + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | + $stepFile = $updaterFolderPath . '/.step'; |
|
55 | + if (file_exists($stepFile)) { |
|
56 | + $output->info('.step file exists'); |
|
57 | 57 | |
58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
58 | + $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
59 | 59 | |
60 | - // cleanup |
|
61 | - if (file_exists($previousStepFile)) { |
|
62 | - if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | - $output->info('.step-previous-update removed'); |
|
64 | - } else { |
|
65 | - $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | - return; |
|
67 | - } |
|
68 | - } |
|
60 | + // cleanup |
|
61 | + if (file_exists($previousStepFile)) { |
|
62 | + if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | + $output->info('.step-previous-update removed'); |
|
64 | + } else { |
|
65 | + $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | + return; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // move step file |
|
71 | - if (rename($stepFile, $previousStepFile)) { |
|
72 | - $output->info('.step file moved to .step-previous-update'); |
|
73 | - } else { |
|
74 | - $output->warning('.step file can\'t be moved'); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
70 | + // move step file |
|
71 | + if (rename($stepFile, $previousStepFile)) { |
|
72 | + $output->info('.step file moved to .step-previous-update'); |
|
73 | + } else { |
|
74 | + $output->warning('.step file can\'t be moved'); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | } |