Completed
Push — stable10 ( b85e94...1e5021 )
by
unknown
23:18 queued 12:32
created
lib/private/Lock/MemcacheLockingProvider.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -27,102 +27,102 @@
 block discarded – undo
27 27
 use OCP\IMemcache;
28 28
 
29 29
 class MemcacheLockingProvider extends AbstractLockingProvider {
30
-	/**
31
-	 * @var \OCP\IMemcache
32
-	 */
33
-	private $memcache;
30
+    /**
31
+     * @var \OCP\IMemcache
32
+     */
33
+    private $memcache;
34 34
 
35
-	/**
36
-	 * @param \OCP\IMemcache $memcache
37
-	 * @param int $ttl
38
-	 */
39
-	public function __construct(IMemcache $memcache, $ttl = 3600) {
40
-		$this->memcache = $memcache;
41
-		$this->ttl = $ttl;
42
-	}
35
+    /**
36
+     * @param \OCP\IMemcache $memcache
37
+     * @param int $ttl
38
+     */
39
+    public function __construct(IMemcache $memcache, $ttl = 3600) {
40
+        $this->memcache = $memcache;
41
+        $this->ttl = $ttl;
42
+    }
43 43
 
44
-	private function setTTL($path) {
45
-		if ($this->memcache instanceof IMemcacheTTL) {
46
-			$this->memcache->setTTL($path, $this->ttl);
47
-		}
48
-	}
44
+    private function setTTL($path) {
45
+        if ($this->memcache instanceof IMemcacheTTL) {
46
+            $this->memcache->setTTL($path, $this->ttl);
47
+        }
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $path
52
-	 * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
53
-	 * @return bool
54
-	 */
55
-	public function isLocked($path, $type) {
56
-		$lockValue = $this->memcache->get($path);
57
-		if ($type === self::LOCK_SHARED) {
58
-			return $lockValue > 0;
59
-		} else if ($type === self::LOCK_EXCLUSIVE) {
60
-			return $lockValue === 'exclusive';
61
-		} else {
62
-			return false;
63
-		}
64
-	}
50
+    /**
51
+     * @param string $path
52
+     * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
53
+     * @return bool
54
+     */
55
+    public function isLocked($path, $type) {
56
+        $lockValue = $this->memcache->get($path);
57
+        if ($type === self::LOCK_SHARED) {
58
+            return $lockValue > 0;
59
+        } else if ($type === self::LOCK_EXCLUSIVE) {
60
+            return $lockValue === 'exclusive';
61
+        } else {
62
+            return false;
63
+        }
64
+    }
65 65
 
66
-	/**
67
-	 * @param string $path
68
-	 * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
69
-	 * @throws \OCP\Lock\LockedException
70
-	 */
71
-	public function acquireLock($path, $type) {
72
-		if ($type === self::LOCK_SHARED) {
73
-			if (!$this->memcache->inc($path)) {
74
-				throw new LockedException($path);
75
-			}
76
-		} else {
77
-			$this->memcache->add($path, 0);
78
-			if (!$this->memcache->cas($path, 0, 'exclusive')) {
79
-				throw new LockedException($path);
80
-			}
81
-		}
82
-		$this->setTTL($path);
83
-		$this->markAcquire($path, $type);
84
-	}
66
+    /**
67
+     * @param string $path
68
+     * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
69
+     * @throws \OCP\Lock\LockedException
70
+     */
71
+    public function acquireLock($path, $type) {
72
+        if ($type === self::LOCK_SHARED) {
73
+            if (!$this->memcache->inc($path)) {
74
+                throw new LockedException($path);
75
+            }
76
+        } else {
77
+            $this->memcache->add($path, 0);
78
+            if (!$this->memcache->cas($path, 0, 'exclusive')) {
79
+                throw new LockedException($path);
80
+            }
81
+        }
82
+        $this->setTTL($path);
83
+        $this->markAcquire($path, $type);
84
+    }
85 85
 
86
-	/**
87
-	 * @param string $path
88
-	 * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
89
-	 */
90
-	public function releaseLock($path, $type) {
91
-		if ($type === self::LOCK_SHARED) {
92
-			if ($this->getOwnSharedLockCount($path) === 1) {
93
-				$removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go
94
-				if (!$removed) { //someone else also has a shared lock, decrease only
95
-					$this->memcache->dec($path);
96
-				}
97
-			} else {
98
-				// if we own more than one lock ourselves just decrease
99
-				$this->memcache->dec($path);
100
-			}
101
-		} else if ($type === self::LOCK_EXCLUSIVE) {
102
-			$this->memcache->cad($path, 'exclusive');
103
-		}
104
-		$this->markRelease($path, $type);
105
-	}
86
+    /**
87
+     * @param string $path
88
+     * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
89
+     */
90
+    public function releaseLock($path, $type) {
91
+        if ($type === self::LOCK_SHARED) {
92
+            if ($this->getOwnSharedLockCount($path) === 1) {
93
+                $removed = $this->memcache->cad($path, 1); // if we're the only one having a shared lock we can remove it in one go
94
+                if (!$removed) { //someone else also has a shared lock, decrease only
95
+                    $this->memcache->dec($path);
96
+                }
97
+            } else {
98
+                // if we own more than one lock ourselves just decrease
99
+                $this->memcache->dec($path);
100
+            }
101
+        } else if ($type === self::LOCK_EXCLUSIVE) {
102
+            $this->memcache->cad($path, 'exclusive');
103
+        }
104
+        $this->markRelease($path, $type);
105
+    }
106 106
 
107
-	/**
108
-	 * Change the type of an existing lock
109
-	 *
110
-	 * @param string $path
111
-	 * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE
112
-	 * @throws \OCP\Lock\LockedException
113
-	 */
114
-	public function changeLock($path, $targetType) {
115
-		if ($targetType === self::LOCK_SHARED) {
116
-			if (!$this->memcache->cas($path, 'exclusive', 1)) {
117
-				throw new LockedException($path);
118
-			}
119
-		} else if ($targetType === self::LOCK_EXCLUSIVE) {
120
-			// we can only change a shared lock to an exclusive if there's only a single owner of the shared lock
121
-			if (!$this->memcache->cas($path, 1, 'exclusive')) {
122
-				throw new LockedException($path);
123
-			}
124
-		}
125
-		$this->setTTL($path);
126
-		$this->markChange($path, $targetType);
127
-	}
107
+    /**
108
+     * Change the type of an existing lock
109
+     *
110
+     * @param string $path
111
+     * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE
112
+     * @throws \OCP\Lock\LockedException
113
+     */
114
+    public function changeLock($path, $targetType) {
115
+        if ($targetType === self::LOCK_SHARED) {
116
+            if (!$this->memcache->cas($path, 'exclusive', 1)) {
117
+                throw new LockedException($path);
118
+            }
119
+        } else if ($targetType === self::LOCK_EXCLUSIVE) {
120
+            // we can only change a shared lock to an exclusive if there's only a single owner of the shared lock
121
+            if (!$this->memcache->cas($path, 1, 'exclusive')) {
122
+                throw new LockedException($path);
123
+            }
124
+        }
125
+        $this->setTTL($path);
126
+        $this->markChange($path, $targetType);
127
+    }
128 128
 }
Please login to merge, or discard this patch.
lib/private/Search/Provider/File.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,45 +32,45 @@
 block discarded – undo
32 32
  */
33 33
 class File extends \OCP\Search\Provider {
34 34
 
35
-	/**
36
-	 * Search for files and folders matching the given query
37
-	 * @param string $query
38
-	 * @return \OCP\Search\Result
39
-	 */
40
-	function search($query) {
41
-		$files = Filesystem::search($query);
42
-		$results = array();
43
-		// edit results
44
-		foreach ($files as $fileData) {
45
-			// skip versions
46
-			if (strpos($fileData['path'], '_versions') === 0) {
47
-				continue;
48
-			}
49
-			// skip top-level folder
50
-			if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
51
-				continue;
52
-			}
53
-			// create audio result
54
-			if($fileData['mimepart'] === 'audio'){
55
-				$result = new \OC\Search\Result\Audio($fileData);
56
-			}
57
-			// create image result
58
-			elseif($fileData['mimepart'] === 'image'){
59
-				$result = new \OC\Search\Result\Image($fileData);
60
-			}
61
-			// create folder result
62
-			elseif($fileData['mimetype'] === 'httpd/unix-directory'){
63
-				$result = new \OC\Search\Result\Folder($fileData);
64
-			}
65
-			// or create file result
66
-			else{
67
-				$result = new \OC\Search\Result\File($fileData);
68
-			}
69
-			// add to results
70
-			$results[] = $result;
71
-		}
72
-		// return
73
-		return $results;
74
-	}
35
+    /**
36
+     * Search for files and folders matching the given query
37
+     * @param string $query
38
+     * @return \OCP\Search\Result
39
+     */
40
+    function search($query) {
41
+        $files = Filesystem::search($query);
42
+        $results = array();
43
+        // edit results
44
+        foreach ($files as $fileData) {
45
+            // skip versions
46
+            if (strpos($fileData['path'], '_versions') === 0) {
47
+                continue;
48
+            }
49
+            // skip top-level folder
50
+            if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
51
+                continue;
52
+            }
53
+            // create audio result
54
+            if($fileData['mimepart'] === 'audio'){
55
+                $result = new \OC\Search\Result\Audio($fileData);
56
+            }
57
+            // create image result
58
+            elseif($fileData['mimepart'] === 'image'){
59
+                $result = new \OC\Search\Result\Image($fileData);
60
+            }
61
+            // create folder result
62
+            elseif($fileData['mimetype'] === 'httpd/unix-directory'){
63
+                $result = new \OC\Search\Result\Folder($fileData);
64
+            }
65
+            // or create file result
66
+            else{
67
+                $result = new \OC\Search\Result\File($fileData);
68
+            }
69
+            // add to results
70
+            $results[] = $result;
71
+        }
72
+        // return
73
+        return $results;
74
+    }
75 75
 	
76 76
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -51,19 +51,19 @@
 block discarded – undo
51 51
 				continue;
52 52
 			}
53 53
 			// create audio result
54
-			if($fileData['mimepart'] === 'audio'){
54
+			if ($fileData['mimepart'] === 'audio') {
55 55
 				$result = new \OC\Search\Result\Audio($fileData);
56 56
 			}
57 57
 			// create image result
58
-			elseif($fileData['mimepart'] === 'image'){
58
+			elseif ($fileData['mimepart'] === 'image') {
59 59
 				$result = new \OC\Search\Result\Image($fileData);
60 60
 			}
61 61
 			// create folder result
62
-			elseif($fileData['mimetype'] === 'httpd/unix-directory'){
62
+			elseif ($fileData['mimetype'] === 'httpd/unix-directory') {
63 63
 				$result = new \OC\Search\Result\Folder($fileData);
64 64
 			}
65 65
 			// or create file result
66
-			else{
66
+			else {
67 67
 				$result = new \OC\Search\Result\File($fileData);
68 68
 			}
69 69
 			// add to results
Please login to merge, or discard this patch.
lib/private/Search/Result/Image.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
  */
30 30
 class Image extends File {
31 31
 
32
-	/**
33
-	 * Type name; translated in templates
34
-	 * @var string 
35
-	 */
36
-	public $type = 'image';
32
+    /**
33
+     * Type name; translated in templates
34
+     * @var string 
35
+     */
36
+    public $type = 'image';
37 37
 	
38
-	/**
39
-	 * @TODO add EXIF information
40
-	 */
38
+    /**
39
+     * @TODO add EXIF information
40
+     */
41 41
 }
Please login to merge, or discard this patch.
lib/private/Search/Result/File.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -32,85 +32,85 @@
 block discarded – undo
32 32
  */
33 33
 class File extends \OCP\Search\Result {
34 34
 
35
-	/**
36
-	 * Type name; translated in templates
37
-	 * @var string 
38
-	 */
39
-	public $type = 'file';
35
+    /**
36
+     * Type name; translated in templates
37
+     * @var string 
38
+     */
39
+    public $type = 'file';
40 40
 
41
-	/**
42
-	 * Path to file
43
-	 * @var string
44
-	 */
45
-	public $path;
41
+    /**
42
+     * Path to file
43
+     * @var string
44
+     */
45
+    public $path;
46 46
 
47
-	/**
48
-	 * Size, in bytes
49
-	 * @var int 
50
-	 */
51
-	public $size;
47
+    /**
48
+     * Size, in bytes
49
+     * @var int 
50
+     */
51
+    public $size;
52 52
 
53
-	/**
54
-	 * Date modified, in human readable form
55
-	 * @var string
56
-	 */
57
-	public $modified;
53
+    /**
54
+     * Date modified, in human readable form
55
+     * @var string
56
+     */
57
+    public $modified;
58 58
 
59
-	/**
60
-	 * File mime type
61
-	 * @var string
62
-	 */
63
-	public $mime_type;
59
+    /**
60
+     * File mime type
61
+     * @var string
62
+     */
63
+    public $mime_type;
64 64
 
65
-	/**
66
-	 * File permissions:
67
-	 * 
68
-	 * @var string
69
-	 */
70
-	public $permissions;
65
+    /**
66
+     * File permissions:
67
+     * 
68
+     * @var string
69
+     */
70
+    public $permissions;
71 71
 
72
-	/**
73
-	 * Create a new file search result
74
-	 * @param FileInfo $data file data given by provider
75
-	 */
76
-	public function __construct(FileInfo $data) {
72
+    /**
73
+     * Create a new file search result
74
+     * @param FileInfo $data file data given by provider
75
+     */
76
+    public function __construct(FileInfo $data) {
77 77
 
78
-		$path = $this->getRelativePath($data->getPath());
78
+        $path = $this->getRelativePath($data->getPath());
79 79
 
80
-		$info = pathinfo($path);
81
-		$this->id = $data->getId();
82
-		$this->name = $info['basename'];
83
-		$this->link = \OC::$server->getURLGenerator()->linkToRoute(
84
-			'files.view.index',
85
-			[
86
-				'dir' => $info['dirname'],
87
-				'scrollto' => $info['basename'],
88
-			]
89
-		);
90
-		$this->permissions = $data->getPermissions();
91
-		$this->path = $path;
92
-		$this->size = $data->getSize();
93
-		$this->modified = $data->getMtime();
94
-		$this->mime = $data->getMimetype();
95
-	}
80
+        $info = pathinfo($path);
81
+        $this->id = $data->getId();
82
+        $this->name = $info['basename'];
83
+        $this->link = \OC::$server->getURLGenerator()->linkToRoute(
84
+            'files.view.index',
85
+            [
86
+                'dir' => $info['dirname'],
87
+                'scrollto' => $info['basename'],
88
+            ]
89
+        );
90
+        $this->permissions = $data->getPermissions();
91
+        $this->path = $path;
92
+        $this->size = $data->getSize();
93
+        $this->modified = $data->getMtime();
94
+        $this->mime = $data->getMimetype();
95
+    }
96 96
 
97
-	/**
98
-	 * @var Folder $userFolderCache
99
-	 */
100
-	static protected $userFolderCache = null;
97
+    /**
98
+     * @var Folder $userFolderCache
99
+     */
100
+    static protected $userFolderCache = null;
101 101
 
102
-	/**
103
-	 * converts a path relative to the users files folder
104
-	 * eg /user/files/foo.txt -> /foo.txt
105
-	 * @param string $path
106
-	 * @return string relative path
107
-	 */
108
-	protected function getRelativePath ($path) {
109
-		if (!isset(self::$userFolderCache)) {
110
-			$user = \OC::$server->getUserSession()->getUser()->getUID();
111
-			self::$userFolderCache = \OC::$server->getUserFolder($user);
112
-		}
113
-		return self::$userFolderCache->getRelativePath($path);
114
-	}
102
+    /**
103
+     * converts a path relative to the users files folder
104
+     * eg /user/files/foo.txt -> /foo.txt
105
+     * @param string $path
106
+     * @return string relative path
107
+     */
108
+    protected function getRelativePath ($path) {
109
+        if (!isset(self::$userFolderCache)) {
110
+            $user = \OC::$server->getUserSession()->getUser()->getUID();
111
+            self::$userFolderCache = \OC::$server->getUserFolder($user);
112
+        }
113
+        return self::$userFolderCache->getRelativePath($path);
114
+    }
115 115
 
116 116
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@
 block discarded – undo
105 105
 	 * @param string $path
106 106
 	 * @return string relative path
107 107
 	 */
108
-	protected function getRelativePath ($path) {
108
+	protected function getRelativePath($path) {
109 109
 		if (!isset(self::$userFolderCache)) {
110 110
 			$user = \OC::$server->getUserSession()->getUser()->getUID();
111 111
 			self::$userFolderCache = \OC::$server->getUserFolder($user);
Please login to merge, or discard this patch.
lib/private/Search/Result/Audio.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
  */
30 30
 class Audio extends File {
31 31
 
32
-	/**
33
-	 * Type name; translated in templates
34
-	 * @var string 
35
-	 */
36
-	public $type = 'audio';
32
+    /**
33
+     * Type name; translated in templates
34
+     * @var string 
35
+     */
36
+    public $type = 'audio';
37 37
 	
38
-	/**
39
-	 * @TODO add ID3 information
40
-	 */
38
+    /**
39
+     * @TODO add ID3 information
40
+     */
41 41
 }
Please login to merge, or discard this patch.
lib/private/Search/Result/Folder.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@
 block discarded – undo
29 29
  */
30 30
 class Folder extends File {
31 31
 
32
-	/**
33
-	 * Type name; translated in templates
34
-	 * @var string 
35
-	 */
36
-	public $type = 'folder';
32
+    /**
33
+     * Type name; translated in templates
34
+     * @var string 
35
+     */
36
+    public $type = 'folder';
37 37
 	
38 38
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Utility/SimpleContainer.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -89,17 +89,17 @@  discard block
 block discarded – undo
89 89
 	 * @throws QueryException if the class could not be found or instantiated
90 90
 	 */
91 91
 	public function resolve($name) {
92
-		$baseMsg = 'Could not resolve ' . $name . '!';
92
+		$baseMsg = 'Could not resolve '.$name.'!';
93 93
 		try {
94 94
 			$class = new ReflectionClass($name);
95 95
 			if ($class->isInstantiable()) {
96 96
 				return $this->buildClass($class);
97 97
 			} else {
98
-				throw new QueryException($baseMsg .
98
+				throw new QueryException($baseMsg.
99 99
 					' Class can not be instantiated');
100 100
 			}
101
-		} catch(ReflectionException $e) {
102
-			throw new QueryException($baseMsg . ' ' . $e->getMessage());
101
+		} catch (ReflectionException $e) {
102
+			throw new QueryException($baseMsg.' '.$e->getMessage());
103 103
 		}
104 104
 	}
105 105
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 			return $this->offsetGet($name);
116 116
 		} else {
117 117
 			$object = $this->resolve($name);
118
-			$this->registerService($name, function () use ($object) {
118
+			$this->registerService($name, function() use ($object) {
119 119
 				return $object;
120 120
 			});
121 121
 			return $object;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 */
142 142
 	public function registerService($name, Closure $closure, $shared = true) {
143 143
 		$name = $this->sanitizeName($name);
144
-		if (isset($this[$name]))  {
144
+		if (isset($this[$name])) {
145 145
 			unset($this[$name]);
146 146
 		}
147 147
 		if ($shared) {
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param string $target the target that should be resolved instead
160 160
 	 */
161 161
 	public function registerAlias($alias, $target) {
162
-		$this->registerService($alias, function (IContainer $container) use ($target) {
162
+		$this->registerService($alias, function(IContainer $container) use ($target) {
163 163
 			return $container->query($target);
164 164
 		}, false);
165 165
 	}
Please login to merge, or discard this patch.
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -42,122 +42,122 @@
 block discarded – undo
42 42
 class SimpleContainer extends Container implements IContainer {
43 43
 
44 44
 
45
-	/**
46
-	 * @param ReflectionClass $class the class to instantiate
47
-	 * @return \stdClass the created class
48
-	 */
49
-	private function buildClass(ReflectionClass $class) {
50
-		$constructor = $class->getConstructor();
51
-		if ($constructor === null) {
52
-			return $class->newInstance();
53
-		} else {
54
-			$parameters = [];
55
-			foreach ($constructor->getParameters() as $parameter) {
56
-				$parameterClass = $parameter->getClass();
57
-
58
-				// try to find out if it is a class or a simple parameter
59
-				if ($parameterClass === null) {
60
-					$resolveName = $parameter->getName();
61
-				} else {
62
-					$resolveName = $parameterClass->name;
63
-				}
64
-
65
-				$parameters[] = $this->query($resolveName);
66
-			}
67
-			return $class->newInstanceArgs($parameters);
68
-		}
69
-	}
70
-
71
-
72
-	/**
73
-	 * If a parameter is not registered in the container try to instantiate it
74
-	 * by using reflection to find out how to build the class
75
-	 * @param string $name the class name to resolve
76
-	 * @return \stdClass
77
-	 * @throws QueryException if the class could not be found or instantiated
78
-	 */
79
-	public function resolve($name) {
80
-		$baseMsg = 'Could not resolve ' . $name . '!';
81
-		try {
82
-			$class = new ReflectionClass($name);
83
-			if ($class->isInstantiable()) {
84
-				return $this->buildClass($class);
85
-			} else {
86
-				throw new QueryException($baseMsg .
87
-					' Class can not be instantiated');
88
-			}
89
-		} catch(ReflectionException $e) {
90
-			throw new QueryException($baseMsg . ' ' . $e->getMessage());
91
-		}
92
-	}
93
-
94
-
95
-	/**
96
-	 * @param string $name name of the service to query for
97
-	 * @return mixed registered service for the given $name
98
-	 * @throws QueryException if the query could not be resolved
99
-	 */
100
-	public function query($name) {
101
-		$name = $this->sanitizeName($name);
102
-		if ($this->offsetExists($name)) {
103
-			return $this->offsetGet($name);
104
-		} else {
105
-			$object = $this->resolve($name);
106
-			$this->registerService($name, function () use ($object) {
107
-				return $object;
108
-			});
109
-			return $object;
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * @param string $name
115
-	 * @param mixed $value
116
-	 */
117
-	public function registerParameter($name, $value) {
118
-		$this[$name] = $value;
119
-	}
120
-
121
-	/**
122
-	 * The given closure is call the first time the given service is queried.
123
-	 * The closure has to return the instance for the given service.
124
-	 * Created instance will be cached in case $shared is true.
125
-	 *
126
-	 * @param string $name name of the service to register another backend for
127
-	 * @param Closure $closure the closure to be called on service creation
128
-	 * @param bool $shared
129
-	 */
130
-	public function registerService($name, Closure $closure, $shared = true) {
131
-		$name = $this->sanitizeName($name);
132
-		if (isset($this[$name]))  {
133
-			unset($this[$name]);
134
-		}
135
-		if ($shared) {
136
-			$this[$name] = $closure;
137
-		} else {
138
-			$this[$name] = parent::factory($closure);
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * Shortcut for returning a service from a service under a different key,
144
-	 * e.g. to tell the container to return a class when queried for an
145
-	 * interface
146
-	 * @param string $alias the alias that should be registered
147
-	 * @param string $target the target that should be resolved instead
148
-	 */
149
-	public function registerAlias($alias, $target) {
150
-		$this->registerService($alias, function (IContainer $container) use ($target) {
151
-			return $container->query($target);
152
-		}, false);
153
-	}
154
-
155
-	/*
45
+    /**
46
+     * @param ReflectionClass $class the class to instantiate
47
+     * @return \stdClass the created class
48
+     */
49
+    private function buildClass(ReflectionClass $class) {
50
+        $constructor = $class->getConstructor();
51
+        if ($constructor === null) {
52
+            return $class->newInstance();
53
+        } else {
54
+            $parameters = [];
55
+            foreach ($constructor->getParameters() as $parameter) {
56
+                $parameterClass = $parameter->getClass();
57
+
58
+                // try to find out if it is a class or a simple parameter
59
+                if ($parameterClass === null) {
60
+                    $resolveName = $parameter->getName();
61
+                } else {
62
+                    $resolveName = $parameterClass->name;
63
+                }
64
+
65
+                $parameters[] = $this->query($resolveName);
66
+            }
67
+            return $class->newInstanceArgs($parameters);
68
+        }
69
+    }
70
+
71
+
72
+    /**
73
+     * If a parameter is not registered in the container try to instantiate it
74
+     * by using reflection to find out how to build the class
75
+     * @param string $name the class name to resolve
76
+     * @return \stdClass
77
+     * @throws QueryException if the class could not be found or instantiated
78
+     */
79
+    public function resolve($name) {
80
+        $baseMsg = 'Could not resolve ' . $name . '!';
81
+        try {
82
+            $class = new ReflectionClass($name);
83
+            if ($class->isInstantiable()) {
84
+                return $this->buildClass($class);
85
+            } else {
86
+                throw new QueryException($baseMsg .
87
+                    ' Class can not be instantiated');
88
+            }
89
+        } catch(ReflectionException $e) {
90
+            throw new QueryException($baseMsg . ' ' . $e->getMessage());
91
+        }
92
+    }
93
+
94
+
95
+    /**
96
+     * @param string $name name of the service to query for
97
+     * @return mixed registered service for the given $name
98
+     * @throws QueryException if the query could not be resolved
99
+     */
100
+    public function query($name) {
101
+        $name = $this->sanitizeName($name);
102
+        if ($this->offsetExists($name)) {
103
+            return $this->offsetGet($name);
104
+        } else {
105
+            $object = $this->resolve($name);
106
+            $this->registerService($name, function () use ($object) {
107
+                return $object;
108
+            });
109
+            return $object;
110
+        }
111
+    }
112
+
113
+    /**
114
+     * @param string $name
115
+     * @param mixed $value
116
+     */
117
+    public function registerParameter($name, $value) {
118
+        $this[$name] = $value;
119
+    }
120
+
121
+    /**
122
+     * The given closure is call the first time the given service is queried.
123
+     * The closure has to return the instance for the given service.
124
+     * Created instance will be cached in case $shared is true.
125
+     *
126
+     * @param string $name name of the service to register another backend for
127
+     * @param Closure $closure the closure to be called on service creation
128
+     * @param bool $shared
129
+     */
130
+    public function registerService($name, Closure $closure, $shared = true) {
131
+        $name = $this->sanitizeName($name);
132
+        if (isset($this[$name]))  {
133
+            unset($this[$name]);
134
+        }
135
+        if ($shared) {
136
+            $this[$name] = $closure;
137
+        } else {
138
+            $this[$name] = parent::factory($closure);
139
+        }
140
+    }
141
+
142
+    /**
143
+     * Shortcut for returning a service from a service under a different key,
144
+     * e.g. to tell the container to return a class when queried for an
145
+     * interface
146
+     * @param string $alias the alias that should be registered
147
+     * @param string $target the target that should be resolved instead
148
+     */
149
+    public function registerAlias($alias, $target) {
150
+        $this->registerService($alias, function (IContainer $container) use ($target) {
151
+            return $container->query($target);
152
+        }, false);
153
+    }
154
+
155
+    /*
156 156
 	 * @param string $name
157 157
 	 * @return string
158 158
 	 */
159
-	protected function sanitizeName($name) {
160
-		return ltrim($name, '\\');
161
-	}
159
+    protected function sanitizeName($name) {
160
+        return ltrim($name, '\\');
161
+    }
162 162
 
163 163
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Utility/TimeFactory.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@
 block discarded – undo
34 34
 class TimeFactory implements ITimeFactory {
35 35
 
36 36
 
37
-	/**
38
-	 * @return int the result of a call to time()
39
-	 */
40
-	public function getTime() {
41
-		return time();
42
-	}
37
+    /**
38
+     * @return int the result of a call to time()
39
+     */
40
+    public function getTime() {
41
+        return time();
42
+    }
43 43
 
44 44
 
45 45
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Core/API.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
  * class and add your methods
39 39
  * @deprecated
40 40
  */
41
-class API implements IApi{
41
+class API implements IApi {
42 42
 
43 43
 	private $appName;
44 44
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 * constructor
47 47
 	 * @param string $appName the name of your application
48 48
 	 */
49
-	public function __construct($appName){
49
+	public function __construct($appName) {
50 50
 		$this->appName = $appName;
51 51
 	}
52 52
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	 * @return string the user id of the current user
57 57
 	 * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID()
58 58
 	 */
59
-	public function getUserId(){
59
+	public function getUserId() {
60 60
 		return \OCP\User::getUser();
61 61
 	}
62 62
 
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 	 * @param string $scriptName the name of the javascript in js/ without the suffix
68 68
 	 * @param string $appName the name of the app, defaults to the current one
69 69
 	 */
70
-	public function addScript($scriptName, $appName=null){
71
-		if($appName === null){
70
+	public function addScript($scriptName, $appName = null) {
71
+		if ($appName === null) {
72 72
 			$appName = $this->appName;
73 73
 		}
74 74
 		\OCP\Util::addScript($appName, $scriptName);
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 	 * @param string $styleName the name of the css file in css/without the suffix
82 82
 	 * @param string $appName the name of the app, defaults to the current one
83 83
 	 */
84
-	public function addStyle($styleName, $appName=null){
85
-		if($appName === null){
84
+	public function addStyle($styleName, $appName = null) {
85
+		if ($appName === null) {
86 86
 			$appName = $this->appName;
87 87
 		}
88 88
 		\OCP\Util::addStyle($appName, $styleName);
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 	 * shorthand for addScript for files in the 3rdparty directory
95 95
 	 * @param string $name the name of the file without the suffix
96 96
 	 */
97
-	public function add3rdPartyScript($name){
98
-		\OCP\Util::addScript($this->appName . '/3rdparty', $name);
97
+	public function add3rdPartyScript($name) {
98
+		\OCP\Util::addScript($this->appName.'/3rdparty', $name);
99 99
 	}
100 100
 
101 101
 
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 * shorthand for addStyle for files in the 3rdparty directory
105 105
 	 * @param string $name the name of the file without the suffix
106 106
 	 */
107
-	public function add3rdPartyStyle($name){
108
-		\OCP\Util::addStyle($this->appName . '/3rdparty', $name);
107
+	public function add3rdPartyStyle($name) {
108
+		\OCP\Util::addStyle($this->appName.'/3rdparty', $name);
109 109
 	}
110 110
 
111 111
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * @param string $appName the name of an app
118 118
 	 * @return bool true if app is enabled
119 119
 	 */
120
-	public function isAppEnabled($appName){
120
+	public function isAppEnabled($appName) {
121 121
 		return \OCP\App::isEnabled($appName);
122 122
 	}
123 123
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	 * @return \OCP\IEventSource a new open EventSource class
128 128
 	 * @deprecated Use \OC::$server->createEventSource();
129 129
 	 */
130
-	public function openEventSource(){
130
+	public function openEventSource() {
131 131
 		return \OC::$server->createEventSource();
132 132
 	}
133 133
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @param string $signalClass
165 165
 	 * @param string $signalName
166 166
 	 */
167
-	public function clearHook($signalClass=false, $signalName=false) {
167
+	public function clearHook($signalClass = false, $signalName = false) {
168 168
 		if ($signalClass) {
169 169
 			\OC_Hook::clear($signalClass, $signalName);
170 170
 		}
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 	 * suffix, relative to your apps directory! not the template directory
177 177
 	 * @param string $appName the name of the app, defaults to the current one
178 178
 	 */
179
-	public function registerAdmin($mainPath, $appName=null) {
180
-		if($appName === null){
179
+	public function registerAdmin($mainPath, $appName = null) {
180
+		if ($appName === null) {
181 181
 			$appName = $this->appName;
182 182
 		}
183 183
 
Please login to merge, or discard this patch.
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -40,162 +40,162 @@
 block discarded – undo
40 40
  */
41 41
 class API implements IApi{
42 42
 
43
-	private $appName;
44
-
45
-	/**
46
-	 * constructor
47
-	 * @param string $appName the name of your application
48
-	 */
49
-	public function __construct($appName){
50
-		$this->appName = $appName;
51
-	}
52
-
53
-
54
-	/**
55
-	 * Gets the userid of the current user
56
-	 * @return string the user id of the current user
57
-	 * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID()
58
-	 */
59
-	public function getUserId(){
60
-		return \OCP\User::getUser();
61
-	}
62
-
63
-
64
-	/**
65
-	 * Adds a new javascript file
66
-	 * @deprecated include javascript and css in template files
67
-	 * @param string $scriptName the name of the javascript in js/ without the suffix
68
-	 * @param string $appName the name of the app, defaults to the current one
69
-	 */
70
-	public function addScript($scriptName, $appName=null){
71
-		if($appName === null){
72
-			$appName = $this->appName;
73
-		}
74
-		\OCP\Util::addScript($appName, $scriptName);
75
-	}
76
-
77
-
78
-	/**
79
-	 * Adds a new css file
80
-	 * @deprecated include javascript and css in template files
81
-	 * @param string $styleName the name of the css file in css/without the suffix
82
-	 * @param string $appName the name of the app, defaults to the current one
83
-	 */
84
-	public function addStyle($styleName, $appName=null){
85
-		if($appName === null){
86
-			$appName = $this->appName;
87
-		}
88
-		\OCP\Util::addStyle($appName, $styleName);
89
-	}
90
-
91
-
92
-	/**
93
-	 * @deprecated include javascript and css in template files
94
-	 * shorthand for addScript for files in the 3rdparty directory
95
-	 * @param string $name the name of the file without the suffix
96
-	 */
97
-	public function add3rdPartyScript($name){
98
-		\OCP\Util::addScript($this->appName . '/3rdparty', $name);
99
-	}
100
-
101
-
102
-	/**
103
-	 * @deprecated include javascript and css in template files
104
-	 * shorthand for addStyle for files in the 3rdparty directory
105
-	 * @param string $name the name of the file without the suffix
106
-	 */
107
-	public function add3rdPartyStyle($name){
108
-		\OCP\Util::addStyle($this->appName . '/3rdparty', $name);
109
-	}
110
-
111
-
112
-	/**
113
-	 * @deprecated communication between apps should happen over built in
114
-	 * callbacks or interfaces (check the contacts and calendar managers)
115
-	 * Checks if an app is enabled
116
-	 * also use \OC::$server->getAppManager()->isEnabledForUser($appName)
117
-	 * @param string $appName the name of an app
118
-	 * @return bool true if app is enabled
119
-	 */
120
-	public function isAppEnabled($appName){
121
-		return \OCP\App::isEnabled($appName);
122
-	}
123
-
124
-
125
-	/**
126
-	 * used to return and open a new event source
127
-	 * @return \OCP\IEventSource a new open EventSource class
128
-	 * @deprecated Use \OC::$server->createEventSource();
129
-	 */
130
-	public function openEventSource(){
131
-		return \OC::$server->createEventSource();
132
-	}
133
-
134
-	/**
135
-	 * @deprecated register hooks directly for class that build in hook interfaces
136
-	 * connects a function to a hook
137
-	 * @param string $signalClass class name of emitter
138
-	 * @param string $signalName name of signal
139
-	 * @param string $slotClass class name of slot
140
-	 * @param string $slotName name of slot, in another word, this is the
141
-	 *               name of the method that will be called when registered
142
-	 *               signal is emitted.
143
-	 * @return bool always true
144
-	 */
145
-	public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
146
-		return \OCP\Util::connectHook($signalClass, $signalName, $slotClass, $slotName);
147
-	}
148
-
149
-	/**
150
-	 * @deprecated implement the emitter interface instead
151
-	 * Emits a signal. To get data from the slot use references!
152
-	 * @param string $signalClass class name of emitter
153
-	 * @param string $signalName name of signal
154
-	 * @param array $params default: array() array with additional data
155
-	 * @return bool true if slots exists or false if not
156
-	 */
157
-	public function emitHook($signalClass, $signalName, $params = array()) {
158
-		return  \OCP\Util::emitHook($signalClass, $signalName, $params);
159
-	}
160
-
161
-	/**
162
-	 * clear hooks
163
-	 * @deprecated clear hooks directly for class that build in hook interfaces
164
-	 * @param string $signalClass
165
-	 * @param string $signalName
166
-	 */
167
-	public function clearHook($signalClass=false, $signalName=false) {
168
-		if ($signalClass) {
169
-			\OC_Hook::clear($signalClass, $signalName);
170
-		}
171
-	}
172
-
173
-
174
-	/**
175
-	 * Register a backgroundjob task
176
-	 * @param string $className full namespace and class name of the class
177
-	 * @param string $methodName the name of the static method that should be
178
-	 * called
179
-	 * @deprecated Use \OC::$server->getJobList()->add();
180
-	 */
181
-	public function addRegularTask($className, $methodName) {
182
-		\OCP\Backgroundjob::addRegularTask($className, $methodName);
183
-	}
184
-
185
-
186
-	/**
187
-	 * Tells ownCloud to include a template in the admin overview
188
-	 * @param string $mainPath the path to the main php file without the php
189
-	 * suffix, relative to your apps directory! not the template directory
190
-	 * @param string $appName the name of the app, defaults to the current one
191
-	 */
192
-	public function registerAdmin($mainPath, $appName=null) {
193
-		if($appName === null){
194
-			$appName = $this->appName;
195
-		}
196
-
197
-		\OCP\App::registerAdmin($appName, $mainPath);
198
-	}
43
+    private $appName;
44
+
45
+    /**
46
+     * constructor
47
+     * @param string $appName the name of your application
48
+     */
49
+    public function __construct($appName){
50
+        $this->appName = $appName;
51
+    }
52
+
53
+
54
+    /**
55
+     * Gets the userid of the current user
56
+     * @return string the user id of the current user
57
+     * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID()
58
+     */
59
+    public function getUserId(){
60
+        return \OCP\User::getUser();
61
+    }
62
+
63
+
64
+    /**
65
+     * Adds a new javascript file
66
+     * @deprecated include javascript and css in template files
67
+     * @param string $scriptName the name of the javascript in js/ without the suffix
68
+     * @param string $appName the name of the app, defaults to the current one
69
+     */
70
+    public function addScript($scriptName, $appName=null){
71
+        if($appName === null){
72
+            $appName = $this->appName;
73
+        }
74
+        \OCP\Util::addScript($appName, $scriptName);
75
+    }
76
+
77
+
78
+    /**
79
+     * Adds a new css file
80
+     * @deprecated include javascript and css in template files
81
+     * @param string $styleName the name of the css file in css/without the suffix
82
+     * @param string $appName the name of the app, defaults to the current one
83
+     */
84
+    public function addStyle($styleName, $appName=null){
85
+        if($appName === null){
86
+            $appName = $this->appName;
87
+        }
88
+        \OCP\Util::addStyle($appName, $styleName);
89
+    }
90
+
91
+
92
+    /**
93
+     * @deprecated include javascript and css in template files
94
+     * shorthand for addScript for files in the 3rdparty directory
95
+     * @param string $name the name of the file without the suffix
96
+     */
97
+    public function add3rdPartyScript($name){
98
+        \OCP\Util::addScript($this->appName . '/3rdparty', $name);
99
+    }
100
+
101
+
102
+    /**
103
+     * @deprecated include javascript and css in template files
104
+     * shorthand for addStyle for files in the 3rdparty directory
105
+     * @param string $name the name of the file without the suffix
106
+     */
107
+    public function add3rdPartyStyle($name){
108
+        \OCP\Util::addStyle($this->appName . '/3rdparty', $name);
109
+    }
110
+
111
+
112
+    /**
113
+     * @deprecated communication between apps should happen over built in
114
+     * callbacks or interfaces (check the contacts and calendar managers)
115
+     * Checks if an app is enabled
116
+     * also use \OC::$server->getAppManager()->isEnabledForUser($appName)
117
+     * @param string $appName the name of an app
118
+     * @return bool true if app is enabled
119
+     */
120
+    public function isAppEnabled($appName){
121
+        return \OCP\App::isEnabled($appName);
122
+    }
123
+
124
+
125
+    /**
126
+     * used to return and open a new event source
127
+     * @return \OCP\IEventSource a new open EventSource class
128
+     * @deprecated Use \OC::$server->createEventSource();
129
+     */
130
+    public function openEventSource(){
131
+        return \OC::$server->createEventSource();
132
+    }
133
+
134
+    /**
135
+     * @deprecated register hooks directly for class that build in hook interfaces
136
+     * connects a function to a hook
137
+     * @param string $signalClass class name of emitter
138
+     * @param string $signalName name of signal
139
+     * @param string $slotClass class name of slot
140
+     * @param string $slotName name of slot, in another word, this is the
141
+     *               name of the method that will be called when registered
142
+     *               signal is emitted.
143
+     * @return bool always true
144
+     */
145
+    public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
146
+        return \OCP\Util::connectHook($signalClass, $signalName, $slotClass, $slotName);
147
+    }
148
+
149
+    /**
150
+     * @deprecated implement the emitter interface instead
151
+     * Emits a signal. To get data from the slot use references!
152
+     * @param string $signalClass class name of emitter
153
+     * @param string $signalName name of signal
154
+     * @param array $params default: array() array with additional data
155
+     * @return bool true if slots exists or false if not
156
+     */
157
+    public function emitHook($signalClass, $signalName, $params = array()) {
158
+        return  \OCP\Util::emitHook($signalClass, $signalName, $params);
159
+    }
160
+
161
+    /**
162
+     * clear hooks
163
+     * @deprecated clear hooks directly for class that build in hook interfaces
164
+     * @param string $signalClass
165
+     * @param string $signalName
166
+     */
167
+    public function clearHook($signalClass=false, $signalName=false) {
168
+        if ($signalClass) {
169
+            \OC_Hook::clear($signalClass, $signalName);
170
+        }
171
+    }
172
+
173
+
174
+    /**
175
+     * Register a backgroundjob task
176
+     * @param string $className full namespace and class name of the class
177
+     * @param string $methodName the name of the static method that should be
178
+     * called
179
+     * @deprecated Use \OC::$server->getJobList()->add();
180
+     */
181
+    public function addRegularTask($className, $methodName) {
182
+        \OCP\Backgroundjob::addRegularTask($className, $methodName);
183
+    }
184
+
185
+
186
+    /**
187
+     * Tells ownCloud to include a template in the admin overview
188
+     * @param string $mainPath the path to the main php file without the php
189
+     * suffix, relative to your apps directory! not the template directory
190
+     * @param string $appName the name of the app, defaults to the current one
191
+     */
192
+    public function registerAdmin($mainPath, $appName=null) {
193
+        if($appName === null){
194
+            $appName = $this->appName;
195
+        }
196
+
197
+        \OCP\App::registerAdmin($appName, $mainPath);
198
+    }
199 199
 
200 200
 
201 201
 }
Please login to merge, or discard this patch.