@@ -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 | } |
@@ -30,70 +30,70 @@ |
||
30 | 30 | * Very thin wrapper class to make output testable |
31 | 31 | */ |
32 | 32 | class Output implements IOutput { |
33 | - /** @var string */ |
|
34 | - private $webRoot; |
|
33 | + /** @var string */ |
|
34 | + private $webRoot; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param $webRoot |
|
38 | - */ |
|
39 | - public function __construct($webRoot) { |
|
40 | - $this->webRoot = $webRoot; |
|
41 | - } |
|
36 | + /** |
|
37 | + * @param $webRoot |
|
38 | + */ |
|
39 | + public function __construct($webRoot) { |
|
40 | + $this->webRoot = $webRoot; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $out |
|
45 | - */ |
|
46 | - public function setOutput($out) { |
|
47 | - print($out); |
|
48 | - } |
|
43 | + /** |
|
44 | + * @param string $out |
|
45 | + */ |
|
46 | + public function setOutput($out) { |
|
47 | + print($out); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string|resource $path or file handle |
|
52 | - * |
|
53 | - * @return bool false if an error occurred |
|
54 | - */ |
|
55 | - public function setReadfile($path) { |
|
56 | - if (is_resource($path)) { |
|
57 | - $output = fopen('php://output', 'w'); |
|
58 | - return stream_copy_to_stream($path, $output) > 0; |
|
59 | - } else { |
|
60 | - return @readfile($path); |
|
61 | - } |
|
62 | - } |
|
50 | + /** |
|
51 | + * @param string|resource $path or file handle |
|
52 | + * |
|
53 | + * @return bool false if an error occurred |
|
54 | + */ |
|
55 | + public function setReadfile($path) { |
|
56 | + if (is_resource($path)) { |
|
57 | + $output = fopen('php://output', 'w'); |
|
58 | + return stream_copy_to_stream($path, $output) > 0; |
|
59 | + } else { |
|
60 | + return @readfile($path); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $header |
|
66 | - */ |
|
67 | - public function setHeader($header) { |
|
68 | - header($header); |
|
69 | - } |
|
64 | + /** |
|
65 | + * @param string $header |
|
66 | + */ |
|
67 | + public function setHeader($header) { |
|
68 | + header($header); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param int $code sets the http status code |
|
73 | - */ |
|
74 | - public function setHttpResponseCode($code) { |
|
75 | - http_response_code($code); |
|
76 | - } |
|
71 | + /** |
|
72 | + * @param int $code sets the http status code |
|
73 | + */ |
|
74 | + public function setHttpResponseCode($code) { |
|
75 | + http_response_code($code); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return int returns the current http response code |
|
80 | - */ |
|
81 | - public function getHttpResponseCode() { |
|
82 | - return http_response_code(); |
|
83 | - } |
|
78 | + /** |
|
79 | + * @return int returns the current http response code |
|
80 | + */ |
|
81 | + public function getHttpResponseCode() { |
|
82 | + return http_response_code(); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param string $name |
|
87 | - * @param string $value |
|
88 | - * @param int $expire |
|
89 | - * @param string $path |
|
90 | - * @param string $domain |
|
91 | - * @param bool $secure |
|
92 | - * @param bool $httpOnly |
|
93 | - */ |
|
94 | - public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) { |
|
95 | - $path = $this->webRoot ? : '/'; |
|
96 | - setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly); |
|
97 | - } |
|
85 | + /** |
|
86 | + * @param string $name |
|
87 | + * @param string $value |
|
88 | + * @param int $expire |
|
89 | + * @param string $path |
|
90 | + * @param string $domain |
|
91 | + * @param bool $secure |
|
92 | + * @param bool $httpOnly |
|
93 | + */ |
|
94 | + public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) { |
|
95 | + $path = $this->webRoot ? : '/'; |
|
96 | + setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly); |
|
97 | + } |
|
98 | 98 | |
99 | 99 | } |
@@ -43,142 +43,142 @@ |
||
43 | 43 | */ |
44 | 44 | class Dispatcher { |
45 | 45 | |
46 | - private $middlewareDispatcher; |
|
47 | - private $protocol; |
|
48 | - private $reflector; |
|
49 | - private $request; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param Http $protocol the http protocol with contains all status headers |
|
53 | - * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
54 | - * runs the middleware |
|
55 | - * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
56 | - * the arguments for the controller |
|
57 | - * @param IRequest $request the incoming request |
|
58 | - */ |
|
59 | - public function __construct(Http $protocol, |
|
60 | - MiddlewareDispatcher $middlewareDispatcher, |
|
61 | - ControllerMethodReflector $reflector, |
|
62 | - IRequest $request) { |
|
63 | - $this->protocol = $protocol; |
|
64 | - $this->middlewareDispatcher = $middlewareDispatcher; |
|
65 | - $this->reflector = $reflector; |
|
66 | - $this->request = $request; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Handles a request and calls the dispatcher on the controller |
|
72 | - * @param Controller $controller the controller which will be called |
|
73 | - * @param string $methodName the method name which will be called on |
|
74 | - * the controller |
|
75 | - * @return array $array[0] contains a string with the http main header, |
|
76 | - * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
77 | - * the response output |
|
78 | - * @throws \Exception |
|
79 | - */ |
|
80 | - public function dispatch(Controller $controller, $methodName) { |
|
81 | - $out = array(null, array(), null); |
|
82 | - |
|
83 | - try { |
|
84 | - // prefill reflector with everything thats needed for the |
|
85 | - // middlewares |
|
86 | - $this->reflector->reflect($controller, $methodName); |
|
87 | - |
|
88 | - $this->middlewareDispatcher->beforeController($controller, |
|
89 | - $methodName); |
|
90 | - $response = $this->executeController($controller, $methodName); |
|
91 | - |
|
92 | - // if an exception appears, the middleware checks if it can handle the |
|
93 | - // exception and creates a response. If no response is created, it is |
|
94 | - // assumed that theres no middleware who can handle it and the error is |
|
95 | - // thrown again |
|
96 | - } catch(\Exception $exception){ |
|
97 | - $response = $this->middlewareDispatcher->afterException( |
|
98 | - $controller, $methodName, $exception); |
|
99 | - if (is_null($response)) { |
|
100 | - throw $exception; |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - $response = $this->middlewareDispatcher->afterController( |
|
105 | - $controller, $methodName, $response); |
|
106 | - |
|
107 | - // depending on the cache object the headers need to be changed |
|
108 | - $out[0] = $this->protocol->getStatusHeader($response->getStatus(), |
|
109 | - $response->getLastModified(), $response->getETag()); |
|
110 | - $out[1] = array_merge($response->getHeaders()); |
|
111 | - $out[2] = $response->getCookies(); |
|
112 | - $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
113 | - $controller, $methodName, $response->render() |
|
114 | - ); |
|
115 | - $out[4] = $response; |
|
116 | - |
|
117 | - return $out; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Uses the reflected parameters, types and request parameters to execute |
|
123 | - * the controller |
|
124 | - * @param Controller $controller the controller to be executed |
|
125 | - * @param string $methodName the method on the controller that should be executed |
|
126 | - * @return Response |
|
127 | - */ |
|
128 | - private function executeController($controller, $methodName) { |
|
129 | - $arguments = array(); |
|
130 | - |
|
131 | - // valid types that will be casted |
|
132 | - $types = array('int', 'integer', 'bool', 'boolean', 'float'); |
|
133 | - |
|
134 | - foreach($this->reflector->getParameters() as $param => $default) { |
|
135 | - |
|
136 | - // try to get the parameter from the request object and cast |
|
137 | - // it to the type annotated in the @param annotation |
|
138 | - $value = $this->request->getParam($param, $default); |
|
139 | - $type = $this->reflector->getType($param); |
|
140 | - |
|
141 | - // if this is submitted using GET or a POST form, 'false' should be |
|
142 | - // converted to false |
|
143 | - if(($type === 'bool' || $type === 'boolean') && |
|
144 | - $value === 'false' && |
|
145 | - ( |
|
146 | - $this->request->method === 'GET' || |
|
147 | - strpos($this->request->getHeader('Content-Type'), |
|
148 | - 'application/x-www-form-urlencoded') !== false |
|
149 | - ) |
|
150 | - ) { |
|
151 | - $value = false; |
|
152 | - |
|
153 | - } elseif($value !== null && in_array($type, $types)) { |
|
154 | - settype($value, $type); |
|
155 | - } |
|
156 | - |
|
157 | - $arguments[] = $value; |
|
158 | - } |
|
159 | - |
|
160 | - $response = call_user_func_array(array($controller, $methodName), $arguments); |
|
161 | - |
|
162 | - // format response |
|
163 | - if($response instanceof DataResponse || !($response instanceof Response)) { |
|
164 | - |
|
165 | - // get format from the url format or request format parameter |
|
166 | - $format = $this->request->getParam('format'); |
|
167 | - |
|
168 | - // if none is given try the first Accept header |
|
169 | - if($format === null) { |
|
170 | - $headers = $this->request->getHeader('Accept'); |
|
171 | - $format = $controller->getResponderByHTTPHeader($headers, null); |
|
172 | - } |
|
173 | - |
|
174 | - if ($format !== null) { |
|
175 | - $response = $controller->buildResponse($response, $format); |
|
176 | - } else { |
|
177 | - $response = $controller->buildResponse($response); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - return $response; |
|
182 | - } |
|
46 | + private $middlewareDispatcher; |
|
47 | + private $protocol; |
|
48 | + private $reflector; |
|
49 | + private $request; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param Http $protocol the http protocol with contains all status headers |
|
53 | + * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
54 | + * runs the middleware |
|
55 | + * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
56 | + * the arguments for the controller |
|
57 | + * @param IRequest $request the incoming request |
|
58 | + */ |
|
59 | + public function __construct(Http $protocol, |
|
60 | + MiddlewareDispatcher $middlewareDispatcher, |
|
61 | + ControllerMethodReflector $reflector, |
|
62 | + IRequest $request) { |
|
63 | + $this->protocol = $protocol; |
|
64 | + $this->middlewareDispatcher = $middlewareDispatcher; |
|
65 | + $this->reflector = $reflector; |
|
66 | + $this->request = $request; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Handles a request and calls the dispatcher on the controller |
|
72 | + * @param Controller $controller the controller which will be called |
|
73 | + * @param string $methodName the method name which will be called on |
|
74 | + * the controller |
|
75 | + * @return array $array[0] contains a string with the http main header, |
|
76 | + * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
77 | + * the response output |
|
78 | + * @throws \Exception |
|
79 | + */ |
|
80 | + public function dispatch(Controller $controller, $methodName) { |
|
81 | + $out = array(null, array(), null); |
|
82 | + |
|
83 | + try { |
|
84 | + // prefill reflector with everything thats needed for the |
|
85 | + // middlewares |
|
86 | + $this->reflector->reflect($controller, $methodName); |
|
87 | + |
|
88 | + $this->middlewareDispatcher->beforeController($controller, |
|
89 | + $methodName); |
|
90 | + $response = $this->executeController($controller, $methodName); |
|
91 | + |
|
92 | + // if an exception appears, the middleware checks if it can handle the |
|
93 | + // exception and creates a response. If no response is created, it is |
|
94 | + // assumed that theres no middleware who can handle it and the error is |
|
95 | + // thrown again |
|
96 | + } catch(\Exception $exception){ |
|
97 | + $response = $this->middlewareDispatcher->afterException( |
|
98 | + $controller, $methodName, $exception); |
|
99 | + if (is_null($response)) { |
|
100 | + throw $exception; |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + $response = $this->middlewareDispatcher->afterController( |
|
105 | + $controller, $methodName, $response); |
|
106 | + |
|
107 | + // depending on the cache object the headers need to be changed |
|
108 | + $out[0] = $this->protocol->getStatusHeader($response->getStatus(), |
|
109 | + $response->getLastModified(), $response->getETag()); |
|
110 | + $out[1] = array_merge($response->getHeaders()); |
|
111 | + $out[2] = $response->getCookies(); |
|
112 | + $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
113 | + $controller, $methodName, $response->render() |
|
114 | + ); |
|
115 | + $out[4] = $response; |
|
116 | + |
|
117 | + return $out; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Uses the reflected parameters, types and request parameters to execute |
|
123 | + * the controller |
|
124 | + * @param Controller $controller the controller to be executed |
|
125 | + * @param string $methodName the method on the controller that should be executed |
|
126 | + * @return Response |
|
127 | + */ |
|
128 | + private function executeController($controller, $methodName) { |
|
129 | + $arguments = array(); |
|
130 | + |
|
131 | + // valid types that will be casted |
|
132 | + $types = array('int', 'integer', 'bool', 'boolean', 'float'); |
|
133 | + |
|
134 | + foreach($this->reflector->getParameters() as $param => $default) { |
|
135 | + |
|
136 | + // try to get the parameter from the request object and cast |
|
137 | + // it to the type annotated in the @param annotation |
|
138 | + $value = $this->request->getParam($param, $default); |
|
139 | + $type = $this->reflector->getType($param); |
|
140 | + |
|
141 | + // if this is submitted using GET or a POST form, 'false' should be |
|
142 | + // converted to false |
|
143 | + if(($type === 'bool' || $type === 'boolean') && |
|
144 | + $value === 'false' && |
|
145 | + ( |
|
146 | + $this->request->method === 'GET' || |
|
147 | + strpos($this->request->getHeader('Content-Type'), |
|
148 | + 'application/x-www-form-urlencoded') !== false |
|
149 | + ) |
|
150 | + ) { |
|
151 | + $value = false; |
|
152 | + |
|
153 | + } elseif($value !== null && in_array($type, $types)) { |
|
154 | + settype($value, $type); |
|
155 | + } |
|
156 | + |
|
157 | + $arguments[] = $value; |
|
158 | + } |
|
159 | + |
|
160 | + $response = call_user_func_array(array($controller, $methodName), $arguments); |
|
161 | + |
|
162 | + // format response |
|
163 | + if($response instanceof DataResponse || !($response instanceof Response)) { |
|
164 | + |
|
165 | + // get format from the url format or request format parameter |
|
166 | + $format = $this->request->getParam('format'); |
|
167 | + |
|
168 | + // if none is given try the first Accept header |
|
169 | + if($format === null) { |
|
170 | + $headers = $this->request->getHeader('Accept'); |
|
171 | + $format = $controller->getResponderByHTTPHeader($headers, null); |
|
172 | + } |
|
173 | + |
|
174 | + if ($format !== null) { |
|
175 | + $response = $controller->buildResponse($response, $format); |
|
176 | + } else { |
|
177 | + $response = $controller->buildResponse($response); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + return $response; |
|
182 | + } |
|
183 | 183 | |
184 | 184 | } |