@@ -35,35 +35,35 @@ |
||
35 | 35 | /** |
36 | 36 | * {@inheritdoc} |
37 | 37 | */ |
38 | - public function isLocked($path, $type) { |
|
39 | - return false; |
|
40 | - } |
|
38 | + public function isLocked($path, $type) { |
|
39 | + return false; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * {@inheritdoc} |
44 | 44 | */ |
45 | - public function acquireLock($path, $type) { |
|
46 | - // do nothing |
|
47 | - } |
|
45 | + public function acquireLock($path, $type) { |
|
46 | + // do nothing |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
49 | + /** |
|
50 | 50 | * {@inheritdoc} |
51 | - */ |
|
52 | - public function releaseLock($path, $type) { |
|
53 | - // do nothing |
|
54 | - } |
|
51 | + */ |
|
52 | + public function releaseLock($path, $type) { |
|
53 | + // do nothing |
|
54 | + } |
|
55 | 55 | |
56 | - /**1 |
|
56 | + /**1 |
|
57 | 57 | * {@inheritdoc} |
58 | 58 | */ |
59 | - public function releaseAll() { |
|
60 | - // do nothing |
|
61 | - } |
|
59 | + public function releaseAll() { |
|
60 | + // do nothing |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - public function changeLock($path, $targetType) { |
|
67 | - // do nothing |
|
68 | - } |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + public function changeLock($path, $targetType) { |
|
67 | + // do nothing |
|
68 | + } |
|
69 | 69 | } |
@@ -29,99 +29,99 @@ |
||
29 | 29 | * to release any left over locks at the end of the request |
30 | 30 | */ |
31 | 31 | abstract class AbstractLockingProvider implements ILockingProvider { |
32 | - protected $ttl; // how long until we clear stray locks in seconds |
|
32 | + protected $ttl; // how long until we clear stray locks in seconds |
|
33 | 33 | |
34 | - protected $acquiredLocks = [ |
|
35 | - 'shared' => [], |
|
36 | - 'exclusive' => [] |
|
37 | - ]; |
|
34 | + protected $acquiredLocks = [ |
|
35 | + 'shared' => [], |
|
36 | + 'exclusive' => [] |
|
37 | + ]; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Check if we've locally acquired a lock |
|
41 | - * |
|
42 | - * @param string $path |
|
43 | - * @param int $type |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - protected function hasAcquiredLock($path, $type) { |
|
47 | - if ($type === self::LOCK_SHARED) { |
|
48 | - return isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 0; |
|
49 | - } else { |
|
50 | - return isset($this->acquiredLocks['exclusive'][$path]) && $this->acquiredLocks['exclusive'][$path] === true; |
|
51 | - } |
|
52 | - } |
|
39 | + /** |
|
40 | + * Check if we've locally acquired a lock |
|
41 | + * |
|
42 | + * @param string $path |
|
43 | + * @param int $type |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + protected function hasAcquiredLock($path, $type) { |
|
47 | + if ($type === self::LOCK_SHARED) { |
|
48 | + return isset($this->acquiredLocks['shared'][$path]) && $this->acquiredLocks['shared'][$path] > 0; |
|
49 | + } else { |
|
50 | + return isset($this->acquiredLocks['exclusive'][$path]) && $this->acquiredLocks['exclusive'][$path] === true; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Mark a locally acquired lock |
|
56 | - * |
|
57 | - * @param string $path |
|
58 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
59 | - */ |
|
60 | - protected function markAcquire($path, $type) { |
|
61 | - if ($type === self::LOCK_SHARED) { |
|
62 | - if (!isset($this->acquiredLocks['shared'][$path])) { |
|
63 | - $this->acquiredLocks['shared'][$path] = 0; |
|
64 | - } |
|
65 | - $this->acquiredLocks['shared'][$path]++; |
|
66 | - } else { |
|
67 | - $this->acquiredLocks['exclusive'][$path] = true; |
|
68 | - } |
|
69 | - } |
|
54 | + /** |
|
55 | + * Mark a locally acquired lock |
|
56 | + * |
|
57 | + * @param string $path |
|
58 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
59 | + */ |
|
60 | + protected function markAcquire($path, $type) { |
|
61 | + if ($type === self::LOCK_SHARED) { |
|
62 | + if (!isset($this->acquiredLocks['shared'][$path])) { |
|
63 | + $this->acquiredLocks['shared'][$path] = 0; |
|
64 | + } |
|
65 | + $this->acquiredLocks['shared'][$path]++; |
|
66 | + } else { |
|
67 | + $this->acquiredLocks['exclusive'][$path] = true; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Mark a release of a locally acquired lock |
|
73 | - * |
|
74 | - * @param string $path |
|
75 | - * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
76 | - */ |
|
77 | - protected function markRelease($path, $type) { |
|
78 | - if ($type === self::LOCK_SHARED) { |
|
79 | - if (isset($this->acquiredLocks['shared'][$path]) and $this->acquiredLocks['shared'][$path] > 0) { |
|
80 | - $this->acquiredLocks['shared'][$path]--; |
|
81 | - if ($this->acquiredLocks['shared'][$path] === 0) { |
|
82 | - unset($this->acquiredLocks['shared'][$path]); |
|
83 | - } |
|
84 | - } |
|
85 | - } else if ($type === self::LOCK_EXCLUSIVE) { |
|
86 | - unset($this->acquiredLocks['exclusive'][$path]); |
|
87 | - } |
|
88 | - } |
|
71 | + /** |
|
72 | + * Mark a release of a locally acquired lock |
|
73 | + * |
|
74 | + * @param string $path |
|
75 | + * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
76 | + */ |
|
77 | + protected function markRelease($path, $type) { |
|
78 | + if ($type === self::LOCK_SHARED) { |
|
79 | + if (isset($this->acquiredLocks['shared'][$path]) and $this->acquiredLocks['shared'][$path] > 0) { |
|
80 | + $this->acquiredLocks['shared'][$path]--; |
|
81 | + if ($this->acquiredLocks['shared'][$path] === 0) { |
|
82 | + unset($this->acquiredLocks['shared'][$path]); |
|
83 | + } |
|
84 | + } |
|
85 | + } else if ($type === self::LOCK_EXCLUSIVE) { |
|
86 | + unset($this->acquiredLocks['exclusive'][$path]); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Change the type of an existing tracked lock |
|
92 | - * |
|
93 | - * @param string $path |
|
94 | - * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | - */ |
|
96 | - protected function markChange($path, $targetType) { |
|
97 | - if ($targetType === self::LOCK_SHARED) { |
|
98 | - unset($this->acquiredLocks['exclusive'][$path]); |
|
99 | - if (!isset($this->acquiredLocks['shared'][$path])) { |
|
100 | - $this->acquiredLocks['shared'][$path] = 0; |
|
101 | - } |
|
102 | - $this->acquiredLocks['shared'][$path]++; |
|
103 | - } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
104 | - $this->acquiredLocks['exclusive'][$path] = true; |
|
105 | - $this->acquiredLocks['shared'][$path]--; |
|
106 | - } |
|
107 | - } |
|
90 | + /** |
|
91 | + * Change the type of an existing tracked lock |
|
92 | + * |
|
93 | + * @param string $path |
|
94 | + * @param int $targetType self::LOCK_SHARED or self::LOCK_EXCLUSIVE |
|
95 | + */ |
|
96 | + protected function markChange($path, $targetType) { |
|
97 | + if ($targetType === self::LOCK_SHARED) { |
|
98 | + unset($this->acquiredLocks['exclusive'][$path]); |
|
99 | + if (!isset($this->acquiredLocks['shared'][$path])) { |
|
100 | + $this->acquiredLocks['shared'][$path] = 0; |
|
101 | + } |
|
102 | + $this->acquiredLocks['shared'][$path]++; |
|
103 | + } else if ($targetType === self::LOCK_EXCLUSIVE) { |
|
104 | + $this->acquiredLocks['exclusive'][$path] = true; |
|
105 | + $this->acquiredLocks['shared'][$path]--; |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * release all lock acquired by this instance which were marked using the mark* methods |
|
111 | - */ |
|
112 | - public function releaseAll() { |
|
113 | - foreach ($this->acquiredLocks['shared'] as $path => $count) { |
|
114 | - for ($i = 0; $i < $count; $i++) { |
|
115 | - $this->releaseLock($path, self::LOCK_SHARED); |
|
116 | - } |
|
117 | - } |
|
109 | + /** |
|
110 | + * release all lock acquired by this instance which were marked using the mark* methods |
|
111 | + */ |
|
112 | + public function releaseAll() { |
|
113 | + foreach ($this->acquiredLocks['shared'] as $path => $count) { |
|
114 | + for ($i = 0; $i < $count; $i++) { |
|
115 | + $this->releaseLock($path, self::LOCK_SHARED); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - foreach ($this->acquiredLocks['exclusive'] as $path => $hasLock) { |
|
120 | - $this->releaseLock($path, self::LOCK_EXCLUSIVE); |
|
121 | - } |
|
122 | - } |
|
119 | + foreach ($this->acquiredLocks['exclusive'] as $path => $hasLock) { |
|
120 | + $this->releaseLock($path, self::LOCK_EXCLUSIVE); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - protected function getOwnSharedLockCount($path) { |
|
125 | - return isset($this->acquiredLocks['shared'][$path]) ? $this->acquiredLocks['shared'][$path] : 0; |
|
126 | - } |
|
124 | + protected function getOwnSharedLockCount($path) { |
|
125 | + return isset($this->acquiredLocks['shared'][$path]) ? $this->acquiredLocks['shared'][$path] : 0; |
|
126 | + } |
|
127 | 127 | } |
@@ -29,13 +29,13 @@ |
||
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 | } |
@@ -29,13 +29,13 @@ |
||
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 | } |
@@ -29,10 +29,10 @@ |
||
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 | } |
@@ -40,66 +40,66 @@ |
||
40 | 40 | */ |
41 | 41 | class AvatarManager implements IAvatarManager { |
42 | 42 | |
43 | - /** @var IUserManager */ |
|
44 | - private $userManager; |
|
43 | + /** @var IUserManager */ |
|
44 | + private $userManager; |
|
45 | 45 | |
46 | - /** @var IAppData */ |
|
47 | - private $appData; |
|
46 | + /** @var IAppData */ |
|
47 | + private $appData; |
|
48 | 48 | |
49 | - /** @var IL10N */ |
|
50 | - private $l; |
|
49 | + /** @var IL10N */ |
|
50 | + private $l; |
|
51 | 51 | |
52 | - /** @var ILogger */ |
|
53 | - private $logger; |
|
52 | + /** @var ILogger */ |
|
53 | + private $logger; |
|
54 | 54 | |
55 | - /** @var IConfig */ |
|
56 | - private $config; |
|
55 | + /** @var IConfig */ |
|
56 | + private $config; |
|
57 | 57 | |
58 | - /** |
|
59 | - * AvatarManager constructor. |
|
60 | - * |
|
61 | - * @param IUserManager $userManager |
|
62 | - * @param IAppData $appData |
|
63 | - * @param IL10N $l |
|
64 | - * @param ILogger $logger |
|
65 | - * @param IConfig $config |
|
66 | - */ |
|
67 | - public function __construct( |
|
68 | - IUserManager $userManager, |
|
69 | - IAppData $appData, |
|
70 | - IL10N $l, |
|
71 | - ILogger $logger, |
|
72 | - IConfig $config) { |
|
73 | - $this->userManager = $userManager; |
|
74 | - $this->appData = $appData; |
|
75 | - $this->l = $l; |
|
76 | - $this->logger = $logger; |
|
77 | - $this->config = $config; |
|
78 | - } |
|
58 | + /** |
|
59 | + * AvatarManager constructor. |
|
60 | + * |
|
61 | + * @param IUserManager $userManager |
|
62 | + * @param IAppData $appData |
|
63 | + * @param IL10N $l |
|
64 | + * @param ILogger $logger |
|
65 | + * @param IConfig $config |
|
66 | + */ |
|
67 | + public function __construct( |
|
68 | + IUserManager $userManager, |
|
69 | + IAppData $appData, |
|
70 | + IL10N $l, |
|
71 | + ILogger $logger, |
|
72 | + IConfig $config) { |
|
73 | + $this->userManager = $userManager; |
|
74 | + $this->appData = $appData; |
|
75 | + $this->l = $l; |
|
76 | + $this->logger = $logger; |
|
77 | + $this->config = $config; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * return a user specific instance of \OCP\IAvatar |
|
82 | - * @see \OCP\IAvatar |
|
83 | - * @param string $userId the ownCloud user id |
|
84 | - * @return \OCP\IAvatar |
|
85 | - * @throws \Exception In case the username is potentially dangerous |
|
86 | - * @throws NotFoundException In case there is no user folder yet |
|
87 | - */ |
|
88 | - public function getAvatar($userId) { |
|
89 | - $user = $this->userManager->get($userId); |
|
90 | - if (is_null($user)) { |
|
91 | - throw new \Exception('user does not exist'); |
|
92 | - } |
|
80 | + /** |
|
81 | + * return a user specific instance of \OCP\IAvatar |
|
82 | + * @see \OCP\IAvatar |
|
83 | + * @param string $userId the ownCloud user id |
|
84 | + * @return \OCP\IAvatar |
|
85 | + * @throws \Exception In case the username is potentially dangerous |
|
86 | + * @throws NotFoundException In case there is no user folder yet |
|
87 | + */ |
|
88 | + public function getAvatar($userId) { |
|
89 | + $user = $this->userManager->get($userId); |
|
90 | + if (is_null($user)) { |
|
91 | + throw new \Exception('user does not exist'); |
|
92 | + } |
|
93 | 93 | |
94 | - // sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below) |
|
95 | - $userId = $user->getUID(); |
|
94 | + // sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below) |
|
95 | + $userId = $user->getUID(); |
|
96 | 96 | |
97 | - try { |
|
98 | - $folder = $this->appData->getFolder($userId); |
|
99 | - } catch (NotFoundException $e) { |
|
100 | - $folder = $this->appData->newFolder($userId); |
|
101 | - } |
|
97 | + try { |
|
98 | + $folder = $this->appData->getFolder($userId); |
|
99 | + } catch (NotFoundException $e) { |
|
100 | + $folder = $this->appData->newFolder($userId); |
|
101 | + } |
|
102 | 102 | |
103 | - return new Avatar($folder, $this->l, $user, $this->logger, $this->config); |
|
104 | - } |
|
103 | + return new Avatar($folder, $this->l, $user, $this->logger, $this->config); |
|
104 | + } |
|
105 | 105 | } |
@@ -42,137 +42,137 @@ |
||
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 | - try { |
|
66 | - $parameters[] = $this->query($resolveName); |
|
67 | - } catch (\Exception $e) { |
|
68 | - // Service not found, use the default value when available |
|
69 | - if ($parameter->isDefaultValueAvailable()) { |
|
70 | - $parameters[] = $parameter->getDefaultValue(); |
|
71 | - } else if ($parameterClass !== null) { |
|
72 | - $resolveName = $parameter->getName(); |
|
73 | - $parameters[] = $this->query($resolveName); |
|
74 | - } else { |
|
75 | - throw $e; |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
79 | - return $class->newInstanceArgs($parameters); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * If a parameter is not registered in the container try to instantiate it |
|
86 | - * by using reflection to find out how to build the class |
|
87 | - * @param string $name the class name to resolve |
|
88 | - * @return \stdClass |
|
89 | - * @throws QueryException if the class could not be found or instantiated |
|
90 | - */ |
|
91 | - public function resolve($name) { |
|
92 | - $baseMsg = 'Could not resolve ' . $name . '!'; |
|
93 | - try { |
|
94 | - $class = new ReflectionClass($name); |
|
95 | - if ($class->isInstantiable()) { |
|
96 | - return $this->buildClass($class); |
|
97 | - } else { |
|
98 | - throw new QueryException($baseMsg . |
|
99 | - ' Class can not be instantiated'); |
|
100 | - } |
|
101 | - } catch(ReflectionException $e) { |
|
102 | - throw new QueryException($baseMsg . ' ' . $e->getMessage()); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param string $name name of the service to query for |
|
109 | - * @return mixed registered service for the given $name |
|
110 | - * @throws QueryException if the query could not be resolved |
|
111 | - */ |
|
112 | - public function query($name) { |
|
113 | - $name = $this->sanitizeName($name); |
|
114 | - if ($this->offsetExists($name)) { |
|
115 | - return $this->offsetGet($name); |
|
116 | - } else { |
|
117 | - $object = $this->resolve($name); |
|
118 | - $this->registerService($name, function () use ($object) { |
|
119 | - return $object; |
|
120 | - }); |
|
121 | - return $object; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $name |
|
127 | - * @param mixed $value |
|
128 | - */ |
|
129 | - public function registerParameter($name, $value) { |
|
130 | - $this[$name] = $value; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * The given closure is call the first time the given service is queried. |
|
135 | - * The closure has to return the instance for the given service. |
|
136 | - * Created instance will be cached in case $shared is true. |
|
137 | - * |
|
138 | - * @param string $name name of the service to register another backend for |
|
139 | - * @param Closure $closure the closure to be called on service creation |
|
140 | - * @param bool $shared |
|
141 | - */ |
|
142 | - public function registerService($name, Closure $closure, $shared = true) { |
|
143 | - $name = $this->sanitizeName($name); |
|
144 | - if (isset($this[$name])) { |
|
145 | - unset($this[$name]); |
|
146 | - } |
|
147 | - if ($shared) { |
|
148 | - $this[$name] = $closure; |
|
149 | - } else { |
|
150 | - $this[$name] = parent::factory($closure); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Shortcut for returning a service from a service under a different key, |
|
156 | - * e.g. to tell the container to return a class when queried for an |
|
157 | - * interface |
|
158 | - * @param string $alias the alias that should be registered |
|
159 | - * @param string $target the target that should be resolved instead |
|
160 | - */ |
|
161 | - public function registerAlias($alias, $target) { |
|
162 | - $this->registerService($alias, function (IContainer $container) use ($target) { |
|
163 | - return $container->query($target); |
|
164 | - }, false); |
|
165 | - } |
|
166 | - |
|
167 | - /* |
|
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 | + try { |
|
66 | + $parameters[] = $this->query($resolveName); |
|
67 | + } catch (\Exception $e) { |
|
68 | + // Service not found, use the default value when available |
|
69 | + if ($parameter->isDefaultValueAvailable()) { |
|
70 | + $parameters[] = $parameter->getDefaultValue(); |
|
71 | + } else if ($parameterClass !== null) { |
|
72 | + $resolveName = $parameter->getName(); |
|
73 | + $parameters[] = $this->query($resolveName); |
|
74 | + } else { |
|
75 | + throw $e; |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | + return $class->newInstanceArgs($parameters); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * If a parameter is not registered in the container try to instantiate it |
|
86 | + * by using reflection to find out how to build the class |
|
87 | + * @param string $name the class name to resolve |
|
88 | + * @return \stdClass |
|
89 | + * @throws QueryException if the class could not be found or instantiated |
|
90 | + */ |
|
91 | + public function resolve($name) { |
|
92 | + $baseMsg = 'Could not resolve ' . $name . '!'; |
|
93 | + try { |
|
94 | + $class = new ReflectionClass($name); |
|
95 | + if ($class->isInstantiable()) { |
|
96 | + return $this->buildClass($class); |
|
97 | + } else { |
|
98 | + throw new QueryException($baseMsg . |
|
99 | + ' Class can not be instantiated'); |
|
100 | + } |
|
101 | + } catch(ReflectionException $e) { |
|
102 | + throw new QueryException($baseMsg . ' ' . $e->getMessage()); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param string $name name of the service to query for |
|
109 | + * @return mixed registered service for the given $name |
|
110 | + * @throws QueryException if the query could not be resolved |
|
111 | + */ |
|
112 | + public function query($name) { |
|
113 | + $name = $this->sanitizeName($name); |
|
114 | + if ($this->offsetExists($name)) { |
|
115 | + return $this->offsetGet($name); |
|
116 | + } else { |
|
117 | + $object = $this->resolve($name); |
|
118 | + $this->registerService($name, function () use ($object) { |
|
119 | + return $object; |
|
120 | + }); |
|
121 | + return $object; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $name |
|
127 | + * @param mixed $value |
|
128 | + */ |
|
129 | + public function registerParameter($name, $value) { |
|
130 | + $this[$name] = $value; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * The given closure is call the first time the given service is queried. |
|
135 | + * The closure has to return the instance for the given service. |
|
136 | + * Created instance will be cached in case $shared is true. |
|
137 | + * |
|
138 | + * @param string $name name of the service to register another backend for |
|
139 | + * @param Closure $closure the closure to be called on service creation |
|
140 | + * @param bool $shared |
|
141 | + */ |
|
142 | + public function registerService($name, Closure $closure, $shared = true) { |
|
143 | + $name = $this->sanitizeName($name); |
|
144 | + if (isset($this[$name])) { |
|
145 | + unset($this[$name]); |
|
146 | + } |
|
147 | + if ($shared) { |
|
148 | + $this[$name] = $closure; |
|
149 | + } else { |
|
150 | + $this[$name] = parent::factory($closure); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Shortcut for returning a service from a service under a different key, |
|
156 | + * e.g. to tell the container to return a class when queried for an |
|
157 | + * interface |
|
158 | + * @param string $alias the alias that should be registered |
|
159 | + * @param string $target the target that should be resolved instead |
|
160 | + */ |
|
161 | + public function registerAlias($alias, $target) { |
|
162 | + $this->registerService($alias, function (IContainer $container) use ($target) { |
|
163 | + return $container->query($target); |
|
164 | + }, false); |
|
165 | + } |
|
166 | + |
|
167 | + /* |
|
168 | 168 | * @param string $name |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - protected function sanitizeName($name) { |
|
172 | - if (isset($name[0]) && $name[0] === '\\') { |
|
173 | - return ltrim($name, '\\'); |
|
174 | - } |
|
175 | - return $name; |
|
176 | - } |
|
171 | + protected function sanitizeName($name) { |
|
172 | + if (isset($name[0]) && $name[0] === '\\') { |
|
173 | + return ltrim($name, '\\'); |
|
174 | + } |
|
175 | + return $name; |
|
176 | + } |
|
177 | 177 | |
178 | 178 | } |
@@ -34,12 +34,12 @@ |
||
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 | } |
@@ -40,149 +40,149 @@ |
||
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 | - * Tells ownCloud to include a template in the admin overview |
|
175 | - * @param string $mainPath the path to the main php file without the php |
|
176 | - * suffix, relative to your apps directory! not the template directory |
|
177 | - * @param string $appName the name of the app, defaults to the current one |
|
178 | - */ |
|
179 | - public function registerAdmin($mainPath, $appName=null) { |
|
180 | - if($appName === null){ |
|
181 | - $appName = $this->appName; |
|
182 | - } |
|
183 | - |
|
184 | - \OCP\App::registerAdmin($appName, $mainPath); |
|
185 | - } |
|
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 | + * Tells ownCloud to include a template in the admin overview |
|
175 | + * @param string $mainPath the path to the main php file without the php |
|
176 | + * suffix, relative to your apps directory! not the template directory |
|
177 | + * @param string $appName the name of the app, defaults to the current one |
|
178 | + */ |
|
179 | + public function registerAdmin($mainPath, $appName=null) { |
|
180 | + if($appName === null){ |
|
181 | + $appName = $this->appName; |
|
182 | + } |
|
183 | + |
|
184 | + \OCP\App::registerAdmin($appName, $mainPath); |
|
185 | + } |
|
186 | 186 | |
187 | 187 | |
188 | 188 | } |