Completed
Pull Request — master (#8334)
by Morris
21:05 queued 06:06
created
lib/versioncheck.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 // Show warning if a PHP version below 7.0 is used, this has to happen here
5 5
 // because base.php will already use 7.0 syntax.
6 6
 if (version_compare(PHP_VERSION, '7.0') === -1) {
7 7
 	http_response_code(500);
8 8
 	echo 'This version of Nextcloud requires at least PHP 7.0<br/>';
9
-	echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.';
9
+	echo 'You are currently running '.PHP_VERSION.'. Please update your PHP version.';
10 10
 	exit(-1);
11 11
 }
12 12
 
@@ -14,6 +14,6 @@  discard block
 block discarded – undo
14 14
 if (version_compare(PHP_VERSION, '7.3.0') !== -1) {
15 15
 	http_response_code(500);
16 16
 	echo 'This version of Nextcloud is not compatible with > PHP 7.2.<br/>';
17
-	echo 'You are currently running ' . PHP_VERSION . '.';
17
+	echo 'You are currently running '.PHP_VERSION.'.';
18 18
 	exit(-1);
19 19
 }
Please login to merge, or discard this patch.
lib/autoloader.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -36,151 +36,151 @@
 block discarded – undo
36 36
 use \OCP\AutoloadNotAllowedException;
37 37
 
38 38
 class Autoloader {
39
-	/** @var bool */
40
-	private $useGlobalClassPath = true;
41
-	/** @var array */
42
-	private $validRoots = [];
43
-
44
-	/**
45
-	 * Optional low-latency memory cache for class to path mapping.
46
-	 *
47
-	 * @var \OC\Memcache\Cache
48
-	 */
49
-	protected $memoryCache;
50
-
51
-	/**
52
-	 * Autoloader constructor.
53
-	 *
54
-	 * @param string[] $validRoots
55
-	 */
56
-	public function __construct(array $validRoots) {
57
-		foreach ($validRoots as $root) {
58
-			$this->validRoots[$root] = true;
59
-		}
60
-	}
61
-
62
-	/**
63
-	 * Add a path to the list of valid php roots for auto loading
64
-	 *
65
-	 * @param string $root
66
-	 */
67
-	public function addValidRoot(string $root) {
68
-		$root = stream_resolve_include_path($root);
69
-		$this->validRoots[$root] = true;
70
-	}
71
-
72
-	/**
73
-	 * disable the usage of the global classpath \OC::$CLASSPATH
74
-	 */
75
-	public function disableGlobalClassPath() {
76
-		$this->useGlobalClassPath = false;
77
-	}
78
-
79
-	/**
80
-	 * enable the usage of the global classpath \OC::$CLASSPATH
81
-	 */
82
-	public function enableGlobalClassPath() {
83
-		$this->useGlobalClassPath = true;
84
-	}
85
-
86
-	/**
87
-	 * get the possible paths for a class
88
-	 *
89
-	 * @param string $class
90
-	 * @return array an array of possible paths
91
-	 */
92
-	public function findClass(string $class): array {
93
-		$class = trim($class, '\\');
94
-
95
-		$paths = [];
96
-		if ($this->useGlobalClassPath && array_key_exists($class, \OC::$CLASSPATH)) {
97
-			$paths[] = \OC::$CLASSPATH[$class];
98
-			/**
99
-			 * @TODO: Remove this when necessary
100
-			 * Remove "apps/" from inclusion path for smooth migration to multi app dir
101
-			 */
102
-			if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) {
103
-				\OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG);
104
-				$paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]);
105
-			}
106
-		} elseif (strpos($class, 'OC_') === 0) {
107
-			$paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php');
108
-		} elseif (strpos($class, 'OCA\\') === 0) {
109
-			list(, $app, $rest) = explode('\\', $class, 3);
110
-			$app = strtolower($app);
111
-			$appPath = \OC_App::getAppPath($app);
112
-			if ($appPath && stream_resolve_include_path($appPath)) {
113
-				$paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php');
114
-				// If not found in the root of the app directory, insert '/lib' after app id and try again.
115
-				$paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php');
116
-			}
117
-		} elseif ($class === 'Test\\TestCase') {
118
-			// This File is considered public API, so we make sure that the class
119
-			// can still be loaded, although the PSR-4 paths have not been loaded.
120
-			$paths[] = \OC::$SERVERROOT . '/tests/lib/TestCase.php';
121
-		}
122
-		return $paths;
123
-	}
124
-
125
-	/**
126
-	 * @param string $fullPath
127
-	 * @return bool
128
-	 * @throws AutoloadNotAllowedException
129
-	 */
130
-	protected function isValidPath(string $fullPath): bool {
131
-		foreach ($this->validRoots as $root => $true) {
132
-			if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') {
133
-				return true;
134
-			}
135
-		}
136
-		throw new AutoloadNotAllowedException($fullPath);
137
-	}
138
-
139
-	/**
140
-	 * Load the specified class
141
-	 *
142
-	 * @param string $class
143
-	 * @return bool
144
-	 * @throws AutoloadNotAllowedException
145
-	 */
146
-	public function load(string $class): bool {
147
-		$pathsToRequire = null;
148
-		if ($this->memoryCache) {
149
-			$pathsToRequire = $this->memoryCache->get($class);
150
-		}
151
-
152
-		if(class_exists($class, false)) {
153
-			return false;
154
-		}
155
-
156
-		if (!is_array($pathsToRequire)) {
157
-			// No cache or cache miss
158
-			$pathsToRequire = array();
159
-			foreach ($this->findClass($class) as $path) {
160
-				$fullPath = stream_resolve_include_path($path);
161
-				if ($fullPath && $this->isValidPath($fullPath)) {
162
-					$pathsToRequire[] = $fullPath;
163
-				}
164
-			}
165
-
166
-			if ($this->memoryCache) {
167
-				$this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec
168
-			}
169
-		}
170
-
171
-		foreach ($pathsToRequire as $fullPath) {
172
-			require_once $fullPath;
173
-		}
174
-
175
-		return false;
176
-	}
177
-
178
-	/**
179
-	 * Sets the optional low-latency cache for class to path mapping.
180
-	 *
181
-	 * @param \OC\Memcache\Cache $memoryCache Instance of memory cache.
182
-	 */
183
-	public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null) {
184
-		$this->memoryCache = $memoryCache;
185
-	}
39
+    /** @var bool */
40
+    private $useGlobalClassPath = true;
41
+    /** @var array */
42
+    private $validRoots = [];
43
+
44
+    /**
45
+     * Optional low-latency memory cache for class to path mapping.
46
+     *
47
+     * @var \OC\Memcache\Cache
48
+     */
49
+    protected $memoryCache;
50
+
51
+    /**
52
+     * Autoloader constructor.
53
+     *
54
+     * @param string[] $validRoots
55
+     */
56
+    public function __construct(array $validRoots) {
57
+        foreach ($validRoots as $root) {
58
+            $this->validRoots[$root] = true;
59
+        }
60
+    }
61
+
62
+    /**
63
+     * Add a path to the list of valid php roots for auto loading
64
+     *
65
+     * @param string $root
66
+     */
67
+    public function addValidRoot(string $root) {
68
+        $root = stream_resolve_include_path($root);
69
+        $this->validRoots[$root] = true;
70
+    }
71
+
72
+    /**
73
+     * disable the usage of the global classpath \OC::$CLASSPATH
74
+     */
75
+    public function disableGlobalClassPath() {
76
+        $this->useGlobalClassPath = false;
77
+    }
78
+
79
+    /**
80
+     * enable the usage of the global classpath \OC::$CLASSPATH
81
+     */
82
+    public function enableGlobalClassPath() {
83
+        $this->useGlobalClassPath = true;
84
+    }
85
+
86
+    /**
87
+     * get the possible paths for a class
88
+     *
89
+     * @param string $class
90
+     * @return array an array of possible paths
91
+     */
92
+    public function findClass(string $class): array {
93
+        $class = trim($class, '\\');
94
+
95
+        $paths = [];
96
+        if ($this->useGlobalClassPath && array_key_exists($class, \OC::$CLASSPATH)) {
97
+            $paths[] = \OC::$CLASSPATH[$class];
98
+            /**
99
+             * @TODO: Remove this when necessary
100
+             * Remove "apps/" from inclusion path for smooth migration to multi app dir
101
+             */
102
+            if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) {
103
+                \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG);
104
+                $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]);
105
+            }
106
+        } elseif (strpos($class, 'OC_') === 0) {
107
+            $paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php');
108
+        } elseif (strpos($class, 'OCA\\') === 0) {
109
+            list(, $app, $rest) = explode('\\', $class, 3);
110
+            $app = strtolower($app);
111
+            $appPath = \OC_App::getAppPath($app);
112
+            if ($appPath && stream_resolve_include_path($appPath)) {
113
+                $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php');
114
+                // If not found in the root of the app directory, insert '/lib' after app id and try again.
115
+                $paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php');
116
+            }
117
+        } elseif ($class === 'Test\\TestCase') {
118
+            // This File is considered public API, so we make sure that the class
119
+            // can still be loaded, although the PSR-4 paths have not been loaded.
120
+            $paths[] = \OC::$SERVERROOT . '/tests/lib/TestCase.php';
121
+        }
122
+        return $paths;
123
+    }
124
+
125
+    /**
126
+     * @param string $fullPath
127
+     * @return bool
128
+     * @throws AutoloadNotAllowedException
129
+     */
130
+    protected function isValidPath(string $fullPath): bool {
131
+        foreach ($this->validRoots as $root => $true) {
132
+            if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') {
133
+                return true;
134
+            }
135
+        }
136
+        throw new AutoloadNotAllowedException($fullPath);
137
+    }
138
+
139
+    /**
140
+     * Load the specified class
141
+     *
142
+     * @param string $class
143
+     * @return bool
144
+     * @throws AutoloadNotAllowedException
145
+     */
146
+    public function load(string $class): bool {
147
+        $pathsToRequire = null;
148
+        if ($this->memoryCache) {
149
+            $pathsToRequire = $this->memoryCache->get($class);
150
+        }
151
+
152
+        if(class_exists($class, false)) {
153
+            return false;
154
+        }
155
+
156
+        if (!is_array($pathsToRequire)) {
157
+            // No cache or cache miss
158
+            $pathsToRequire = array();
159
+            foreach ($this->findClass($class) as $path) {
160
+                $fullPath = stream_resolve_include_path($path);
161
+                if ($fullPath && $this->isValidPath($fullPath)) {
162
+                    $pathsToRequire[] = $fullPath;
163
+                }
164
+            }
165
+
166
+            if ($this->memoryCache) {
167
+                $this->memoryCache->set($class, $pathsToRequire, 60); // cache 60 sec
168
+            }
169
+        }
170
+
171
+        foreach ($pathsToRequire as $fullPath) {
172
+            require_once $fullPath;
173
+        }
174
+
175
+        return false;
176
+    }
177
+
178
+    /**
179
+     * Sets the optional low-latency cache for class to path mapping.
180
+     *
181
+     * @param \OC\Memcache\Cache $memoryCache Instance of memory cache.
182
+     */
183
+    public function setMemoryCache(\OC\Memcache\Cache $memoryCache = null) {
184
+        $this->memoryCache = $memoryCache;
185
+    }
186 186
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 /**
4 4
  * @copyright Copyright (c) 2016, ownCloud, Inc.
5 5
  *
@@ -100,24 +100,24 @@  discard block
 block discarded – undo
100 100
 			 * Remove "apps/" from inclusion path for smooth migration to multi app dir
101 101
 			 */
102 102
 			if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) {
103
-				\OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG);
103
+				\OCP\Util::writeLog('core', 'include path for class "'.$class.'" starts with "apps/"', \OCP\Util::DEBUG);
104 104
 				$paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]);
105 105
 			}
106 106
 		} elseif (strpos($class, 'OC_') === 0) {
107
-			$paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php');
107
+			$paths[] = \OC::$SERVERROOT.'/lib/private/legacy/'.strtolower(str_replace('_', '/', substr($class, 3)).'.php');
108 108
 		} elseif (strpos($class, 'OCA\\') === 0) {
109 109
 			list(, $app, $rest) = explode('\\', $class, 3);
110 110
 			$app = strtolower($app);
111 111
 			$appPath = \OC_App::getAppPath($app);
112 112
 			if ($appPath && stream_resolve_include_path($appPath)) {
113
-				$paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php');
113
+				$paths[] = $appPath.'/'.strtolower(str_replace('\\', '/', $rest).'.php');
114 114
 				// If not found in the root of the app directory, insert '/lib' after app id and try again.
115
-				$paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php');
115
+				$paths[] = $appPath.'/lib/'.strtolower(str_replace('\\', '/', $rest).'.php');
116 116
 			}
117 117
 		} elseif ($class === 'Test\\TestCase') {
118 118
 			// This File is considered public API, so we make sure that the class
119 119
 			// can still be loaded, although the PSR-4 paths have not been loaded.
120
-			$paths[] = \OC::$SERVERROOT . '/tests/lib/TestCase.php';
120
+			$paths[] = \OC::$SERVERROOT.'/tests/lib/TestCase.php';
121 121
 		}
122 122
 		return $paths;
123 123
 	}
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	protected function isValidPath(string $fullPath): bool {
131 131
 		foreach ($this->validRoots as $root => $true) {
132
-			if (substr($fullPath, 0, strlen($root) + 1) === $root . '/') {
132
+			if (substr($fullPath, 0, strlen($root) + 1) === $root.'/') {
133 133
 				return true;
134 134
 			}
135 135
 		}
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 			$pathsToRequire = $this->memoryCache->get($class);
150 150
 		}
151 151
 
152
-		if(class_exists($class, false)) {
152
+		if (class_exists($class, false)) {
153 153
 			return false;
154 154
 		}
155 155
 
Please login to merge, or discard this patch.