@@ -32,31 +32,31 @@ |
||
32 | 32 | |
33 | 33 | class ContactsMenuController extends Controller { |
34 | 34 | |
35 | - /** @var Manager */ |
|
36 | - private $manager; |
|
37 | - |
|
38 | - /** @var IUserSession */ |
|
39 | - private $userSession; |
|
40 | - |
|
41 | - /** |
|
42 | - * @param IRequest $request |
|
43 | - * @param IUserSession $userSession |
|
44 | - * @param Manager $manager |
|
45 | - */ |
|
46 | - public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) { |
|
47 | - parent::__construct('core', $request); |
|
48 | - $this->userSession = $userSession; |
|
49 | - $this->manager = $manager; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @NoAdminRequired |
|
54 | - * |
|
55 | - * @param string|null filter |
|
56 | - * @return JSONResponse |
|
57 | - */ |
|
58 | - public function index($filter = null) { |
|
59 | - return $this->manager->getEntries($this->userSession->getUser(), $filter); |
|
60 | - } |
|
35 | + /** @var Manager */ |
|
36 | + private $manager; |
|
37 | + |
|
38 | + /** @var IUserSession */ |
|
39 | + private $userSession; |
|
40 | + |
|
41 | + /** |
|
42 | + * @param IRequest $request |
|
43 | + * @param IUserSession $userSession |
|
44 | + * @param Manager $manager |
|
45 | + */ |
|
46 | + public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) { |
|
47 | + parent::__construct('core', $request); |
|
48 | + $this->userSession = $userSession; |
|
49 | + $this->manager = $manager; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @NoAdminRequired |
|
54 | + * |
|
55 | + * @param string|null filter |
|
56 | + * @return JSONResponse |
|
57 | + */ |
|
58 | + public function index($filter = null) { |
|
59 | + return $this->manager->getEntries($this->userSession->getUser(), $filter); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | } |
@@ -35,80 +35,80 @@ |
||
35 | 35 | |
36 | 36 | class ActionProviderStore { |
37 | 37 | |
38 | - /** @var IServerContainer */ |
|
39 | - private $serverContainer; |
|
40 | - |
|
41 | - /** @var AppManager */ |
|
42 | - private $appManager; |
|
43 | - |
|
44 | - /** @var ILogger */ |
|
45 | - private $logger; |
|
46 | - |
|
47 | - /** |
|
48 | - * @param IServerContainer $serverContainer |
|
49 | - * @param AppManager $appManager |
|
50 | - * @param ILogger $logger |
|
51 | - */ |
|
52 | - public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
53 | - $this->serverContainer = $serverContainer; |
|
54 | - $this->appManager = $appManager; |
|
55 | - $this->logger = $logger; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param IUser $user |
|
60 | - * @return IProvider[] |
|
61 | - * @throws Exception |
|
62 | - */ |
|
63 | - public function getProviders(IUser $user) { |
|
64 | - $appClasses = $this->getAppProviderClasses($user); |
|
65 | - $providerClasses = $this->getServerProviderClasses(); |
|
66 | - $allClasses = array_merge($providerClasses, $appClasses); |
|
67 | - $providers = []; |
|
68 | - |
|
69 | - foreach ($allClasses as $class) { |
|
70 | - try { |
|
71 | - $providers[] = $this->serverContainer->query($class); |
|
72 | - } catch (QueryException $ex) { |
|
73 | - $this->logger->logException($ex, [ |
|
74 | - 'message' => "Could not load contacts menu action provider $class", |
|
75 | - 'app' => 'core', |
|
76 | - ]); |
|
77 | - throw new Exception("Could not load contacts menu action provider"); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - return $providers; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @return string[] |
|
86 | - */ |
|
87 | - private function getServerProviderClasses() { |
|
88 | - return [ |
|
89 | - EMailProvider::class, |
|
90 | - ]; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param IUser $user |
|
95 | - * @return string[] |
|
96 | - */ |
|
97 | - private function getAppProviderClasses(IUser $user) { |
|
98 | - return array_reduce($this->appManager->getEnabledAppsForUser($user), function($all, $appId) { |
|
99 | - $info = $this->appManager->getAppInfo($appId); |
|
100 | - |
|
101 | - if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
102 | - // Nothing to add |
|
103 | - return $all; |
|
104 | - } |
|
105 | - |
|
106 | - $providers = array_reduce($info['contactsmenu'], function($all, $provider) { |
|
107 | - return array_merge($all, [$provider]); |
|
108 | - }, []); |
|
109 | - |
|
110 | - return array_merge($all, $providers); |
|
111 | - }, []); |
|
112 | - } |
|
38 | + /** @var IServerContainer */ |
|
39 | + private $serverContainer; |
|
40 | + |
|
41 | + /** @var AppManager */ |
|
42 | + private $appManager; |
|
43 | + |
|
44 | + /** @var ILogger */ |
|
45 | + private $logger; |
|
46 | + |
|
47 | + /** |
|
48 | + * @param IServerContainer $serverContainer |
|
49 | + * @param AppManager $appManager |
|
50 | + * @param ILogger $logger |
|
51 | + */ |
|
52 | + public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
53 | + $this->serverContainer = $serverContainer; |
|
54 | + $this->appManager = $appManager; |
|
55 | + $this->logger = $logger; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param IUser $user |
|
60 | + * @return IProvider[] |
|
61 | + * @throws Exception |
|
62 | + */ |
|
63 | + public function getProviders(IUser $user) { |
|
64 | + $appClasses = $this->getAppProviderClasses($user); |
|
65 | + $providerClasses = $this->getServerProviderClasses(); |
|
66 | + $allClasses = array_merge($providerClasses, $appClasses); |
|
67 | + $providers = []; |
|
68 | + |
|
69 | + foreach ($allClasses as $class) { |
|
70 | + try { |
|
71 | + $providers[] = $this->serverContainer->query($class); |
|
72 | + } catch (QueryException $ex) { |
|
73 | + $this->logger->logException($ex, [ |
|
74 | + 'message' => "Could not load contacts menu action provider $class", |
|
75 | + 'app' => 'core', |
|
76 | + ]); |
|
77 | + throw new Exception("Could not load contacts menu action provider"); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + return $providers; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @return string[] |
|
86 | + */ |
|
87 | + private function getServerProviderClasses() { |
|
88 | + return [ |
|
89 | + EMailProvider::class, |
|
90 | + ]; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param IUser $user |
|
95 | + * @return string[] |
|
96 | + */ |
|
97 | + private function getAppProviderClasses(IUser $user) { |
|
98 | + return array_reduce($this->appManager->getEnabledAppsForUser($user), function($all, $appId) { |
|
99 | + $info = $this->appManager->getAppInfo($appId); |
|
100 | + |
|
101 | + if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
102 | + // Nothing to add |
|
103 | + return $all; |
|
104 | + } |
|
105 | + |
|
106 | + $providers = array_reduce($info['contactsmenu'], function($all, $provider) { |
|
107 | + return array_merge($all, [$provider]); |
|
108 | + }, []); |
|
109 | + |
|
110 | + return array_merge($all, $providers); |
|
111 | + }, []); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |
@@ -32,170 +32,170 @@ |
||
32 | 32 | * Tools for transforming search queries into database queries |
33 | 33 | */ |
34 | 34 | class QuerySearchHelper { |
35 | - static protected $searchOperatorMap = [ |
|
36 | - ISearchComparison::COMPARE_LIKE => 'iLike', |
|
37 | - ISearchComparison::COMPARE_EQUAL => 'eq', |
|
38 | - ISearchComparison::COMPARE_GREATER_THAN => 'gt', |
|
39 | - ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'gte', |
|
40 | - ISearchComparison::COMPARE_LESS_THAN => 'lt', |
|
41 | - ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lte' |
|
42 | - ]; |
|
43 | - |
|
44 | - static protected $searchOperatorNegativeMap = [ |
|
45 | - ISearchComparison::COMPARE_LIKE => 'notLike', |
|
46 | - ISearchComparison::COMPARE_EQUAL => 'neq', |
|
47 | - ISearchComparison::COMPARE_GREATER_THAN => 'lte', |
|
48 | - ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'lt', |
|
49 | - ISearchComparison::COMPARE_LESS_THAN => 'gte', |
|
50 | - ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lt' |
|
51 | - ]; |
|
52 | - |
|
53 | - const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
54 | - |
|
55 | - /** @var IMimeTypeLoader */ |
|
56 | - private $mimetypeLoader; |
|
57 | - |
|
58 | - /** |
|
59 | - * QuerySearchUtil constructor. |
|
60 | - * |
|
61 | - * @param IMimeTypeLoader $mimetypeLoader |
|
62 | - */ |
|
63 | - public function __construct(IMimeTypeLoader $mimetypeLoader) { |
|
64 | - $this->mimetypeLoader = $mimetypeLoader; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Whether or not the tag tables should be joined to complete the search |
|
69 | - * |
|
70 | - * @param ISearchOperator $operator |
|
71 | - * @return boolean |
|
72 | - */ |
|
73 | - public function shouldJoinTags(ISearchOperator $operator) { |
|
74 | - if ($operator instanceof ISearchBinaryOperator) { |
|
75 | - return array_reduce($operator->getArguments(), function ($shouldJoin, ISearchOperator $operator) { |
|
76 | - return $shouldJoin || $this->shouldJoinTags($operator); |
|
77 | - }, false); |
|
78 | - } else if ($operator instanceof ISearchComparison) { |
|
79 | - return $operator->getField() === 'tagname' || $operator->getField() === 'favorite'; |
|
80 | - } |
|
81 | - return false; |
|
82 | - } |
|
83 | - |
|
84 | - public function searchOperatorToDBExpr(IQueryBuilder $builder, ISearchOperator $operator) { |
|
85 | - $expr = $builder->expr(); |
|
86 | - if ($operator instanceof ISearchBinaryOperator) { |
|
87 | - switch ($operator->getType()) { |
|
88 | - case ISearchBinaryOperator::OPERATOR_NOT: |
|
89 | - $negativeOperator = $operator->getArguments()[0]; |
|
90 | - if ($negativeOperator instanceof ISearchComparison) { |
|
91 | - return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::$searchOperatorNegativeMap); |
|
92 | - } else { |
|
93 | - throw new \InvalidArgumentException('Binary operators inside "not" is not supported'); |
|
94 | - } |
|
95 | - case ISearchBinaryOperator::OPERATOR_AND: |
|
96 | - return $expr->andX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
97 | - case ISearchBinaryOperator::OPERATOR_OR: |
|
98 | - return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
99 | - default: |
|
100 | - throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
101 | - } |
|
102 | - } else if ($operator instanceof ISearchComparison) { |
|
103 | - return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
|
104 | - } else { |
|
105 | - throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - private function searchComparisonToDBExpr(IQueryBuilder $builder, ISearchComparison $comparison, array $operatorMap) { |
|
110 | - $this->validateComparison($comparison); |
|
111 | - |
|
112 | - list($field, $value, $type) = $this->getOperatorFieldAndValue($comparison); |
|
113 | - if (isset($operatorMap[$type])) { |
|
114 | - $queryOperator = $operatorMap[$type]; |
|
115 | - return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
|
116 | - } else { |
|
117 | - throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - private function getOperatorFieldAndValue(ISearchComparison $operator) { |
|
122 | - $field = $operator->getField(); |
|
123 | - $value = $operator->getValue(); |
|
124 | - $type = $operator->getType(); |
|
125 | - if ($field === 'mimetype') { |
|
126 | - if ($operator->getType() === ISearchComparison::COMPARE_EQUAL) { |
|
127 | - $value = $this->mimetypeLoader->getId($value); |
|
128 | - } else if ($operator->getType() === ISearchComparison::COMPARE_LIKE) { |
|
129 | - // transform "mimetype='foo/%'" to "mimepart='foo'" |
|
130 | - if (preg_match('|(.+)/%|', $value, $matches)) { |
|
131 | - $field = 'mimepart'; |
|
132 | - $value = $this->mimetypeLoader->getId($matches[1]); |
|
133 | - $type = ISearchComparison::COMPARE_EQUAL; |
|
134 | - } |
|
135 | - if (strpos($value, '%') !== false) { |
|
136 | - throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
137 | - } |
|
138 | - } |
|
139 | - } else if ($field === 'favorite') { |
|
140 | - $field = 'tag.category'; |
|
141 | - $value = self::TAG_FAVORITE; |
|
142 | - } else if ($field === 'tagname') { |
|
143 | - $field = 'tag.category'; |
|
144 | - } |
|
145 | - return [$field, $value, $type]; |
|
146 | - } |
|
147 | - |
|
148 | - private function validateComparison(ISearchComparison $operator) { |
|
149 | - $types = [ |
|
150 | - 'mimetype' => 'string', |
|
151 | - 'mtime' => 'integer', |
|
152 | - 'name' => 'string', |
|
153 | - 'size' => 'integer', |
|
154 | - 'tagname' => 'string', |
|
155 | - 'favorite' => 'boolean', |
|
156 | - 'fileid' => 'integer' |
|
157 | - ]; |
|
158 | - $comparisons = [ |
|
159 | - 'mimetype' => ['eq', 'like'], |
|
160 | - 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
161 | - 'name' => ['eq', 'like'], |
|
162 | - 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
163 | - 'tagname' => ['eq', 'like'], |
|
164 | - 'favorite' => ['eq'], |
|
165 | - 'fileid' => ['eq'] |
|
166 | - ]; |
|
167 | - |
|
168 | - if (!isset($types[$operator->getField()])) { |
|
169 | - throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
170 | - } |
|
171 | - $type = $types[$operator->getField()]; |
|
172 | - if (gettype($operator->getValue()) !== $type) { |
|
173 | - throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
174 | - } |
|
175 | - if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
|
176 | - throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - private function getParameterForValue(IQueryBuilder $builder, $value) { |
|
181 | - if ($value instanceof \DateTime) { |
|
182 | - $value = $value->getTimestamp(); |
|
183 | - } |
|
184 | - if (is_numeric($value)) { |
|
185 | - $type = IQueryBuilder::PARAM_INT; |
|
186 | - } else { |
|
187 | - $type = IQueryBuilder::PARAM_STR; |
|
188 | - } |
|
189 | - return $builder->createNamedParameter($value, $type); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @param IQueryBuilder $query |
|
194 | - * @param ISearchOrder[] $orders |
|
195 | - */ |
|
196 | - public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders) { |
|
197 | - foreach ($orders as $order) { |
|
198 | - $query->addOrderBy($order->getField(), $order->getDirection()); |
|
199 | - } |
|
200 | - } |
|
35 | + static protected $searchOperatorMap = [ |
|
36 | + ISearchComparison::COMPARE_LIKE => 'iLike', |
|
37 | + ISearchComparison::COMPARE_EQUAL => 'eq', |
|
38 | + ISearchComparison::COMPARE_GREATER_THAN => 'gt', |
|
39 | + ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'gte', |
|
40 | + ISearchComparison::COMPARE_LESS_THAN => 'lt', |
|
41 | + ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lte' |
|
42 | + ]; |
|
43 | + |
|
44 | + static protected $searchOperatorNegativeMap = [ |
|
45 | + ISearchComparison::COMPARE_LIKE => 'notLike', |
|
46 | + ISearchComparison::COMPARE_EQUAL => 'neq', |
|
47 | + ISearchComparison::COMPARE_GREATER_THAN => 'lte', |
|
48 | + ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'lt', |
|
49 | + ISearchComparison::COMPARE_LESS_THAN => 'gte', |
|
50 | + ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lt' |
|
51 | + ]; |
|
52 | + |
|
53 | + const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
54 | + |
|
55 | + /** @var IMimeTypeLoader */ |
|
56 | + private $mimetypeLoader; |
|
57 | + |
|
58 | + /** |
|
59 | + * QuerySearchUtil constructor. |
|
60 | + * |
|
61 | + * @param IMimeTypeLoader $mimetypeLoader |
|
62 | + */ |
|
63 | + public function __construct(IMimeTypeLoader $mimetypeLoader) { |
|
64 | + $this->mimetypeLoader = $mimetypeLoader; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Whether or not the tag tables should be joined to complete the search |
|
69 | + * |
|
70 | + * @param ISearchOperator $operator |
|
71 | + * @return boolean |
|
72 | + */ |
|
73 | + public function shouldJoinTags(ISearchOperator $operator) { |
|
74 | + if ($operator instanceof ISearchBinaryOperator) { |
|
75 | + return array_reduce($operator->getArguments(), function ($shouldJoin, ISearchOperator $operator) { |
|
76 | + return $shouldJoin || $this->shouldJoinTags($operator); |
|
77 | + }, false); |
|
78 | + } else if ($operator instanceof ISearchComparison) { |
|
79 | + return $operator->getField() === 'tagname' || $operator->getField() === 'favorite'; |
|
80 | + } |
|
81 | + return false; |
|
82 | + } |
|
83 | + |
|
84 | + public function searchOperatorToDBExpr(IQueryBuilder $builder, ISearchOperator $operator) { |
|
85 | + $expr = $builder->expr(); |
|
86 | + if ($operator instanceof ISearchBinaryOperator) { |
|
87 | + switch ($operator->getType()) { |
|
88 | + case ISearchBinaryOperator::OPERATOR_NOT: |
|
89 | + $negativeOperator = $operator->getArguments()[0]; |
|
90 | + if ($negativeOperator instanceof ISearchComparison) { |
|
91 | + return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::$searchOperatorNegativeMap); |
|
92 | + } else { |
|
93 | + throw new \InvalidArgumentException('Binary operators inside "not" is not supported'); |
|
94 | + } |
|
95 | + case ISearchBinaryOperator::OPERATOR_AND: |
|
96 | + return $expr->andX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
97 | + case ISearchBinaryOperator::OPERATOR_OR: |
|
98 | + return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
99 | + default: |
|
100 | + throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
101 | + } |
|
102 | + } else if ($operator instanceof ISearchComparison) { |
|
103 | + return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
|
104 | + } else { |
|
105 | + throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + private function searchComparisonToDBExpr(IQueryBuilder $builder, ISearchComparison $comparison, array $operatorMap) { |
|
110 | + $this->validateComparison($comparison); |
|
111 | + |
|
112 | + list($field, $value, $type) = $this->getOperatorFieldAndValue($comparison); |
|
113 | + if (isset($operatorMap[$type])) { |
|
114 | + $queryOperator = $operatorMap[$type]; |
|
115 | + return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
|
116 | + } else { |
|
117 | + throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + private function getOperatorFieldAndValue(ISearchComparison $operator) { |
|
122 | + $field = $operator->getField(); |
|
123 | + $value = $operator->getValue(); |
|
124 | + $type = $operator->getType(); |
|
125 | + if ($field === 'mimetype') { |
|
126 | + if ($operator->getType() === ISearchComparison::COMPARE_EQUAL) { |
|
127 | + $value = $this->mimetypeLoader->getId($value); |
|
128 | + } else if ($operator->getType() === ISearchComparison::COMPARE_LIKE) { |
|
129 | + // transform "mimetype='foo/%'" to "mimepart='foo'" |
|
130 | + if (preg_match('|(.+)/%|', $value, $matches)) { |
|
131 | + $field = 'mimepart'; |
|
132 | + $value = $this->mimetypeLoader->getId($matches[1]); |
|
133 | + $type = ISearchComparison::COMPARE_EQUAL; |
|
134 | + } |
|
135 | + if (strpos($value, '%') !== false) { |
|
136 | + throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
137 | + } |
|
138 | + } |
|
139 | + } else if ($field === 'favorite') { |
|
140 | + $field = 'tag.category'; |
|
141 | + $value = self::TAG_FAVORITE; |
|
142 | + } else if ($field === 'tagname') { |
|
143 | + $field = 'tag.category'; |
|
144 | + } |
|
145 | + return [$field, $value, $type]; |
|
146 | + } |
|
147 | + |
|
148 | + private function validateComparison(ISearchComparison $operator) { |
|
149 | + $types = [ |
|
150 | + 'mimetype' => 'string', |
|
151 | + 'mtime' => 'integer', |
|
152 | + 'name' => 'string', |
|
153 | + 'size' => 'integer', |
|
154 | + 'tagname' => 'string', |
|
155 | + 'favorite' => 'boolean', |
|
156 | + 'fileid' => 'integer' |
|
157 | + ]; |
|
158 | + $comparisons = [ |
|
159 | + 'mimetype' => ['eq', 'like'], |
|
160 | + 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
161 | + 'name' => ['eq', 'like'], |
|
162 | + 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
163 | + 'tagname' => ['eq', 'like'], |
|
164 | + 'favorite' => ['eq'], |
|
165 | + 'fileid' => ['eq'] |
|
166 | + ]; |
|
167 | + |
|
168 | + if (!isset($types[$operator->getField()])) { |
|
169 | + throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
170 | + } |
|
171 | + $type = $types[$operator->getField()]; |
|
172 | + if (gettype($operator->getValue()) !== $type) { |
|
173 | + throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
174 | + } |
|
175 | + if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
|
176 | + throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + private function getParameterForValue(IQueryBuilder $builder, $value) { |
|
181 | + if ($value instanceof \DateTime) { |
|
182 | + $value = $value->getTimestamp(); |
|
183 | + } |
|
184 | + if (is_numeric($value)) { |
|
185 | + $type = IQueryBuilder::PARAM_INT; |
|
186 | + } else { |
|
187 | + $type = IQueryBuilder::PARAM_STR; |
|
188 | + } |
|
189 | + return $builder->createNamedParameter($value, $type); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @param IQueryBuilder $query |
|
194 | + * @param ISearchOrder[] $orders |
|
195 | + */ |
|
196 | + public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders) { |
|
197 | + foreach ($orders as $order) { |
|
198 | + $query->addOrderBy($order->getField(), $order->getDirection()); |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | /** @var Folder $folder $results */ |
156 | 156 | $results = $folder->search($query); |
157 | 157 | |
158 | - return array_map(function (Node $node) { |
|
158 | + return array_map(function(Node $node) { |
|
159 | 159 | if ($node instanceof Folder) { |
160 | 160 | return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node)); |
161 | 161 | } else { |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * @return string |
170 | 170 | */ |
171 | 171 | private function getHrefForNode(Node $node) { |
172 | - $base = '/files/' . $this->user->getUID(); |
|
173 | - return $base . $this->view->getRelativePath($node->getPath()); |
|
172 | + $base = '/files/'.$this->user->getUID(); |
|
173 | + return $base.$this->view->getRelativePath($node->getPath()); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -210,19 +210,19 @@ discard block |
||
210 | 210 | case Operator::OPERATION_LESS_THAN: |
211 | 211 | case Operator::OPERATION_IS_LIKE: |
212 | 212 | if (count($operator->arguments) !== 2) { |
213 | - throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
213 | + throw new \InvalidArgumentException('Invalid number of arguments for '.$trimmedType.' operation'); |
|
214 | 214 | } |
215 | 215 | if (!is_string($operator->arguments[0])) { |
216 | - throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
216 | + throw new \InvalidArgumentException('Invalid argument 1 for '.$trimmedType.' operation, expected property'); |
|
217 | 217 | } |
218 | 218 | if (!($operator->arguments[1] instanceof Literal)) { |
219 | - throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
219 | + throw new \InvalidArgumentException('Invalid argument 2 for '.$trimmedType.' operation, expected literal'); |
|
220 | 220 | } |
221 | 221 | return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
222 | 222 | case Operator::OPERATION_IS_COLLECTION: |
223 | 223 | return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
224 | 224 | default: |
225 | - throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')'); |
|
225 | + throw new \InvalidArgumentException('Unsupported operation '.$trimmedType.' ('.$operator->type.')'); |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME: |
248 | 248 | return 'fileid'; |
249 | 249 | default: |
250 | - throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
250 | + throw new \InvalidArgumentException('Unsupported property for search or order: '.$propertyName); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 |
@@ -49,231 +49,231 @@ |
||
49 | 49 | use SearchDAV\XML\Order; |
50 | 50 | |
51 | 51 | class FileSearchBackend implements ISearchBackend { |
52 | - /** @var Tree */ |
|
53 | - private $tree; |
|
52 | + /** @var Tree */ |
|
53 | + private $tree; |
|
54 | 54 | |
55 | - /** @var IUser */ |
|
56 | - private $user; |
|
55 | + /** @var IUser */ |
|
56 | + private $user; |
|
57 | 57 | |
58 | - /** @var IRootFolder */ |
|
59 | - private $rootFolder; |
|
58 | + /** @var IRootFolder */ |
|
59 | + private $rootFolder; |
|
60 | 60 | |
61 | - /** @var IManager */ |
|
62 | - private $shareManager; |
|
61 | + /** @var IManager */ |
|
62 | + private $shareManager; |
|
63 | 63 | |
64 | - /** @var View */ |
|
65 | - private $view; |
|
64 | + /** @var View */ |
|
65 | + private $view; |
|
66 | 66 | |
67 | - /** |
|
68 | - * FileSearchBackend constructor. |
|
69 | - * |
|
70 | - * @param Tree $tree |
|
71 | - * @param IUser $user |
|
72 | - * @param IRootFolder $rootFolder |
|
73 | - * @param IManager $shareManager |
|
74 | - * @param View $view |
|
75 | - * @internal param IRootFolder $rootFolder |
|
76 | - */ |
|
77 | - public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) { |
|
78 | - $this->tree = $tree; |
|
79 | - $this->user = $user; |
|
80 | - $this->rootFolder = $rootFolder; |
|
81 | - $this->shareManager = $shareManager; |
|
82 | - $this->view = $view; |
|
83 | - } |
|
67 | + /** |
|
68 | + * FileSearchBackend constructor. |
|
69 | + * |
|
70 | + * @param Tree $tree |
|
71 | + * @param IUser $user |
|
72 | + * @param IRootFolder $rootFolder |
|
73 | + * @param IManager $shareManager |
|
74 | + * @param View $view |
|
75 | + * @internal param IRootFolder $rootFolder |
|
76 | + */ |
|
77 | + public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) { |
|
78 | + $this->tree = $tree; |
|
79 | + $this->user = $user; |
|
80 | + $this->rootFolder = $rootFolder; |
|
81 | + $this->shareManager = $shareManager; |
|
82 | + $this->view = $view; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Search endpoint will be remote.php/dav |
|
87 | - * |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getArbiterPath() { |
|
91 | - return ''; |
|
92 | - } |
|
85 | + /** |
|
86 | + * Search endpoint will be remote.php/dav |
|
87 | + * |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getArbiterPath() { |
|
91 | + return ''; |
|
92 | + } |
|
93 | 93 | |
94 | - public function isValidScope($href, $depth, $path) { |
|
95 | - // only allow scopes inside the dav server |
|
96 | - if (is_null($path)) { |
|
97 | - return false; |
|
98 | - } |
|
94 | + public function isValidScope($href, $depth, $path) { |
|
95 | + // only allow scopes inside the dav server |
|
96 | + if (is_null($path)) { |
|
97 | + return false; |
|
98 | + } |
|
99 | 99 | |
100 | - try { |
|
101 | - $node = $this->tree->getNodeForPath($path); |
|
102 | - return $node instanceof Directory; |
|
103 | - } catch (NotFound $e) { |
|
104 | - return false; |
|
105 | - } |
|
106 | - } |
|
100 | + try { |
|
101 | + $node = $this->tree->getNodeForPath($path); |
|
102 | + return $node instanceof Directory; |
|
103 | + } catch (NotFound $e) { |
|
104 | + return false; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - public function getPropertyDefinitionsForScope($href, $path) { |
|
109 | - // all valid scopes support the same schema |
|
108 | + public function getPropertyDefinitionsForScope($href, $path) { |
|
109 | + // all valid scopes support the same schema |
|
110 | 110 | |
111 | - //todo dynamically load all propfind properties that are supported |
|
112 | - return [ |
|
113 | - // queryable properties |
|
114 | - new SearchPropertyDefinition('{DAV:}displayname', true, false, true), |
|
115 | - new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), |
|
116 | - new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), |
|
117 | - new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
118 | - new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
119 | - new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
111 | + //todo dynamically load all propfind properties that are supported |
|
112 | + return [ |
|
113 | + // queryable properties |
|
114 | + new SearchPropertyDefinition('{DAV:}displayname', true, false, true), |
|
115 | + new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), |
|
116 | + new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), |
|
117 | + new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
118 | + new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
119 | + new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
120 | 120 | |
121 | - // select only properties |
|
122 | - new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false), |
|
123 | - new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false), |
|
124 | - new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false), |
|
125 | - new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false), |
|
126 | - new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false), |
|
127 | - new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false), |
|
128 | - new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false), |
|
129 | - new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false), |
|
130 | - new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
131 | - new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
132 | - ]; |
|
133 | - } |
|
121 | + // select only properties |
|
122 | + new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false), |
|
123 | + new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false), |
|
124 | + new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false), |
|
125 | + new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false), |
|
126 | + new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false), |
|
127 | + new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false), |
|
128 | + new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false), |
|
129 | + new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false), |
|
130 | + new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN), |
|
131 | + new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), |
|
132 | + ]; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param BasicSearch $search |
|
137 | - * @return SearchResult[] |
|
138 | - */ |
|
139 | - public function search(BasicSearch $search) { |
|
140 | - if (count($search->from) !== 1) { |
|
141 | - throw new \InvalidArgumentException('Searching more than one folder is not supported'); |
|
142 | - } |
|
143 | - $query = $this->transformQuery($search); |
|
144 | - $scope = $search->from[0]; |
|
145 | - if ($scope->path === null) { |
|
146 | - throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead'); |
|
147 | - } |
|
148 | - $node = $this->tree->getNodeForPath($scope->path); |
|
149 | - if (!$node instanceof Directory) { |
|
150 | - throw new \InvalidArgumentException('Search is only supported on directories'); |
|
151 | - } |
|
135 | + /** |
|
136 | + * @param BasicSearch $search |
|
137 | + * @return SearchResult[] |
|
138 | + */ |
|
139 | + public function search(BasicSearch $search) { |
|
140 | + if (count($search->from) !== 1) { |
|
141 | + throw new \InvalidArgumentException('Searching more than one folder is not supported'); |
|
142 | + } |
|
143 | + $query = $this->transformQuery($search); |
|
144 | + $scope = $search->from[0]; |
|
145 | + if ($scope->path === null) { |
|
146 | + throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead'); |
|
147 | + } |
|
148 | + $node = $this->tree->getNodeForPath($scope->path); |
|
149 | + if (!$node instanceof Directory) { |
|
150 | + throw new \InvalidArgumentException('Search is only supported on directories'); |
|
151 | + } |
|
152 | 152 | |
153 | - $fileInfo = $node->getFileInfo(); |
|
154 | - $folder = $this->rootFolder->get($fileInfo->getPath()); |
|
155 | - /** @var Folder $folder $results */ |
|
156 | - $results = $folder->search($query); |
|
153 | + $fileInfo = $node->getFileInfo(); |
|
154 | + $folder = $this->rootFolder->get($fileInfo->getPath()); |
|
155 | + /** @var Folder $folder $results */ |
|
156 | + $results = $folder->search($query); |
|
157 | 157 | |
158 | - return array_map(function (Node $node) { |
|
159 | - if ($node instanceof Folder) { |
|
160 | - return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node)); |
|
161 | - } else { |
|
162 | - return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node)); |
|
163 | - } |
|
164 | - }, $results); |
|
165 | - } |
|
158 | + return array_map(function (Node $node) { |
|
159 | + if ($node instanceof Folder) { |
|
160 | + return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node)); |
|
161 | + } else { |
|
162 | + return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node)); |
|
163 | + } |
|
164 | + }, $results); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param Node $node |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - private function getHrefForNode(Node $node) { |
|
172 | - $base = '/files/' . $this->user->getUID(); |
|
173 | - return $base . $this->view->getRelativePath($node->getPath()); |
|
174 | - } |
|
167 | + /** |
|
168 | + * @param Node $node |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + private function getHrefForNode(Node $node) { |
|
172 | + $base = '/files/' . $this->user->getUID(); |
|
173 | + return $base . $this->view->getRelativePath($node->getPath()); |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @param BasicSearch $query |
|
178 | - * @return ISearchQuery |
|
179 | - */ |
|
180 | - private function transformQuery(BasicSearch $query) { |
|
181 | - // TODO offset, limit |
|
182 | - $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy); |
|
183 | - return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user); |
|
184 | - } |
|
176 | + /** |
|
177 | + * @param BasicSearch $query |
|
178 | + * @return ISearchQuery |
|
179 | + */ |
|
180 | + private function transformQuery(BasicSearch $query) { |
|
181 | + // TODO offset, limit |
|
182 | + $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy); |
|
183 | + return new SearchQuery($this->transformSearchOperation($query->where), 0, 0, $orders, $this->user); |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * @param Order $order |
|
188 | - * @return ISearchOrder |
|
189 | - */ |
|
190 | - private function mapSearchOrder(Order $order) { |
|
191 | - return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property)); |
|
192 | - } |
|
186 | + /** |
|
187 | + * @param Order $order |
|
188 | + * @return ISearchOrder |
|
189 | + */ |
|
190 | + private function mapSearchOrder(Order $order) { |
|
191 | + return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property)); |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * @param Operator $operator |
|
196 | - * @return ISearchOperator |
|
197 | - */ |
|
198 | - private function transformSearchOperation(Operator $operator) { |
|
199 | - list(, $trimmedType) = explode('}', $operator->type); |
|
200 | - switch ($operator->type) { |
|
201 | - case Operator::OPERATION_AND: |
|
202 | - case Operator::OPERATION_OR: |
|
203 | - case Operator::OPERATION_NOT: |
|
204 | - $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments); |
|
205 | - return new SearchBinaryOperator($trimmedType, $arguments); |
|
206 | - case Operator::OPERATION_EQUAL: |
|
207 | - case Operator::OPERATION_GREATER_OR_EQUAL_THAN: |
|
208 | - case Operator::OPERATION_GREATER_THAN: |
|
209 | - case Operator::OPERATION_LESS_OR_EQUAL_THAN: |
|
210 | - case Operator::OPERATION_LESS_THAN: |
|
211 | - case Operator::OPERATION_IS_LIKE: |
|
212 | - if (count($operator->arguments) !== 2) { |
|
213 | - throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
214 | - } |
|
215 | - if (!is_string($operator->arguments[0])) { |
|
216 | - throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
217 | - } |
|
218 | - if (!($operator->arguments[1] instanceof Literal)) { |
|
219 | - throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
220 | - } |
|
221 | - return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
|
222 | - case Operator::OPERATION_IS_COLLECTION: |
|
223 | - return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
|
224 | - default: |
|
225 | - throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')'); |
|
226 | - } |
|
227 | - } |
|
194 | + /** |
|
195 | + * @param Operator $operator |
|
196 | + * @return ISearchOperator |
|
197 | + */ |
|
198 | + private function transformSearchOperation(Operator $operator) { |
|
199 | + list(, $trimmedType) = explode('}', $operator->type); |
|
200 | + switch ($operator->type) { |
|
201 | + case Operator::OPERATION_AND: |
|
202 | + case Operator::OPERATION_OR: |
|
203 | + case Operator::OPERATION_NOT: |
|
204 | + $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments); |
|
205 | + return new SearchBinaryOperator($trimmedType, $arguments); |
|
206 | + case Operator::OPERATION_EQUAL: |
|
207 | + case Operator::OPERATION_GREATER_OR_EQUAL_THAN: |
|
208 | + case Operator::OPERATION_GREATER_THAN: |
|
209 | + case Operator::OPERATION_LESS_OR_EQUAL_THAN: |
|
210 | + case Operator::OPERATION_LESS_THAN: |
|
211 | + case Operator::OPERATION_IS_LIKE: |
|
212 | + if (count($operator->arguments) !== 2) { |
|
213 | + throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
|
214 | + } |
|
215 | + if (!is_string($operator->arguments[0])) { |
|
216 | + throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
|
217 | + } |
|
218 | + if (!($operator->arguments[1] instanceof Literal)) { |
|
219 | + throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
|
220 | + } |
|
221 | + return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value)); |
|
222 | + case Operator::OPERATION_IS_COLLECTION: |
|
223 | + return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
|
224 | + default: |
|
225 | + throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')'); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * @param string $propertyName |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - private function mapPropertyNameToColumn($propertyName) { |
|
234 | - switch ($propertyName) { |
|
235 | - case '{DAV:}displayname': |
|
236 | - return 'name'; |
|
237 | - case '{DAV:}getcontenttype': |
|
238 | - return 'mimetype'; |
|
239 | - case '{DAV:}getlastmodified': |
|
240 | - return 'mtime'; |
|
241 | - case FilesPlugin::SIZE_PROPERTYNAME: |
|
242 | - return 'size'; |
|
243 | - case TagsPlugin::FAVORITE_PROPERTYNAME: |
|
244 | - return 'favorite'; |
|
245 | - case TagsPlugin::TAGS_PROPERTYNAME: |
|
246 | - return 'tagname'; |
|
247 | - case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME: |
|
248 | - return 'fileid'; |
|
249 | - default: |
|
250 | - throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
251 | - } |
|
252 | - } |
|
229 | + /** |
|
230 | + * @param string $propertyName |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + private function mapPropertyNameToColumn($propertyName) { |
|
234 | + switch ($propertyName) { |
|
235 | + case '{DAV:}displayname': |
|
236 | + return 'name'; |
|
237 | + case '{DAV:}getcontenttype': |
|
238 | + return 'mimetype'; |
|
239 | + case '{DAV:}getlastmodified': |
|
240 | + return 'mtime'; |
|
241 | + case FilesPlugin::SIZE_PROPERTYNAME: |
|
242 | + return 'size'; |
|
243 | + case TagsPlugin::FAVORITE_PROPERTYNAME: |
|
244 | + return 'favorite'; |
|
245 | + case TagsPlugin::TAGS_PROPERTYNAME: |
|
246 | + return 'tagname'; |
|
247 | + case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME: |
|
248 | + return 'fileid'; |
|
249 | + default: |
|
250 | + throw new \InvalidArgumentException('Unsupported property for search or order: ' . $propertyName); |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | - private function castValue($propertyName, $value) { |
|
255 | - $allProps = $this->getPropertyDefinitionsForScope('', ''); |
|
256 | - foreach ($allProps as $prop) { |
|
257 | - if ($prop->name === $propertyName) { |
|
258 | - $dataType = $prop->dataType; |
|
259 | - switch ($dataType) { |
|
260 | - case SearchPropertyDefinition::DATATYPE_BOOLEAN: |
|
261 | - return $value === 'yes'; |
|
262 | - case SearchPropertyDefinition::DATATYPE_DECIMAL: |
|
263 | - case SearchPropertyDefinition::DATATYPE_INTEGER: |
|
264 | - case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: |
|
265 | - return 0 + $value; |
|
266 | - case SearchPropertyDefinition::DATATYPE_DATETIME: |
|
267 | - if (is_numeric($value)) { |
|
268 | - return 0 + $value; |
|
269 | - } |
|
270 | - $date = \DateTime::createFromFormat(\DateTime::ATOM, $value); |
|
271 | - return ($date instanceof \DateTime) ? $date->getTimestamp() : 0; |
|
272 | - default: |
|
273 | - return $value; |
|
274 | - } |
|
275 | - } |
|
276 | - } |
|
277 | - return $value; |
|
278 | - } |
|
254 | + private function castValue($propertyName, $value) { |
|
255 | + $allProps = $this->getPropertyDefinitionsForScope('', ''); |
|
256 | + foreach ($allProps as $prop) { |
|
257 | + if ($prop->name === $propertyName) { |
|
258 | + $dataType = $prop->dataType; |
|
259 | + switch ($dataType) { |
|
260 | + case SearchPropertyDefinition::DATATYPE_BOOLEAN: |
|
261 | + return $value === 'yes'; |
|
262 | + case SearchPropertyDefinition::DATATYPE_DECIMAL: |
|
263 | + case SearchPropertyDefinition::DATATYPE_INTEGER: |
|
264 | + case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER: |
|
265 | + return 0 + $value; |
|
266 | + case SearchPropertyDefinition::DATATYPE_DATETIME: |
|
267 | + if (is_numeric($value)) { |
|
268 | + return 0 + $value; |
|
269 | + } |
|
270 | + $date = \DateTime::createFromFormat(\DateTime::ATOM, $value); |
|
271 | + return ($date instanceof \DateTime) ? $date->getTimestamp() : 0; |
|
272 | + default: |
|
273 | + return $value; |
|
274 | + } |
|
275 | + } |
|
276 | + } |
|
277 | + return $value; |
|
278 | + } |
|
279 | 279 | } |
@@ -37,118 +37,118 @@ |
||
37 | 37 | * Note that the read permissions can't be masked |
38 | 38 | */ |
39 | 39 | class PermissionsMask extends Wrapper { |
40 | - /** |
|
41 | - * @var int the permissions bits we want to keep |
|
42 | - */ |
|
43 | - private $mask; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
47 | - * |
|
48 | - * $storage: The storage the permissions mask should be applied on |
|
49 | - * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
50 | - */ |
|
51 | - public function __construct($arguments) { |
|
52 | - parent::__construct($arguments); |
|
53 | - $this->mask = $arguments['mask']; |
|
54 | - } |
|
55 | - |
|
56 | - private function checkMask($permissions) { |
|
57 | - return ($this->mask & $permissions) === $permissions; |
|
58 | - } |
|
59 | - |
|
60 | - public function isUpdatable($path) { |
|
61 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
62 | - } |
|
63 | - |
|
64 | - public function isCreatable($path) { |
|
65 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
66 | - } |
|
67 | - |
|
68 | - public function isDeletable($path) { |
|
69 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
70 | - } |
|
71 | - |
|
72 | - public function isSharable($path) { |
|
73 | - return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
74 | - } |
|
75 | - |
|
76 | - public function getPermissions($path) { |
|
77 | - return $this->storage->getPermissions($path) & $this->mask; |
|
78 | - } |
|
79 | - |
|
80 | - public function rename($path1, $path2) { |
|
81 | - $p = strpos($path1, $path2); |
|
82 | - if ($p === 0) { |
|
83 | - $part = substr($path1, strlen($path2)); |
|
84 | - //This is a rename of the transfer file to the original file |
|
85 | - if (strpos($part, '.ocTransferId') === 0) { |
|
86 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
87 | - } |
|
88 | - } |
|
89 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
90 | - } |
|
91 | - |
|
92 | - public function copy($path1, $path2) { |
|
93 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
94 | - } |
|
95 | - |
|
96 | - public function touch($path, $mtime = null) { |
|
97 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
98 | - return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
99 | - } |
|
100 | - |
|
101 | - public function mkdir($path) { |
|
102 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
103 | - } |
|
104 | - |
|
105 | - public function rmdir($path) { |
|
106 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
107 | - } |
|
108 | - |
|
109 | - public function unlink($path) { |
|
110 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
111 | - } |
|
112 | - |
|
113 | - public function file_put_contents($path, $data) { |
|
114 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
115 | - return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
116 | - } |
|
117 | - |
|
118 | - public function fopen($path, $mode) { |
|
119 | - if ($mode === 'r' or $mode === 'rb') { |
|
120 | - return parent::fopen($path, $mode); |
|
121 | - } else { |
|
122 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
123 | - return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * get a cache instance for the storage |
|
129 | - * |
|
130 | - * @param string $path |
|
131 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
132 | - * @return \OC\Files\Cache\Cache |
|
133 | - */ |
|
134 | - public function getCache($path = '', $storage = null) { |
|
135 | - if (!$storage) { |
|
136 | - $storage = $this; |
|
137 | - } |
|
138 | - $sourceCache = parent::getCache($path, $storage); |
|
139 | - return new CachePermissionsMask($sourceCache, $this->mask); |
|
140 | - } |
|
141 | - |
|
142 | - public function getMetaData($path) { |
|
143 | - $data = parent::getMetaData($path); |
|
144 | - |
|
145 | - if ($data && isset($data['permissions'])) { |
|
146 | - $data['permissions'] = $data['permissions'] & $this->mask; |
|
147 | - } |
|
148 | - return $data; |
|
149 | - } |
|
150 | - |
|
151 | - public function getScanner($path = '', $storage = null) { |
|
152 | - return parent::getScanner($path, $this->storage); |
|
153 | - } |
|
40 | + /** |
|
41 | + * @var int the permissions bits we want to keep |
|
42 | + */ |
|
43 | + private $mask; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
47 | + * |
|
48 | + * $storage: The storage the permissions mask should be applied on |
|
49 | + * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
50 | + */ |
|
51 | + public function __construct($arguments) { |
|
52 | + parent::__construct($arguments); |
|
53 | + $this->mask = $arguments['mask']; |
|
54 | + } |
|
55 | + |
|
56 | + private function checkMask($permissions) { |
|
57 | + return ($this->mask & $permissions) === $permissions; |
|
58 | + } |
|
59 | + |
|
60 | + public function isUpdatable($path) { |
|
61 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
62 | + } |
|
63 | + |
|
64 | + public function isCreatable($path) { |
|
65 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
66 | + } |
|
67 | + |
|
68 | + public function isDeletable($path) { |
|
69 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
70 | + } |
|
71 | + |
|
72 | + public function isSharable($path) { |
|
73 | + return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
74 | + } |
|
75 | + |
|
76 | + public function getPermissions($path) { |
|
77 | + return $this->storage->getPermissions($path) & $this->mask; |
|
78 | + } |
|
79 | + |
|
80 | + public function rename($path1, $path2) { |
|
81 | + $p = strpos($path1, $path2); |
|
82 | + if ($p === 0) { |
|
83 | + $part = substr($path1, strlen($path2)); |
|
84 | + //This is a rename of the transfer file to the original file |
|
85 | + if (strpos($part, '.ocTransferId') === 0) { |
|
86 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
87 | + } |
|
88 | + } |
|
89 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
90 | + } |
|
91 | + |
|
92 | + public function copy($path1, $path2) { |
|
93 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
94 | + } |
|
95 | + |
|
96 | + public function touch($path, $mtime = null) { |
|
97 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
98 | + return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
99 | + } |
|
100 | + |
|
101 | + public function mkdir($path) { |
|
102 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
103 | + } |
|
104 | + |
|
105 | + public function rmdir($path) { |
|
106 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
107 | + } |
|
108 | + |
|
109 | + public function unlink($path) { |
|
110 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
111 | + } |
|
112 | + |
|
113 | + public function file_put_contents($path, $data) { |
|
114 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
115 | + return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
116 | + } |
|
117 | + |
|
118 | + public function fopen($path, $mode) { |
|
119 | + if ($mode === 'r' or $mode === 'rb') { |
|
120 | + return parent::fopen($path, $mode); |
|
121 | + } else { |
|
122 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
123 | + return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * get a cache instance for the storage |
|
129 | + * |
|
130 | + * @param string $path |
|
131 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
132 | + * @return \OC\Files\Cache\Cache |
|
133 | + */ |
|
134 | + public function getCache($path = '', $storage = null) { |
|
135 | + if (!$storage) { |
|
136 | + $storage = $this; |
|
137 | + } |
|
138 | + $sourceCache = parent::getCache($path, $storage); |
|
139 | + return new CachePermissionsMask($sourceCache, $this->mask); |
|
140 | + } |
|
141 | + |
|
142 | + public function getMetaData($path) { |
|
143 | + $data = parent::getMetaData($path); |
|
144 | + |
|
145 | + if ($data && isset($data['permissions'])) { |
|
146 | + $data['permissions'] = $data['permissions'] & $this->mask; |
|
147 | + } |
|
148 | + return $data; |
|
149 | + } |
|
150 | + |
|
151 | + public function getScanner($path = '', $storage = null) { |
|
152 | + return parent::getScanner($path, $this->storage); |
|
153 | + } |
|
154 | 154 | } |
@@ -29,10 +29,10 @@ |
||
29 | 29 | */ |
30 | 30 | interface IProvider { |
31 | 31 | |
32 | - /** |
|
33 | - * @since 12.0 |
|
34 | - * @param IEntry $entry |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - public function process(IEntry $entry); |
|
32 | + /** |
|
33 | + * @since 12.0 |
|
34 | + * @param IEntry $entry |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + public function process(IEntry $entry); |
|
38 | 38 | } |
@@ -118,1598 +118,1598 @@ |
||
118 | 118 | * TODO: hookup all manager classes |
119 | 119 | */ |
120 | 120 | class Server extends ServerContainer implements IServerContainer { |
121 | - /** @var string */ |
|
122 | - private $webRoot; |
|
123 | - |
|
124 | - /** |
|
125 | - * @param string $webRoot |
|
126 | - * @param \OC\Config $config |
|
127 | - */ |
|
128 | - public function __construct($webRoot, \OC\Config $config) { |
|
129 | - parent::__construct(); |
|
130 | - $this->webRoot = $webRoot; |
|
131 | - |
|
132 | - $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
133 | - return $c; |
|
134 | - }); |
|
135 | - |
|
136 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
137 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
138 | - |
|
139 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
144 | - return new PreviewManager( |
|
145 | - $c->getConfig(), |
|
146 | - $c->getRootFolder(), |
|
147 | - $c->getAppDataDir('preview'), |
|
148 | - $c->getEventDispatcher(), |
|
149 | - $c->getSession()->get('user_id') |
|
150 | - ); |
|
151 | - }); |
|
152 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
153 | - |
|
154 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
155 | - return new \OC\Preview\Watcher( |
|
156 | - $c->getAppDataDir('preview') |
|
157 | - ); |
|
158 | - }); |
|
159 | - |
|
160 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
161 | - $view = new View(); |
|
162 | - $util = new Encryption\Util( |
|
163 | - $view, |
|
164 | - $c->getUserManager(), |
|
165 | - $c->getGroupManager(), |
|
166 | - $c->getConfig() |
|
167 | - ); |
|
168 | - return new Encryption\Manager( |
|
169 | - $c->getConfig(), |
|
170 | - $c->getLogger(), |
|
171 | - $c->getL10N('core'), |
|
172 | - new View(), |
|
173 | - $util, |
|
174 | - new ArrayCache() |
|
175 | - ); |
|
176 | - }); |
|
177 | - |
|
178 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
179 | - $util = new Encryption\Util( |
|
180 | - new View(), |
|
181 | - $c->getUserManager(), |
|
182 | - $c->getGroupManager(), |
|
183 | - $c->getConfig() |
|
184 | - ); |
|
185 | - return new Encryption\File($util); |
|
186 | - }); |
|
187 | - |
|
188 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
189 | - $view = new View(); |
|
190 | - $util = new Encryption\Util( |
|
191 | - $view, |
|
192 | - $c->getUserManager(), |
|
193 | - $c->getGroupManager(), |
|
194 | - $c->getConfig() |
|
195 | - ); |
|
196 | - |
|
197 | - return new Encryption\Keys\Storage($view, $util); |
|
198 | - }); |
|
199 | - $this->registerService('TagMapper', function (Server $c) { |
|
200 | - return new TagMapper($c->getDatabaseConnection()); |
|
201 | - }); |
|
202 | - |
|
203 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
204 | - $tagMapper = $c->query('TagMapper'); |
|
205 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
206 | - }); |
|
207 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
208 | - |
|
209 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
210 | - $config = $c->getConfig(); |
|
211 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
212 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
213 | - $factory = new $factoryClass($this); |
|
214 | - return $factory; |
|
215 | - }); |
|
216 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
217 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
218 | - }); |
|
219 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
220 | - |
|
221 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
222 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
223 | - }); |
|
224 | - $this->registerService('RootFolder', function (Server $c) { |
|
225 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
226 | - $view = new View(); |
|
227 | - $root = new Root( |
|
228 | - $manager, |
|
229 | - $view, |
|
230 | - null, |
|
231 | - $c->getUserMountCache(), |
|
232 | - $this->getLogger(), |
|
233 | - $this->getUserManager() |
|
234 | - ); |
|
235 | - $connector = new HookConnector($root, $view); |
|
236 | - $connector->viewToNode(); |
|
237 | - |
|
238 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
239 | - $previewConnector->connectWatcher(); |
|
240 | - |
|
241 | - return $root; |
|
242 | - }); |
|
243 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
244 | - |
|
245 | - $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
246 | - return new LazyRoot(function() use ($c) { |
|
247 | - return $c->query('RootFolder'); |
|
248 | - }); |
|
249 | - }); |
|
250 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
251 | - |
|
252 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
253 | - $config = $c->getConfig(); |
|
254 | - return new \OC\User\Manager($config); |
|
255 | - }); |
|
256 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
257 | - |
|
258 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
259 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
260 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
261 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
262 | - }); |
|
263 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
264 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
265 | - }); |
|
266 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
267 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
268 | - }); |
|
269 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
270 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
271 | - }); |
|
272 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
273 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
274 | - }); |
|
275 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
276 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
277 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
278 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
279 | - }); |
|
280 | - return $groupManager; |
|
281 | - }); |
|
282 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
283 | - |
|
284 | - $this->registerService(Store::class, function(Server $c) { |
|
285 | - $session = $c->getSession(); |
|
286 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
287 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
288 | - } else { |
|
289 | - $tokenProvider = null; |
|
290 | - } |
|
291 | - $logger = $c->getLogger(); |
|
292 | - return new Store($session, $logger, $tokenProvider); |
|
293 | - }); |
|
294 | - $this->registerAlias(IStore::class, Store::class); |
|
295 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
296 | - $dbConnection = $c->getDatabaseConnection(); |
|
297 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
298 | - }); |
|
299 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
300 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
301 | - $crypto = $c->getCrypto(); |
|
302 | - $config = $c->getConfig(); |
|
303 | - $logger = $c->getLogger(); |
|
304 | - $timeFactory = new TimeFactory(); |
|
305 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
306 | - }); |
|
307 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
308 | - |
|
309 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
310 | - $manager = $c->getUserManager(); |
|
311 | - $session = new \OC\Session\Memory(''); |
|
312 | - $timeFactory = new TimeFactory(); |
|
313 | - // Token providers might require a working database. This code |
|
314 | - // might however be called when ownCloud is not yet setup. |
|
315 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
316 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
317 | - } else { |
|
318 | - $defaultTokenProvider = null; |
|
319 | - } |
|
320 | - |
|
321 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
322 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
323 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
324 | - }); |
|
325 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
326 | - /** @var $user \OC\User\User */ |
|
327 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
328 | - }); |
|
329 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
330 | - /** @var $user \OC\User\User */ |
|
331 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
332 | - }); |
|
333 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
334 | - /** @var $user \OC\User\User */ |
|
335 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
336 | - }); |
|
337 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
338 | - /** @var $user \OC\User\User */ |
|
339 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
340 | - }); |
|
341 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
342 | - /** @var $user \OC\User\User */ |
|
343 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
344 | - }); |
|
345 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
346 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
347 | - }); |
|
348 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
349 | - /** @var $user \OC\User\User */ |
|
350 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
351 | - }); |
|
352 | - $userSession->listen('\OC\User', 'logout', function () { |
|
353 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
354 | - }); |
|
355 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
356 | - /** @var $user \OC\User\User */ |
|
357 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
|
358 | - }); |
|
359 | - return $userSession; |
|
360 | - }); |
|
361 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
362 | - |
|
363 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
364 | - return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
365 | - }); |
|
366 | - |
|
367 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
368 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
369 | - |
|
370 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
371 | - return new \OC\AllConfig( |
|
372 | - $c->getSystemConfig() |
|
373 | - ); |
|
374 | - }); |
|
375 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
376 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
377 | - |
|
378 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
379 | - return new \OC\SystemConfig($config); |
|
380 | - }); |
|
381 | - |
|
382 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
383 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
384 | - }); |
|
385 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
386 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
387 | - |
|
388 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
389 | - return new \OC\L10N\Factory( |
|
390 | - $c->getConfig(), |
|
391 | - $c->getRequest(), |
|
392 | - $c->getUserSession(), |
|
393 | - \OC::$SERVERROOT |
|
394 | - ); |
|
395 | - }); |
|
396 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
397 | - |
|
398 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
399 | - $config = $c->getConfig(); |
|
400 | - $cacheFactory = $c->getMemCacheFactory(); |
|
401 | - return new \OC\URLGenerator( |
|
402 | - $config, |
|
403 | - $cacheFactory |
|
404 | - ); |
|
405 | - }); |
|
406 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
407 | - |
|
408 | - $this->registerService('AppHelper', function ($c) { |
|
409 | - return new \OC\AppHelper(); |
|
410 | - }); |
|
411 | - $this->registerService('AppFetcher', function ($c) { |
|
412 | - return new AppFetcher( |
|
413 | - $this->getAppDataDir('appstore'), |
|
414 | - $this->getHTTPClientService(), |
|
415 | - $this->query(TimeFactory::class), |
|
416 | - $this->getConfig() |
|
417 | - ); |
|
418 | - }); |
|
419 | - $this->registerService('CategoryFetcher', function ($c) { |
|
420 | - return new CategoryFetcher( |
|
421 | - $this->getAppDataDir('appstore'), |
|
422 | - $this->getHTTPClientService(), |
|
423 | - $this->query(TimeFactory::class), |
|
424 | - $this->getConfig() |
|
425 | - ); |
|
426 | - }); |
|
427 | - |
|
428 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
429 | - return new Cache\File(); |
|
430 | - }); |
|
431 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
432 | - |
|
433 | - $this->registerService(Factory::class, function (Server $c) { |
|
434 | - $config = $c->getConfig(); |
|
435 | - |
|
436 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
437 | - $v = \OC_App::getAppVersions(); |
|
438 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
439 | - $version = implode(',', $v); |
|
440 | - $instanceId = \OC_Util::getInstanceId(); |
|
441 | - $path = \OC::$SERVERROOT; |
|
442 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
443 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
444 | - $config->getSystemValue('memcache.local', null), |
|
445 | - $config->getSystemValue('memcache.distributed', null), |
|
446 | - $config->getSystemValue('memcache.locking', null) |
|
447 | - ); |
|
448 | - } |
|
449 | - |
|
450 | - return new \OC\Memcache\Factory('', $c->getLogger(), |
|
451 | - '\\OC\\Memcache\\ArrayCache', |
|
452 | - '\\OC\\Memcache\\ArrayCache', |
|
453 | - '\\OC\\Memcache\\ArrayCache' |
|
454 | - ); |
|
455 | - }); |
|
456 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
457 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
458 | - |
|
459 | - $this->registerService('RedisFactory', function (Server $c) { |
|
460 | - $systemConfig = $c->getSystemConfig(); |
|
461 | - return new RedisFactory($systemConfig); |
|
462 | - }); |
|
463 | - |
|
464 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
465 | - return new \OC\Activity\Manager( |
|
466 | - $c->getRequest(), |
|
467 | - $c->getUserSession(), |
|
468 | - $c->getConfig(), |
|
469 | - $c->query(IValidator::class) |
|
470 | - ); |
|
471 | - }); |
|
472 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
473 | - |
|
474 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
475 | - return new \OC\Activity\EventMerger( |
|
476 | - $c->getL10N('lib') |
|
477 | - ); |
|
478 | - }); |
|
479 | - $this->registerAlias(IValidator::class, Validator::class); |
|
480 | - |
|
481 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
482 | - return new AvatarManager( |
|
483 | - $c->getUserManager(), |
|
484 | - $c->getAppDataDir('avatar'), |
|
485 | - $c->getL10N('lib'), |
|
486 | - $c->getLogger(), |
|
487 | - $c->getConfig() |
|
488 | - ); |
|
489 | - }); |
|
490 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
491 | - |
|
492 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
493 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
494 | - $logger = Log::getLogClass($logType); |
|
495 | - call_user_func(array($logger, 'init')); |
|
496 | - |
|
497 | - return new Log($logger); |
|
498 | - }); |
|
499 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
500 | - |
|
501 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
502 | - $config = $c->getConfig(); |
|
503 | - return new \OC\BackgroundJob\JobList( |
|
504 | - $c->getDatabaseConnection(), |
|
505 | - $config, |
|
506 | - new TimeFactory() |
|
507 | - ); |
|
508 | - }); |
|
509 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
510 | - |
|
511 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
512 | - $cacheFactory = $c->getMemCacheFactory(); |
|
513 | - $logger = $c->getLogger(); |
|
514 | - if ($cacheFactory->isAvailable()) { |
|
515 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
516 | - } else { |
|
517 | - $router = new \OC\Route\Router($logger); |
|
518 | - } |
|
519 | - return $router; |
|
520 | - }); |
|
521 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
522 | - |
|
523 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
524 | - return new Search(); |
|
525 | - }); |
|
526 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
527 | - |
|
528 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
529 | - return new SecureRandom(); |
|
530 | - }); |
|
531 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
532 | - |
|
533 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
534 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
535 | - }); |
|
536 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
537 | - |
|
538 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
539 | - return new Hasher($c->getConfig()); |
|
540 | - }); |
|
541 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
542 | - |
|
543 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
544 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
545 | - }); |
|
546 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
547 | - |
|
548 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
549 | - $systemConfig = $c->getSystemConfig(); |
|
550 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
551 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
552 | - if (!$factory->isValidType($type)) { |
|
553 | - throw new \OC\DatabaseException('Invalid database type'); |
|
554 | - } |
|
555 | - $connectionParams = $factory->createConnectionParams(); |
|
556 | - $connection = $factory->getConnection($type, $connectionParams); |
|
557 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
558 | - return $connection; |
|
559 | - }); |
|
560 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
561 | - |
|
562 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
563 | - $config = $c->getConfig(); |
|
564 | - return new HTTPHelper( |
|
565 | - $config, |
|
566 | - $c->getHTTPClientService() |
|
567 | - ); |
|
568 | - }); |
|
569 | - |
|
570 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
571 | - $user = \OC_User::getUser(); |
|
572 | - $uid = $user ? $user : null; |
|
573 | - return new ClientService( |
|
574 | - $c->getConfig(), |
|
575 | - new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
576 | - ); |
|
577 | - }); |
|
578 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
579 | - |
|
580 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
581 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
582 | - return new EventLogger(); |
|
583 | - } else { |
|
584 | - return new NullEventLogger(); |
|
585 | - } |
|
586 | - }); |
|
587 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
588 | - |
|
589 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
590 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
591 | - return new QueryLogger(); |
|
592 | - } else { |
|
593 | - return new NullQueryLogger(); |
|
594 | - } |
|
595 | - }); |
|
596 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
597 | - |
|
598 | - $this->registerService(TempManager::class, function (Server $c) { |
|
599 | - return new TempManager( |
|
600 | - $c->getLogger(), |
|
601 | - $c->getConfig() |
|
602 | - ); |
|
603 | - }); |
|
604 | - $this->registerAlias('TempManager', TempManager::class); |
|
605 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
606 | - |
|
607 | - $this->registerService(AppManager::class, function (Server $c) { |
|
608 | - return new \OC\App\AppManager( |
|
609 | - $c->getUserSession(), |
|
610 | - $c->getAppConfig(), |
|
611 | - $c->getGroupManager(), |
|
612 | - $c->getMemCacheFactory(), |
|
613 | - $c->getEventDispatcher() |
|
614 | - ); |
|
615 | - }); |
|
616 | - $this->registerAlias('AppManager', AppManager::class); |
|
617 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
618 | - |
|
619 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
620 | - return new DateTimeZone( |
|
621 | - $c->getConfig(), |
|
622 | - $c->getSession() |
|
623 | - ); |
|
624 | - }); |
|
625 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
626 | - |
|
627 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
628 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
629 | - |
|
630 | - return new DateTimeFormatter( |
|
631 | - $c->getDateTimeZone()->getTimeZone(), |
|
632 | - $c->getL10N('lib', $language) |
|
633 | - ); |
|
634 | - }); |
|
635 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
636 | - |
|
637 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
638 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
639 | - $listener = new UserMountCacheListener($mountCache); |
|
640 | - $listener->listen($c->getUserManager()); |
|
641 | - return $mountCache; |
|
642 | - }); |
|
643 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
644 | - |
|
645 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
646 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
647 | - $mountCache = $c->query('UserMountCache'); |
|
648 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
649 | - |
|
650 | - // builtin providers |
|
651 | - |
|
652 | - $config = $c->getConfig(); |
|
653 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
654 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
655 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
656 | - |
|
657 | - return $manager; |
|
658 | - }); |
|
659 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
660 | - |
|
661 | - $this->registerService('IniWrapper', function ($c) { |
|
662 | - return new IniGetWrapper(); |
|
663 | - }); |
|
664 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
665 | - $jobList = $c->getJobList(); |
|
666 | - return new AsyncBus($jobList); |
|
667 | - }); |
|
668 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
669 | - return new TrustedDomainHelper($this->getConfig()); |
|
670 | - }); |
|
671 | - $this->registerService('Throttler', function(Server $c) { |
|
672 | - return new Throttler( |
|
673 | - $c->getDatabaseConnection(), |
|
674 | - new TimeFactory(), |
|
675 | - $c->getLogger(), |
|
676 | - $c->getConfig() |
|
677 | - ); |
|
678 | - }); |
|
679 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
680 | - // IConfig and IAppManager requires a working database. This code |
|
681 | - // might however be called when ownCloud is not yet setup. |
|
682 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
683 | - $config = $c->getConfig(); |
|
684 | - $appManager = $c->getAppManager(); |
|
685 | - } else { |
|
686 | - $config = null; |
|
687 | - $appManager = null; |
|
688 | - } |
|
689 | - |
|
690 | - return new Checker( |
|
691 | - new EnvironmentHelper(), |
|
692 | - new FileAccessHelper(), |
|
693 | - new AppLocator(), |
|
694 | - $config, |
|
695 | - $c->getMemCacheFactory(), |
|
696 | - $appManager, |
|
697 | - $c->getTempManager() |
|
698 | - ); |
|
699 | - }); |
|
700 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
701 | - if (isset($this['urlParams'])) { |
|
702 | - $urlParams = $this['urlParams']; |
|
703 | - } else { |
|
704 | - $urlParams = []; |
|
705 | - } |
|
706 | - |
|
707 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
708 | - && in_array('fakeinput', stream_get_wrappers()) |
|
709 | - ) { |
|
710 | - $stream = 'fakeinput://data'; |
|
711 | - } else { |
|
712 | - $stream = 'php://input'; |
|
713 | - } |
|
714 | - |
|
715 | - return new Request( |
|
716 | - [ |
|
717 | - 'get' => $_GET, |
|
718 | - 'post' => $_POST, |
|
719 | - 'files' => $_FILES, |
|
720 | - 'server' => $_SERVER, |
|
721 | - 'env' => $_ENV, |
|
722 | - 'cookies' => $_COOKIE, |
|
723 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
724 | - ? $_SERVER['REQUEST_METHOD'] |
|
725 | - : null, |
|
726 | - 'urlParams' => $urlParams, |
|
727 | - ], |
|
728 | - $this->getSecureRandom(), |
|
729 | - $this->getConfig(), |
|
730 | - $this->getCsrfTokenManager(), |
|
731 | - $stream |
|
732 | - ); |
|
733 | - }); |
|
734 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
735 | - |
|
736 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
737 | - return new Mailer( |
|
738 | - $c->getConfig(), |
|
739 | - $c->getLogger(), |
|
740 | - $c->getThemingDefaults() |
|
741 | - ); |
|
742 | - }); |
|
743 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
744 | - |
|
745 | - $this->registerService('LDAPProvider', function(Server $c) { |
|
746 | - $config = $c->getConfig(); |
|
747 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
748 | - if(is_null($factoryClass)) { |
|
749 | - throw new \Exception('ldapProviderFactory not set'); |
|
750 | - } |
|
751 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
752 | - $factory = new $factoryClass($this); |
|
753 | - return $factory->getLDAPProvider(); |
|
754 | - }); |
|
755 | - $this->registerService('LockingProvider', function (Server $c) { |
|
756 | - $ini = $c->getIniWrapper(); |
|
757 | - $config = $c->getConfig(); |
|
758 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
759 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
760 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
761 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
762 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
763 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
764 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
765 | - } |
|
766 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
767 | - } |
|
768 | - return new NoopLockingProvider(); |
|
769 | - }); |
|
770 | - |
|
771 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
772 | - return new \OC\Files\Mount\Manager(); |
|
773 | - }); |
|
774 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
775 | - |
|
776 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
777 | - return new \OC\Files\Type\Detection( |
|
778 | - $c->getURLGenerator(), |
|
779 | - \OC::$configDir, |
|
780 | - \OC::$SERVERROOT . '/resources/config/' |
|
781 | - ); |
|
782 | - }); |
|
783 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
784 | - |
|
785 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
786 | - return new \OC\Files\Type\Loader( |
|
787 | - $c->getDatabaseConnection() |
|
788 | - ); |
|
789 | - }); |
|
790 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
791 | - |
|
792 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
793 | - return new Manager( |
|
794 | - $c->query(IValidator::class) |
|
795 | - ); |
|
796 | - }); |
|
797 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
798 | - |
|
799 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
800 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
801 | - $manager->registerCapability(function () use ($c) { |
|
802 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
803 | - }); |
|
804 | - return $manager; |
|
805 | - }); |
|
806 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
807 | - |
|
808 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
809 | - $config = $c->getConfig(); |
|
810 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
811 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
812 | - $factory = new $factoryClass($this); |
|
813 | - return $factory->getManager(); |
|
814 | - }); |
|
815 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
816 | - |
|
817 | - $this->registerService('ThemingDefaults', function(Server $c) { |
|
818 | - /* |
|
121 | + /** @var string */ |
|
122 | + private $webRoot; |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $webRoot |
|
126 | + * @param \OC\Config $config |
|
127 | + */ |
|
128 | + public function __construct($webRoot, \OC\Config $config) { |
|
129 | + parent::__construct(); |
|
130 | + $this->webRoot = $webRoot; |
|
131 | + |
|
132 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
133 | + return $c; |
|
134 | + }); |
|
135 | + |
|
136 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
137 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
138 | + |
|
139 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
144 | + return new PreviewManager( |
|
145 | + $c->getConfig(), |
|
146 | + $c->getRootFolder(), |
|
147 | + $c->getAppDataDir('preview'), |
|
148 | + $c->getEventDispatcher(), |
|
149 | + $c->getSession()->get('user_id') |
|
150 | + ); |
|
151 | + }); |
|
152 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
153 | + |
|
154 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
155 | + return new \OC\Preview\Watcher( |
|
156 | + $c->getAppDataDir('preview') |
|
157 | + ); |
|
158 | + }); |
|
159 | + |
|
160 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
161 | + $view = new View(); |
|
162 | + $util = new Encryption\Util( |
|
163 | + $view, |
|
164 | + $c->getUserManager(), |
|
165 | + $c->getGroupManager(), |
|
166 | + $c->getConfig() |
|
167 | + ); |
|
168 | + return new Encryption\Manager( |
|
169 | + $c->getConfig(), |
|
170 | + $c->getLogger(), |
|
171 | + $c->getL10N('core'), |
|
172 | + new View(), |
|
173 | + $util, |
|
174 | + new ArrayCache() |
|
175 | + ); |
|
176 | + }); |
|
177 | + |
|
178 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
179 | + $util = new Encryption\Util( |
|
180 | + new View(), |
|
181 | + $c->getUserManager(), |
|
182 | + $c->getGroupManager(), |
|
183 | + $c->getConfig() |
|
184 | + ); |
|
185 | + return new Encryption\File($util); |
|
186 | + }); |
|
187 | + |
|
188 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
189 | + $view = new View(); |
|
190 | + $util = new Encryption\Util( |
|
191 | + $view, |
|
192 | + $c->getUserManager(), |
|
193 | + $c->getGroupManager(), |
|
194 | + $c->getConfig() |
|
195 | + ); |
|
196 | + |
|
197 | + return new Encryption\Keys\Storage($view, $util); |
|
198 | + }); |
|
199 | + $this->registerService('TagMapper', function (Server $c) { |
|
200 | + return new TagMapper($c->getDatabaseConnection()); |
|
201 | + }); |
|
202 | + |
|
203 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
204 | + $tagMapper = $c->query('TagMapper'); |
|
205 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
206 | + }); |
|
207 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
208 | + |
|
209 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
210 | + $config = $c->getConfig(); |
|
211 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
212 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
213 | + $factory = new $factoryClass($this); |
|
214 | + return $factory; |
|
215 | + }); |
|
216 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
217 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
218 | + }); |
|
219 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
220 | + |
|
221 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
222 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
223 | + }); |
|
224 | + $this->registerService('RootFolder', function (Server $c) { |
|
225 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
226 | + $view = new View(); |
|
227 | + $root = new Root( |
|
228 | + $manager, |
|
229 | + $view, |
|
230 | + null, |
|
231 | + $c->getUserMountCache(), |
|
232 | + $this->getLogger(), |
|
233 | + $this->getUserManager() |
|
234 | + ); |
|
235 | + $connector = new HookConnector($root, $view); |
|
236 | + $connector->viewToNode(); |
|
237 | + |
|
238 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
239 | + $previewConnector->connectWatcher(); |
|
240 | + |
|
241 | + return $root; |
|
242 | + }); |
|
243 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
244 | + |
|
245 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
246 | + return new LazyRoot(function() use ($c) { |
|
247 | + return $c->query('RootFolder'); |
|
248 | + }); |
|
249 | + }); |
|
250 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
251 | + |
|
252 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
253 | + $config = $c->getConfig(); |
|
254 | + return new \OC\User\Manager($config); |
|
255 | + }); |
|
256 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
257 | + |
|
258 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
259 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
260 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
261 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
262 | + }); |
|
263 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
264 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
265 | + }); |
|
266 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
267 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
268 | + }); |
|
269 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
270 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
271 | + }); |
|
272 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
273 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
274 | + }); |
|
275 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
276 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
277 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
278 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
279 | + }); |
|
280 | + return $groupManager; |
|
281 | + }); |
|
282 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
283 | + |
|
284 | + $this->registerService(Store::class, function(Server $c) { |
|
285 | + $session = $c->getSession(); |
|
286 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
287 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
288 | + } else { |
|
289 | + $tokenProvider = null; |
|
290 | + } |
|
291 | + $logger = $c->getLogger(); |
|
292 | + return new Store($session, $logger, $tokenProvider); |
|
293 | + }); |
|
294 | + $this->registerAlias(IStore::class, Store::class); |
|
295 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
296 | + $dbConnection = $c->getDatabaseConnection(); |
|
297 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
298 | + }); |
|
299 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
300 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
301 | + $crypto = $c->getCrypto(); |
|
302 | + $config = $c->getConfig(); |
|
303 | + $logger = $c->getLogger(); |
|
304 | + $timeFactory = new TimeFactory(); |
|
305 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
306 | + }); |
|
307 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
308 | + |
|
309 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
310 | + $manager = $c->getUserManager(); |
|
311 | + $session = new \OC\Session\Memory(''); |
|
312 | + $timeFactory = new TimeFactory(); |
|
313 | + // Token providers might require a working database. This code |
|
314 | + // might however be called when ownCloud is not yet setup. |
|
315 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
316 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
317 | + } else { |
|
318 | + $defaultTokenProvider = null; |
|
319 | + } |
|
320 | + |
|
321 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
322 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
323 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
324 | + }); |
|
325 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
326 | + /** @var $user \OC\User\User */ |
|
327 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
328 | + }); |
|
329 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
330 | + /** @var $user \OC\User\User */ |
|
331 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
332 | + }); |
|
333 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
334 | + /** @var $user \OC\User\User */ |
|
335 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
336 | + }); |
|
337 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
338 | + /** @var $user \OC\User\User */ |
|
339 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
340 | + }); |
|
341 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
342 | + /** @var $user \OC\User\User */ |
|
343 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
344 | + }); |
|
345 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
346 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
347 | + }); |
|
348 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
349 | + /** @var $user \OC\User\User */ |
|
350 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
351 | + }); |
|
352 | + $userSession->listen('\OC\User', 'logout', function () { |
|
353 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
354 | + }); |
|
355 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
356 | + /** @var $user \OC\User\User */ |
|
357 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
|
358 | + }); |
|
359 | + return $userSession; |
|
360 | + }); |
|
361 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
362 | + |
|
363 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
364 | + return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
365 | + }); |
|
366 | + |
|
367 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
368 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
369 | + |
|
370 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
371 | + return new \OC\AllConfig( |
|
372 | + $c->getSystemConfig() |
|
373 | + ); |
|
374 | + }); |
|
375 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
376 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
377 | + |
|
378 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
379 | + return new \OC\SystemConfig($config); |
|
380 | + }); |
|
381 | + |
|
382 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
383 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
384 | + }); |
|
385 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
386 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
387 | + |
|
388 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
389 | + return new \OC\L10N\Factory( |
|
390 | + $c->getConfig(), |
|
391 | + $c->getRequest(), |
|
392 | + $c->getUserSession(), |
|
393 | + \OC::$SERVERROOT |
|
394 | + ); |
|
395 | + }); |
|
396 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
397 | + |
|
398 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
399 | + $config = $c->getConfig(); |
|
400 | + $cacheFactory = $c->getMemCacheFactory(); |
|
401 | + return new \OC\URLGenerator( |
|
402 | + $config, |
|
403 | + $cacheFactory |
|
404 | + ); |
|
405 | + }); |
|
406 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
407 | + |
|
408 | + $this->registerService('AppHelper', function ($c) { |
|
409 | + return new \OC\AppHelper(); |
|
410 | + }); |
|
411 | + $this->registerService('AppFetcher', function ($c) { |
|
412 | + return new AppFetcher( |
|
413 | + $this->getAppDataDir('appstore'), |
|
414 | + $this->getHTTPClientService(), |
|
415 | + $this->query(TimeFactory::class), |
|
416 | + $this->getConfig() |
|
417 | + ); |
|
418 | + }); |
|
419 | + $this->registerService('CategoryFetcher', function ($c) { |
|
420 | + return new CategoryFetcher( |
|
421 | + $this->getAppDataDir('appstore'), |
|
422 | + $this->getHTTPClientService(), |
|
423 | + $this->query(TimeFactory::class), |
|
424 | + $this->getConfig() |
|
425 | + ); |
|
426 | + }); |
|
427 | + |
|
428 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
429 | + return new Cache\File(); |
|
430 | + }); |
|
431 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
432 | + |
|
433 | + $this->registerService(Factory::class, function (Server $c) { |
|
434 | + $config = $c->getConfig(); |
|
435 | + |
|
436 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
437 | + $v = \OC_App::getAppVersions(); |
|
438 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
439 | + $version = implode(',', $v); |
|
440 | + $instanceId = \OC_Util::getInstanceId(); |
|
441 | + $path = \OC::$SERVERROOT; |
|
442 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
443 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
444 | + $config->getSystemValue('memcache.local', null), |
|
445 | + $config->getSystemValue('memcache.distributed', null), |
|
446 | + $config->getSystemValue('memcache.locking', null) |
|
447 | + ); |
|
448 | + } |
|
449 | + |
|
450 | + return new \OC\Memcache\Factory('', $c->getLogger(), |
|
451 | + '\\OC\\Memcache\\ArrayCache', |
|
452 | + '\\OC\\Memcache\\ArrayCache', |
|
453 | + '\\OC\\Memcache\\ArrayCache' |
|
454 | + ); |
|
455 | + }); |
|
456 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
457 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
458 | + |
|
459 | + $this->registerService('RedisFactory', function (Server $c) { |
|
460 | + $systemConfig = $c->getSystemConfig(); |
|
461 | + return new RedisFactory($systemConfig); |
|
462 | + }); |
|
463 | + |
|
464 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
465 | + return new \OC\Activity\Manager( |
|
466 | + $c->getRequest(), |
|
467 | + $c->getUserSession(), |
|
468 | + $c->getConfig(), |
|
469 | + $c->query(IValidator::class) |
|
470 | + ); |
|
471 | + }); |
|
472 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
473 | + |
|
474 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
475 | + return new \OC\Activity\EventMerger( |
|
476 | + $c->getL10N('lib') |
|
477 | + ); |
|
478 | + }); |
|
479 | + $this->registerAlias(IValidator::class, Validator::class); |
|
480 | + |
|
481 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
482 | + return new AvatarManager( |
|
483 | + $c->getUserManager(), |
|
484 | + $c->getAppDataDir('avatar'), |
|
485 | + $c->getL10N('lib'), |
|
486 | + $c->getLogger(), |
|
487 | + $c->getConfig() |
|
488 | + ); |
|
489 | + }); |
|
490 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
491 | + |
|
492 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
493 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
494 | + $logger = Log::getLogClass($logType); |
|
495 | + call_user_func(array($logger, 'init')); |
|
496 | + |
|
497 | + return new Log($logger); |
|
498 | + }); |
|
499 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
500 | + |
|
501 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
502 | + $config = $c->getConfig(); |
|
503 | + return new \OC\BackgroundJob\JobList( |
|
504 | + $c->getDatabaseConnection(), |
|
505 | + $config, |
|
506 | + new TimeFactory() |
|
507 | + ); |
|
508 | + }); |
|
509 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
510 | + |
|
511 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
512 | + $cacheFactory = $c->getMemCacheFactory(); |
|
513 | + $logger = $c->getLogger(); |
|
514 | + if ($cacheFactory->isAvailable()) { |
|
515 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
516 | + } else { |
|
517 | + $router = new \OC\Route\Router($logger); |
|
518 | + } |
|
519 | + return $router; |
|
520 | + }); |
|
521 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
522 | + |
|
523 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
524 | + return new Search(); |
|
525 | + }); |
|
526 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
527 | + |
|
528 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
529 | + return new SecureRandom(); |
|
530 | + }); |
|
531 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
532 | + |
|
533 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
534 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
535 | + }); |
|
536 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
537 | + |
|
538 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
539 | + return new Hasher($c->getConfig()); |
|
540 | + }); |
|
541 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
542 | + |
|
543 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
544 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
545 | + }); |
|
546 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
547 | + |
|
548 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
549 | + $systemConfig = $c->getSystemConfig(); |
|
550 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
551 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
552 | + if (!$factory->isValidType($type)) { |
|
553 | + throw new \OC\DatabaseException('Invalid database type'); |
|
554 | + } |
|
555 | + $connectionParams = $factory->createConnectionParams(); |
|
556 | + $connection = $factory->getConnection($type, $connectionParams); |
|
557 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
558 | + return $connection; |
|
559 | + }); |
|
560 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
561 | + |
|
562 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
563 | + $config = $c->getConfig(); |
|
564 | + return new HTTPHelper( |
|
565 | + $config, |
|
566 | + $c->getHTTPClientService() |
|
567 | + ); |
|
568 | + }); |
|
569 | + |
|
570 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
571 | + $user = \OC_User::getUser(); |
|
572 | + $uid = $user ? $user : null; |
|
573 | + return new ClientService( |
|
574 | + $c->getConfig(), |
|
575 | + new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
576 | + ); |
|
577 | + }); |
|
578 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
579 | + |
|
580 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
581 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
582 | + return new EventLogger(); |
|
583 | + } else { |
|
584 | + return new NullEventLogger(); |
|
585 | + } |
|
586 | + }); |
|
587 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
588 | + |
|
589 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
590 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
591 | + return new QueryLogger(); |
|
592 | + } else { |
|
593 | + return new NullQueryLogger(); |
|
594 | + } |
|
595 | + }); |
|
596 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
597 | + |
|
598 | + $this->registerService(TempManager::class, function (Server $c) { |
|
599 | + return new TempManager( |
|
600 | + $c->getLogger(), |
|
601 | + $c->getConfig() |
|
602 | + ); |
|
603 | + }); |
|
604 | + $this->registerAlias('TempManager', TempManager::class); |
|
605 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
606 | + |
|
607 | + $this->registerService(AppManager::class, function (Server $c) { |
|
608 | + return new \OC\App\AppManager( |
|
609 | + $c->getUserSession(), |
|
610 | + $c->getAppConfig(), |
|
611 | + $c->getGroupManager(), |
|
612 | + $c->getMemCacheFactory(), |
|
613 | + $c->getEventDispatcher() |
|
614 | + ); |
|
615 | + }); |
|
616 | + $this->registerAlias('AppManager', AppManager::class); |
|
617 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
618 | + |
|
619 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
620 | + return new DateTimeZone( |
|
621 | + $c->getConfig(), |
|
622 | + $c->getSession() |
|
623 | + ); |
|
624 | + }); |
|
625 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
626 | + |
|
627 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
628 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
629 | + |
|
630 | + return new DateTimeFormatter( |
|
631 | + $c->getDateTimeZone()->getTimeZone(), |
|
632 | + $c->getL10N('lib', $language) |
|
633 | + ); |
|
634 | + }); |
|
635 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
636 | + |
|
637 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
638 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
639 | + $listener = new UserMountCacheListener($mountCache); |
|
640 | + $listener->listen($c->getUserManager()); |
|
641 | + return $mountCache; |
|
642 | + }); |
|
643 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
644 | + |
|
645 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
646 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
647 | + $mountCache = $c->query('UserMountCache'); |
|
648 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
649 | + |
|
650 | + // builtin providers |
|
651 | + |
|
652 | + $config = $c->getConfig(); |
|
653 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
654 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
655 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
656 | + |
|
657 | + return $manager; |
|
658 | + }); |
|
659 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
660 | + |
|
661 | + $this->registerService('IniWrapper', function ($c) { |
|
662 | + return new IniGetWrapper(); |
|
663 | + }); |
|
664 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
665 | + $jobList = $c->getJobList(); |
|
666 | + return new AsyncBus($jobList); |
|
667 | + }); |
|
668 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
669 | + return new TrustedDomainHelper($this->getConfig()); |
|
670 | + }); |
|
671 | + $this->registerService('Throttler', function(Server $c) { |
|
672 | + return new Throttler( |
|
673 | + $c->getDatabaseConnection(), |
|
674 | + new TimeFactory(), |
|
675 | + $c->getLogger(), |
|
676 | + $c->getConfig() |
|
677 | + ); |
|
678 | + }); |
|
679 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
680 | + // IConfig and IAppManager requires a working database. This code |
|
681 | + // might however be called when ownCloud is not yet setup. |
|
682 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
683 | + $config = $c->getConfig(); |
|
684 | + $appManager = $c->getAppManager(); |
|
685 | + } else { |
|
686 | + $config = null; |
|
687 | + $appManager = null; |
|
688 | + } |
|
689 | + |
|
690 | + return new Checker( |
|
691 | + new EnvironmentHelper(), |
|
692 | + new FileAccessHelper(), |
|
693 | + new AppLocator(), |
|
694 | + $config, |
|
695 | + $c->getMemCacheFactory(), |
|
696 | + $appManager, |
|
697 | + $c->getTempManager() |
|
698 | + ); |
|
699 | + }); |
|
700 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
701 | + if (isset($this['urlParams'])) { |
|
702 | + $urlParams = $this['urlParams']; |
|
703 | + } else { |
|
704 | + $urlParams = []; |
|
705 | + } |
|
706 | + |
|
707 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
708 | + && in_array('fakeinput', stream_get_wrappers()) |
|
709 | + ) { |
|
710 | + $stream = 'fakeinput://data'; |
|
711 | + } else { |
|
712 | + $stream = 'php://input'; |
|
713 | + } |
|
714 | + |
|
715 | + return new Request( |
|
716 | + [ |
|
717 | + 'get' => $_GET, |
|
718 | + 'post' => $_POST, |
|
719 | + 'files' => $_FILES, |
|
720 | + 'server' => $_SERVER, |
|
721 | + 'env' => $_ENV, |
|
722 | + 'cookies' => $_COOKIE, |
|
723 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
724 | + ? $_SERVER['REQUEST_METHOD'] |
|
725 | + : null, |
|
726 | + 'urlParams' => $urlParams, |
|
727 | + ], |
|
728 | + $this->getSecureRandom(), |
|
729 | + $this->getConfig(), |
|
730 | + $this->getCsrfTokenManager(), |
|
731 | + $stream |
|
732 | + ); |
|
733 | + }); |
|
734 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
735 | + |
|
736 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
737 | + return new Mailer( |
|
738 | + $c->getConfig(), |
|
739 | + $c->getLogger(), |
|
740 | + $c->getThemingDefaults() |
|
741 | + ); |
|
742 | + }); |
|
743 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
744 | + |
|
745 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
746 | + $config = $c->getConfig(); |
|
747 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
748 | + if(is_null($factoryClass)) { |
|
749 | + throw new \Exception('ldapProviderFactory not set'); |
|
750 | + } |
|
751 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
752 | + $factory = new $factoryClass($this); |
|
753 | + return $factory->getLDAPProvider(); |
|
754 | + }); |
|
755 | + $this->registerService('LockingProvider', function (Server $c) { |
|
756 | + $ini = $c->getIniWrapper(); |
|
757 | + $config = $c->getConfig(); |
|
758 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
759 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
760 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
761 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
762 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
763 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
764 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
765 | + } |
|
766 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
767 | + } |
|
768 | + return new NoopLockingProvider(); |
|
769 | + }); |
|
770 | + |
|
771 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
772 | + return new \OC\Files\Mount\Manager(); |
|
773 | + }); |
|
774 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
775 | + |
|
776 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
777 | + return new \OC\Files\Type\Detection( |
|
778 | + $c->getURLGenerator(), |
|
779 | + \OC::$configDir, |
|
780 | + \OC::$SERVERROOT . '/resources/config/' |
|
781 | + ); |
|
782 | + }); |
|
783 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
784 | + |
|
785 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
786 | + return new \OC\Files\Type\Loader( |
|
787 | + $c->getDatabaseConnection() |
|
788 | + ); |
|
789 | + }); |
|
790 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
791 | + |
|
792 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
793 | + return new Manager( |
|
794 | + $c->query(IValidator::class) |
|
795 | + ); |
|
796 | + }); |
|
797 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
798 | + |
|
799 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
800 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
801 | + $manager->registerCapability(function () use ($c) { |
|
802 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
803 | + }); |
|
804 | + return $manager; |
|
805 | + }); |
|
806 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
807 | + |
|
808 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
809 | + $config = $c->getConfig(); |
|
810 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
811 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
812 | + $factory = new $factoryClass($this); |
|
813 | + return $factory->getManager(); |
|
814 | + }); |
|
815 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
816 | + |
|
817 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
818 | + /* |
|
819 | 819 | * Dark magic for autoloader. |
820 | 820 | * If we do a class_exists it will try to load the class which will |
821 | 821 | * make composer cache the result. Resulting in errors when enabling |
822 | 822 | * the theming app. |
823 | 823 | */ |
824 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
825 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
826 | - $classExists = true; |
|
827 | - } else { |
|
828 | - $classExists = false; |
|
829 | - } |
|
830 | - |
|
831 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
832 | - return new ThemingDefaults( |
|
833 | - $c->getConfig(), |
|
834 | - $c->getL10N('theming'), |
|
835 | - $c->getURLGenerator(), |
|
836 | - new \OC_Defaults(), |
|
837 | - $c->getAppDataDir('theming'), |
|
838 | - $c->getMemCacheFactory() |
|
839 | - ); |
|
840 | - } |
|
841 | - return new \OC_Defaults(); |
|
842 | - }); |
|
843 | - $this->registerService(EventDispatcher::class, function () { |
|
844 | - return new EventDispatcher(); |
|
845 | - }); |
|
846 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
847 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
848 | - |
|
849 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
850 | - // FIXME: Instantiiated here due to cyclic dependency |
|
851 | - $request = new Request( |
|
852 | - [ |
|
853 | - 'get' => $_GET, |
|
854 | - 'post' => $_POST, |
|
855 | - 'files' => $_FILES, |
|
856 | - 'server' => $_SERVER, |
|
857 | - 'env' => $_ENV, |
|
858 | - 'cookies' => $_COOKIE, |
|
859 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
860 | - ? $_SERVER['REQUEST_METHOD'] |
|
861 | - : null, |
|
862 | - ], |
|
863 | - $c->getSecureRandom(), |
|
864 | - $c->getConfig() |
|
865 | - ); |
|
866 | - |
|
867 | - return new CryptoWrapper( |
|
868 | - $c->getConfig(), |
|
869 | - $c->getCrypto(), |
|
870 | - $c->getSecureRandom(), |
|
871 | - $request |
|
872 | - ); |
|
873 | - }); |
|
874 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
875 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
876 | - |
|
877 | - return new CsrfTokenManager( |
|
878 | - $tokenGenerator, |
|
879 | - $c->query(SessionStorage::class) |
|
880 | - ); |
|
881 | - }); |
|
882 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
883 | - return new SessionStorage($c->getSession()); |
|
884 | - }); |
|
885 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
886 | - return new ContentSecurityPolicyManager(); |
|
887 | - }); |
|
888 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
889 | - |
|
890 | - $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
891 | - return new ContentSecurityPolicyNonceManager( |
|
892 | - $c->getCsrfTokenManager(), |
|
893 | - $c->getRequest() |
|
894 | - ); |
|
895 | - }); |
|
896 | - |
|
897 | - $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
898 | - $config = $c->getConfig(); |
|
899 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
900 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
901 | - $factory = new $factoryClass($this); |
|
902 | - |
|
903 | - $manager = new \OC\Share20\Manager( |
|
904 | - $c->getLogger(), |
|
905 | - $c->getConfig(), |
|
906 | - $c->getSecureRandom(), |
|
907 | - $c->getHasher(), |
|
908 | - $c->getMountManager(), |
|
909 | - $c->getGroupManager(), |
|
910 | - $c->getL10N('core'), |
|
911 | - $factory, |
|
912 | - $c->getUserManager(), |
|
913 | - $c->getLazyRootFolder(), |
|
914 | - $c->getEventDispatcher() |
|
915 | - ); |
|
916 | - |
|
917 | - return $manager; |
|
918 | - }); |
|
919 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
920 | - |
|
921 | - $this->registerService('SettingsManager', function(Server $c) { |
|
922 | - $manager = new \OC\Settings\Manager( |
|
923 | - $c->getLogger(), |
|
924 | - $c->getDatabaseConnection(), |
|
925 | - $c->getL10N('lib'), |
|
926 | - $c->getConfig(), |
|
927 | - $c->getEncryptionManager(), |
|
928 | - $c->getUserManager(), |
|
929 | - $c->getLockingProvider(), |
|
930 | - $c->getRequest(), |
|
931 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
932 | - $c->getURLGenerator() |
|
933 | - ); |
|
934 | - return $manager; |
|
935 | - }); |
|
936 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
937 | - return new \OC\Files\AppData\Factory( |
|
938 | - $c->getRootFolder(), |
|
939 | - $c->getSystemConfig() |
|
940 | - ); |
|
941 | - }); |
|
942 | - |
|
943 | - $this->registerService('LockdownManager', function (Server $c) { |
|
944 | - return new LockdownManager(function() use ($c) { |
|
945 | - return $c->getSession(); |
|
946 | - }); |
|
947 | - }); |
|
948 | - |
|
949 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
950 | - return new CloudIdManager(); |
|
951 | - }); |
|
952 | - |
|
953 | - /* To trick DI since we don't extend the DIContainer here */ |
|
954 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
955 | - return new CleanPreviewsBackgroundJob( |
|
956 | - $c->getRootFolder(), |
|
957 | - $c->getLogger(), |
|
958 | - $c->getJobList(), |
|
959 | - new TimeFactory() |
|
960 | - ); |
|
961 | - }); |
|
962 | - |
|
963 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
964 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
965 | - |
|
966 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
967 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
968 | - |
|
969 | - $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
970 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
971 | - }); |
|
972 | - } |
|
973 | - |
|
974 | - /** |
|
975 | - * @return \OCP\Contacts\IManager |
|
976 | - */ |
|
977 | - public function getContactsManager() { |
|
978 | - return $this->query('ContactsManager'); |
|
979 | - } |
|
980 | - |
|
981 | - /** |
|
982 | - * @return \OC\Encryption\Manager |
|
983 | - */ |
|
984 | - public function getEncryptionManager() { |
|
985 | - return $this->query('EncryptionManager'); |
|
986 | - } |
|
987 | - |
|
988 | - /** |
|
989 | - * @return \OC\Encryption\File |
|
990 | - */ |
|
991 | - public function getEncryptionFilesHelper() { |
|
992 | - return $this->query('EncryptionFileHelper'); |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * @return \OCP\Encryption\Keys\IStorage |
|
997 | - */ |
|
998 | - public function getEncryptionKeyStorage() { |
|
999 | - return $this->query('EncryptionKeyStorage'); |
|
1000 | - } |
|
1001 | - |
|
1002 | - /** |
|
1003 | - * The current request object holding all information about the request |
|
1004 | - * currently being processed is returned from this method. |
|
1005 | - * In case the current execution was not initiated by a web request null is returned |
|
1006 | - * |
|
1007 | - * @return \OCP\IRequest |
|
1008 | - */ |
|
1009 | - public function getRequest() { |
|
1010 | - return $this->query('Request'); |
|
1011 | - } |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * Returns the preview manager which can create preview images for a given file |
|
1015 | - * |
|
1016 | - * @return \OCP\IPreview |
|
1017 | - */ |
|
1018 | - public function getPreviewManager() { |
|
1019 | - return $this->query('PreviewManager'); |
|
1020 | - } |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * Returns the tag manager which can get and set tags for different object types |
|
1024 | - * |
|
1025 | - * @see \OCP\ITagManager::load() |
|
1026 | - * @return \OCP\ITagManager |
|
1027 | - */ |
|
1028 | - public function getTagManager() { |
|
1029 | - return $this->query('TagManager'); |
|
1030 | - } |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * Returns the system-tag manager |
|
1034 | - * |
|
1035 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1036 | - * |
|
1037 | - * @since 9.0.0 |
|
1038 | - */ |
|
1039 | - public function getSystemTagManager() { |
|
1040 | - return $this->query('SystemTagManager'); |
|
1041 | - } |
|
1042 | - |
|
1043 | - /** |
|
1044 | - * Returns the system-tag object mapper |
|
1045 | - * |
|
1046 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1047 | - * |
|
1048 | - * @since 9.0.0 |
|
1049 | - */ |
|
1050 | - public function getSystemTagObjectMapper() { |
|
1051 | - return $this->query('SystemTagObjectMapper'); |
|
1052 | - } |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * Returns the avatar manager, used for avatar functionality |
|
1056 | - * |
|
1057 | - * @return \OCP\IAvatarManager |
|
1058 | - */ |
|
1059 | - public function getAvatarManager() { |
|
1060 | - return $this->query('AvatarManager'); |
|
1061 | - } |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * Returns the root folder of ownCloud's data directory |
|
1065 | - * |
|
1066 | - * @return \OCP\Files\IRootFolder |
|
1067 | - */ |
|
1068 | - public function getRootFolder() { |
|
1069 | - return $this->query('LazyRootFolder'); |
|
1070 | - } |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * Returns the root folder of ownCloud's data directory |
|
1074 | - * This is the lazy variant so this gets only initialized once it |
|
1075 | - * is actually used. |
|
1076 | - * |
|
1077 | - * @return \OCP\Files\IRootFolder |
|
1078 | - */ |
|
1079 | - public function getLazyRootFolder() { |
|
1080 | - return $this->query('LazyRootFolder'); |
|
1081 | - } |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * Returns a view to ownCloud's files folder |
|
1085 | - * |
|
1086 | - * @param string $userId user ID |
|
1087 | - * @return \OCP\Files\Folder|null |
|
1088 | - */ |
|
1089 | - public function getUserFolder($userId = null) { |
|
1090 | - if ($userId === null) { |
|
1091 | - $user = $this->getUserSession()->getUser(); |
|
1092 | - if (!$user) { |
|
1093 | - return null; |
|
1094 | - } |
|
1095 | - $userId = $user->getUID(); |
|
1096 | - } |
|
1097 | - $root = $this->getRootFolder(); |
|
1098 | - return $root->getUserFolder($userId); |
|
1099 | - } |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Returns an app-specific view in ownClouds data directory |
|
1103 | - * |
|
1104 | - * @return \OCP\Files\Folder |
|
1105 | - * @deprecated since 9.2.0 use IAppData |
|
1106 | - */ |
|
1107 | - public function getAppFolder() { |
|
1108 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1109 | - $root = $this->getRootFolder(); |
|
1110 | - if (!$root->nodeExists($dir)) { |
|
1111 | - $folder = $root->newFolder($dir); |
|
1112 | - } else { |
|
1113 | - $folder = $root->get($dir); |
|
1114 | - } |
|
1115 | - return $folder; |
|
1116 | - } |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * @return \OC\User\Manager |
|
1120 | - */ |
|
1121 | - public function getUserManager() { |
|
1122 | - return $this->query('UserManager'); |
|
1123 | - } |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * @return \OC\Group\Manager |
|
1127 | - */ |
|
1128 | - public function getGroupManager() { |
|
1129 | - return $this->query('GroupManager'); |
|
1130 | - } |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * @return \OC\User\Session |
|
1134 | - */ |
|
1135 | - public function getUserSession() { |
|
1136 | - return $this->query('UserSession'); |
|
1137 | - } |
|
1138 | - |
|
1139 | - /** |
|
1140 | - * @return \OCP\ISession |
|
1141 | - */ |
|
1142 | - public function getSession() { |
|
1143 | - return $this->query('UserSession')->getSession(); |
|
1144 | - } |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * @param \OCP\ISession $session |
|
1148 | - */ |
|
1149 | - public function setSession(\OCP\ISession $session) { |
|
1150 | - $this->query(SessionStorage::class)->setSession($session); |
|
1151 | - $this->query('UserSession')->setSession($session); |
|
1152 | - $this->query(Store::class)->setSession($session); |
|
1153 | - } |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1157 | - */ |
|
1158 | - public function getTwoFactorAuthManager() { |
|
1159 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1160 | - } |
|
1161 | - |
|
1162 | - /** |
|
1163 | - * @return \OC\NavigationManager |
|
1164 | - */ |
|
1165 | - public function getNavigationManager() { |
|
1166 | - return $this->query('NavigationManager'); |
|
1167 | - } |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * @return \OCP\IConfig |
|
1171 | - */ |
|
1172 | - public function getConfig() { |
|
1173 | - return $this->query('AllConfig'); |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * @internal For internal use only |
|
1178 | - * @return \OC\SystemConfig |
|
1179 | - */ |
|
1180 | - public function getSystemConfig() { |
|
1181 | - return $this->query('SystemConfig'); |
|
1182 | - } |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Returns the app config manager |
|
1186 | - * |
|
1187 | - * @return \OCP\IAppConfig |
|
1188 | - */ |
|
1189 | - public function getAppConfig() { |
|
1190 | - return $this->query('AppConfig'); |
|
1191 | - } |
|
1192 | - |
|
1193 | - /** |
|
1194 | - * @return \OCP\L10N\IFactory |
|
1195 | - */ |
|
1196 | - public function getL10NFactory() { |
|
1197 | - return $this->query('L10NFactory'); |
|
1198 | - } |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * get an L10N instance |
|
1202 | - * |
|
1203 | - * @param string $app appid |
|
1204 | - * @param string $lang |
|
1205 | - * @return IL10N |
|
1206 | - */ |
|
1207 | - public function getL10N($app, $lang = null) { |
|
1208 | - return $this->getL10NFactory()->get($app, $lang); |
|
1209 | - } |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * @return \OCP\IURLGenerator |
|
1213 | - */ |
|
1214 | - public function getURLGenerator() { |
|
1215 | - return $this->query('URLGenerator'); |
|
1216 | - } |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * @return \OCP\IHelper |
|
1220 | - */ |
|
1221 | - public function getHelper() { |
|
1222 | - return $this->query('AppHelper'); |
|
1223 | - } |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * @return AppFetcher |
|
1227 | - */ |
|
1228 | - public function getAppFetcher() { |
|
1229 | - return $this->query('AppFetcher'); |
|
1230 | - } |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1234 | - * getMemCacheFactory() instead. |
|
1235 | - * |
|
1236 | - * @return \OCP\ICache |
|
1237 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1238 | - */ |
|
1239 | - public function getCache() { |
|
1240 | - return $this->query('UserCache'); |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * Returns an \OCP\CacheFactory instance |
|
1245 | - * |
|
1246 | - * @return \OCP\ICacheFactory |
|
1247 | - */ |
|
1248 | - public function getMemCacheFactory() { |
|
1249 | - return $this->query('MemCacheFactory'); |
|
1250 | - } |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * Returns an \OC\RedisFactory instance |
|
1254 | - * |
|
1255 | - * @return \OC\RedisFactory |
|
1256 | - */ |
|
1257 | - public function getGetRedisFactory() { |
|
1258 | - return $this->query('RedisFactory'); |
|
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Returns the current session |
|
1264 | - * |
|
1265 | - * @return \OCP\IDBConnection |
|
1266 | - */ |
|
1267 | - public function getDatabaseConnection() { |
|
1268 | - return $this->query('DatabaseConnection'); |
|
1269 | - } |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * Returns the activity manager |
|
1273 | - * |
|
1274 | - * @return \OCP\Activity\IManager |
|
1275 | - */ |
|
1276 | - public function getActivityManager() { |
|
1277 | - return $this->query('ActivityManager'); |
|
1278 | - } |
|
1279 | - |
|
1280 | - /** |
|
1281 | - * Returns an job list for controlling background jobs |
|
1282 | - * |
|
1283 | - * @return \OCP\BackgroundJob\IJobList |
|
1284 | - */ |
|
1285 | - public function getJobList() { |
|
1286 | - return $this->query('JobList'); |
|
1287 | - } |
|
1288 | - |
|
1289 | - /** |
|
1290 | - * Returns a logger instance |
|
1291 | - * |
|
1292 | - * @return \OCP\ILogger |
|
1293 | - */ |
|
1294 | - public function getLogger() { |
|
1295 | - return $this->query('Logger'); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Returns a router for generating and matching urls |
|
1300 | - * |
|
1301 | - * @return \OCP\Route\IRouter |
|
1302 | - */ |
|
1303 | - public function getRouter() { |
|
1304 | - return $this->query('Router'); |
|
1305 | - } |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * Returns a search instance |
|
1309 | - * |
|
1310 | - * @return \OCP\ISearch |
|
1311 | - */ |
|
1312 | - public function getSearch() { |
|
1313 | - return $this->query('Search'); |
|
1314 | - } |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * Returns a SecureRandom instance |
|
1318 | - * |
|
1319 | - * @return \OCP\Security\ISecureRandom |
|
1320 | - */ |
|
1321 | - public function getSecureRandom() { |
|
1322 | - return $this->query('SecureRandom'); |
|
1323 | - } |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * Returns a Crypto instance |
|
1327 | - * |
|
1328 | - * @return \OCP\Security\ICrypto |
|
1329 | - */ |
|
1330 | - public function getCrypto() { |
|
1331 | - return $this->query('Crypto'); |
|
1332 | - } |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * Returns a Hasher instance |
|
1336 | - * |
|
1337 | - * @return \OCP\Security\IHasher |
|
1338 | - */ |
|
1339 | - public function getHasher() { |
|
1340 | - return $this->query('Hasher'); |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Returns a CredentialsManager instance |
|
1345 | - * |
|
1346 | - * @return \OCP\Security\ICredentialsManager |
|
1347 | - */ |
|
1348 | - public function getCredentialsManager() { |
|
1349 | - return $this->query('CredentialsManager'); |
|
1350 | - } |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * Returns an instance of the HTTP helper class |
|
1354 | - * |
|
1355 | - * @deprecated Use getHTTPClientService() |
|
1356 | - * @return \OC\HTTPHelper |
|
1357 | - */ |
|
1358 | - public function getHTTPHelper() { |
|
1359 | - return $this->query('HTTPHelper'); |
|
1360 | - } |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Get the certificate manager for the user |
|
1364 | - * |
|
1365 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1366 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1367 | - */ |
|
1368 | - public function getCertificateManager($userId = '') { |
|
1369 | - if ($userId === '') { |
|
1370 | - $userSession = $this->getUserSession(); |
|
1371 | - $user = $userSession->getUser(); |
|
1372 | - if (is_null($user)) { |
|
1373 | - return null; |
|
1374 | - } |
|
1375 | - $userId = $user->getUID(); |
|
1376 | - } |
|
1377 | - return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1378 | - } |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * Returns an instance of the HTTP client service |
|
1382 | - * |
|
1383 | - * @return \OCP\Http\Client\IClientService |
|
1384 | - */ |
|
1385 | - public function getHTTPClientService() { |
|
1386 | - return $this->query('HttpClientService'); |
|
1387 | - } |
|
1388 | - |
|
1389 | - /** |
|
1390 | - * Create a new event source |
|
1391 | - * |
|
1392 | - * @return \OCP\IEventSource |
|
1393 | - */ |
|
1394 | - public function createEventSource() { |
|
1395 | - return new \OC_EventSource(); |
|
1396 | - } |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * Get the active event logger |
|
1400 | - * |
|
1401 | - * The returned logger only logs data when debug mode is enabled |
|
1402 | - * |
|
1403 | - * @return \OCP\Diagnostics\IEventLogger |
|
1404 | - */ |
|
1405 | - public function getEventLogger() { |
|
1406 | - return $this->query('EventLogger'); |
|
1407 | - } |
|
1408 | - |
|
1409 | - /** |
|
1410 | - * Get the active query logger |
|
1411 | - * |
|
1412 | - * The returned logger only logs data when debug mode is enabled |
|
1413 | - * |
|
1414 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1415 | - */ |
|
1416 | - public function getQueryLogger() { |
|
1417 | - return $this->query('QueryLogger'); |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * Get the manager for temporary files and folders |
|
1422 | - * |
|
1423 | - * @return \OCP\ITempManager |
|
1424 | - */ |
|
1425 | - public function getTempManager() { |
|
1426 | - return $this->query('TempManager'); |
|
1427 | - } |
|
1428 | - |
|
1429 | - /** |
|
1430 | - * Get the app manager |
|
1431 | - * |
|
1432 | - * @return \OCP\App\IAppManager |
|
1433 | - */ |
|
1434 | - public function getAppManager() { |
|
1435 | - return $this->query('AppManager'); |
|
1436 | - } |
|
1437 | - |
|
1438 | - /** |
|
1439 | - * Creates a new mailer |
|
1440 | - * |
|
1441 | - * @return \OCP\Mail\IMailer |
|
1442 | - */ |
|
1443 | - public function getMailer() { |
|
1444 | - return $this->query('Mailer'); |
|
1445 | - } |
|
1446 | - |
|
1447 | - /** |
|
1448 | - * Get the webroot |
|
1449 | - * |
|
1450 | - * @return string |
|
1451 | - */ |
|
1452 | - public function getWebRoot() { |
|
1453 | - return $this->webRoot; |
|
1454 | - } |
|
1455 | - |
|
1456 | - /** |
|
1457 | - * @return \OC\OCSClient |
|
1458 | - */ |
|
1459 | - public function getOcsClient() { |
|
1460 | - return $this->query('OcsClient'); |
|
1461 | - } |
|
1462 | - |
|
1463 | - /** |
|
1464 | - * @return \OCP\IDateTimeZone |
|
1465 | - */ |
|
1466 | - public function getDateTimeZone() { |
|
1467 | - return $this->query('DateTimeZone'); |
|
1468 | - } |
|
1469 | - |
|
1470 | - /** |
|
1471 | - * @return \OCP\IDateTimeFormatter |
|
1472 | - */ |
|
1473 | - public function getDateTimeFormatter() { |
|
1474 | - return $this->query('DateTimeFormatter'); |
|
1475 | - } |
|
1476 | - |
|
1477 | - /** |
|
1478 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1479 | - */ |
|
1480 | - public function getMountProviderCollection() { |
|
1481 | - return $this->query('MountConfigManager'); |
|
1482 | - } |
|
1483 | - |
|
1484 | - /** |
|
1485 | - * Get the IniWrapper |
|
1486 | - * |
|
1487 | - * @return IniGetWrapper |
|
1488 | - */ |
|
1489 | - public function getIniWrapper() { |
|
1490 | - return $this->query('IniWrapper'); |
|
1491 | - } |
|
1492 | - |
|
1493 | - /** |
|
1494 | - * @return \OCP\Command\IBus |
|
1495 | - */ |
|
1496 | - public function getCommandBus() { |
|
1497 | - return $this->query('AsyncCommandBus'); |
|
1498 | - } |
|
1499 | - |
|
1500 | - /** |
|
1501 | - * Get the trusted domain helper |
|
1502 | - * |
|
1503 | - * @return TrustedDomainHelper |
|
1504 | - */ |
|
1505 | - public function getTrustedDomainHelper() { |
|
1506 | - return $this->query('TrustedDomainHelper'); |
|
1507 | - } |
|
1508 | - |
|
1509 | - /** |
|
1510 | - * Get the locking provider |
|
1511 | - * |
|
1512 | - * @return \OCP\Lock\ILockingProvider |
|
1513 | - * @since 8.1.0 |
|
1514 | - */ |
|
1515 | - public function getLockingProvider() { |
|
1516 | - return $this->query('LockingProvider'); |
|
1517 | - } |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * @return \OCP\Files\Mount\IMountManager |
|
1521 | - **/ |
|
1522 | - function getMountManager() { |
|
1523 | - return $this->query('MountManager'); |
|
1524 | - } |
|
1525 | - |
|
1526 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1527 | - function getUserMountCache() { |
|
1528 | - return $this->query('UserMountCache'); |
|
1529 | - } |
|
1530 | - |
|
1531 | - /** |
|
1532 | - * Get the MimeTypeDetector |
|
1533 | - * |
|
1534 | - * @return \OCP\Files\IMimeTypeDetector |
|
1535 | - */ |
|
1536 | - public function getMimeTypeDetector() { |
|
1537 | - return $this->query('MimeTypeDetector'); |
|
1538 | - } |
|
1539 | - |
|
1540 | - /** |
|
1541 | - * Get the MimeTypeLoader |
|
1542 | - * |
|
1543 | - * @return \OCP\Files\IMimeTypeLoader |
|
1544 | - */ |
|
1545 | - public function getMimeTypeLoader() { |
|
1546 | - return $this->query('MimeTypeLoader'); |
|
1547 | - } |
|
1548 | - |
|
1549 | - /** |
|
1550 | - * Get the manager of all the capabilities |
|
1551 | - * |
|
1552 | - * @return \OC\CapabilitiesManager |
|
1553 | - */ |
|
1554 | - public function getCapabilitiesManager() { |
|
1555 | - return $this->query('CapabilitiesManager'); |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * Get the EventDispatcher |
|
1560 | - * |
|
1561 | - * @return EventDispatcherInterface |
|
1562 | - * @since 8.2.0 |
|
1563 | - */ |
|
1564 | - public function getEventDispatcher() { |
|
1565 | - return $this->query('EventDispatcher'); |
|
1566 | - } |
|
1567 | - |
|
1568 | - /** |
|
1569 | - * Get the Notification Manager |
|
1570 | - * |
|
1571 | - * @return \OCP\Notification\IManager |
|
1572 | - * @since 8.2.0 |
|
1573 | - */ |
|
1574 | - public function getNotificationManager() { |
|
1575 | - return $this->query('NotificationManager'); |
|
1576 | - } |
|
1577 | - |
|
1578 | - /** |
|
1579 | - * @return \OCP\Comments\ICommentsManager |
|
1580 | - */ |
|
1581 | - public function getCommentsManager() { |
|
1582 | - return $this->query('CommentsManager'); |
|
1583 | - } |
|
1584 | - |
|
1585 | - /** |
|
1586 | - * @return \OCA\Theming\ThemingDefaults |
|
1587 | - */ |
|
1588 | - public function getThemingDefaults() { |
|
1589 | - return $this->query('ThemingDefaults'); |
|
1590 | - } |
|
1591 | - |
|
1592 | - /** |
|
1593 | - * @return \OC\IntegrityCheck\Checker |
|
1594 | - */ |
|
1595 | - public function getIntegrityCodeChecker() { |
|
1596 | - return $this->query('IntegrityCodeChecker'); |
|
1597 | - } |
|
1598 | - |
|
1599 | - /** |
|
1600 | - * @return \OC\Session\CryptoWrapper |
|
1601 | - */ |
|
1602 | - public function getSessionCryptoWrapper() { |
|
1603 | - return $this->query('CryptoWrapper'); |
|
1604 | - } |
|
1605 | - |
|
1606 | - /** |
|
1607 | - * @return CsrfTokenManager |
|
1608 | - */ |
|
1609 | - public function getCsrfTokenManager() { |
|
1610 | - return $this->query('CsrfTokenManager'); |
|
1611 | - } |
|
1612 | - |
|
1613 | - /** |
|
1614 | - * @return Throttler |
|
1615 | - */ |
|
1616 | - public function getBruteForceThrottler() { |
|
1617 | - return $this->query('Throttler'); |
|
1618 | - } |
|
1619 | - |
|
1620 | - /** |
|
1621 | - * @return IContentSecurityPolicyManager |
|
1622 | - */ |
|
1623 | - public function getContentSecurityPolicyManager() { |
|
1624 | - return $this->query('ContentSecurityPolicyManager'); |
|
1625 | - } |
|
1626 | - |
|
1627 | - /** |
|
1628 | - * @return ContentSecurityPolicyNonceManager |
|
1629 | - */ |
|
1630 | - public function getContentSecurityPolicyNonceManager() { |
|
1631 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1632 | - } |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Not a public API as of 8.2, wait for 9.0 |
|
1636 | - * |
|
1637 | - * @return \OCA\Files_External\Service\BackendService |
|
1638 | - */ |
|
1639 | - public function getStoragesBackendService() { |
|
1640 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1641 | - } |
|
1642 | - |
|
1643 | - /** |
|
1644 | - * Not a public API as of 8.2, wait for 9.0 |
|
1645 | - * |
|
1646 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1647 | - */ |
|
1648 | - public function getGlobalStoragesService() { |
|
1649 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1650 | - } |
|
1651 | - |
|
1652 | - /** |
|
1653 | - * Not a public API as of 8.2, wait for 9.0 |
|
1654 | - * |
|
1655 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1656 | - */ |
|
1657 | - public function getUserGlobalStoragesService() { |
|
1658 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1659 | - } |
|
1660 | - |
|
1661 | - /** |
|
1662 | - * Not a public API as of 8.2, wait for 9.0 |
|
1663 | - * |
|
1664 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1665 | - */ |
|
1666 | - public function getUserStoragesService() { |
|
1667 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1668 | - } |
|
1669 | - |
|
1670 | - /** |
|
1671 | - * @return \OCP\Share\IManager |
|
1672 | - */ |
|
1673 | - public function getShareManager() { |
|
1674 | - return $this->query('ShareManager'); |
|
1675 | - } |
|
1676 | - |
|
1677 | - /** |
|
1678 | - * Returns the LDAP Provider |
|
1679 | - * |
|
1680 | - * @return \OCP\LDAP\ILDAPProvider |
|
1681 | - */ |
|
1682 | - public function getLDAPProvider() { |
|
1683 | - return $this->query('LDAPProvider'); |
|
1684 | - } |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * @return \OCP\Settings\IManager |
|
1688 | - */ |
|
1689 | - public function getSettingsManager() { |
|
1690 | - return $this->query('SettingsManager'); |
|
1691 | - } |
|
1692 | - |
|
1693 | - /** |
|
1694 | - * @return \OCP\Files\IAppData |
|
1695 | - */ |
|
1696 | - public function getAppDataDir($app) { |
|
1697 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1698 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1699 | - return $factory->get($app); |
|
1700 | - } |
|
1701 | - |
|
1702 | - /** |
|
1703 | - * @return \OCP\Lockdown\ILockdownManager |
|
1704 | - */ |
|
1705 | - public function getLockdownManager() { |
|
1706 | - return $this->query('LockdownManager'); |
|
1707 | - } |
|
1708 | - |
|
1709 | - /** |
|
1710 | - * @return \OCP\Federation\ICloudIdManager |
|
1711 | - */ |
|
1712 | - public function getCloudIdManager() { |
|
1713 | - return $this->query(ICloudIdManager::class); |
|
1714 | - } |
|
824 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
825 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
826 | + $classExists = true; |
|
827 | + } else { |
|
828 | + $classExists = false; |
|
829 | + } |
|
830 | + |
|
831 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
832 | + return new ThemingDefaults( |
|
833 | + $c->getConfig(), |
|
834 | + $c->getL10N('theming'), |
|
835 | + $c->getURLGenerator(), |
|
836 | + new \OC_Defaults(), |
|
837 | + $c->getAppDataDir('theming'), |
|
838 | + $c->getMemCacheFactory() |
|
839 | + ); |
|
840 | + } |
|
841 | + return new \OC_Defaults(); |
|
842 | + }); |
|
843 | + $this->registerService(EventDispatcher::class, function () { |
|
844 | + return new EventDispatcher(); |
|
845 | + }); |
|
846 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
847 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
848 | + |
|
849 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
850 | + // FIXME: Instantiiated here due to cyclic dependency |
|
851 | + $request = new Request( |
|
852 | + [ |
|
853 | + 'get' => $_GET, |
|
854 | + 'post' => $_POST, |
|
855 | + 'files' => $_FILES, |
|
856 | + 'server' => $_SERVER, |
|
857 | + 'env' => $_ENV, |
|
858 | + 'cookies' => $_COOKIE, |
|
859 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
860 | + ? $_SERVER['REQUEST_METHOD'] |
|
861 | + : null, |
|
862 | + ], |
|
863 | + $c->getSecureRandom(), |
|
864 | + $c->getConfig() |
|
865 | + ); |
|
866 | + |
|
867 | + return new CryptoWrapper( |
|
868 | + $c->getConfig(), |
|
869 | + $c->getCrypto(), |
|
870 | + $c->getSecureRandom(), |
|
871 | + $request |
|
872 | + ); |
|
873 | + }); |
|
874 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
875 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
876 | + |
|
877 | + return new CsrfTokenManager( |
|
878 | + $tokenGenerator, |
|
879 | + $c->query(SessionStorage::class) |
|
880 | + ); |
|
881 | + }); |
|
882 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
883 | + return new SessionStorage($c->getSession()); |
|
884 | + }); |
|
885 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
886 | + return new ContentSecurityPolicyManager(); |
|
887 | + }); |
|
888 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
889 | + |
|
890 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
891 | + return new ContentSecurityPolicyNonceManager( |
|
892 | + $c->getCsrfTokenManager(), |
|
893 | + $c->getRequest() |
|
894 | + ); |
|
895 | + }); |
|
896 | + |
|
897 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
898 | + $config = $c->getConfig(); |
|
899 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
900 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
901 | + $factory = new $factoryClass($this); |
|
902 | + |
|
903 | + $manager = new \OC\Share20\Manager( |
|
904 | + $c->getLogger(), |
|
905 | + $c->getConfig(), |
|
906 | + $c->getSecureRandom(), |
|
907 | + $c->getHasher(), |
|
908 | + $c->getMountManager(), |
|
909 | + $c->getGroupManager(), |
|
910 | + $c->getL10N('core'), |
|
911 | + $factory, |
|
912 | + $c->getUserManager(), |
|
913 | + $c->getLazyRootFolder(), |
|
914 | + $c->getEventDispatcher() |
|
915 | + ); |
|
916 | + |
|
917 | + return $manager; |
|
918 | + }); |
|
919 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
920 | + |
|
921 | + $this->registerService('SettingsManager', function(Server $c) { |
|
922 | + $manager = new \OC\Settings\Manager( |
|
923 | + $c->getLogger(), |
|
924 | + $c->getDatabaseConnection(), |
|
925 | + $c->getL10N('lib'), |
|
926 | + $c->getConfig(), |
|
927 | + $c->getEncryptionManager(), |
|
928 | + $c->getUserManager(), |
|
929 | + $c->getLockingProvider(), |
|
930 | + $c->getRequest(), |
|
931 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
932 | + $c->getURLGenerator() |
|
933 | + ); |
|
934 | + return $manager; |
|
935 | + }); |
|
936 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
937 | + return new \OC\Files\AppData\Factory( |
|
938 | + $c->getRootFolder(), |
|
939 | + $c->getSystemConfig() |
|
940 | + ); |
|
941 | + }); |
|
942 | + |
|
943 | + $this->registerService('LockdownManager', function (Server $c) { |
|
944 | + return new LockdownManager(function() use ($c) { |
|
945 | + return $c->getSession(); |
|
946 | + }); |
|
947 | + }); |
|
948 | + |
|
949 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
950 | + return new CloudIdManager(); |
|
951 | + }); |
|
952 | + |
|
953 | + /* To trick DI since we don't extend the DIContainer here */ |
|
954 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
955 | + return new CleanPreviewsBackgroundJob( |
|
956 | + $c->getRootFolder(), |
|
957 | + $c->getLogger(), |
|
958 | + $c->getJobList(), |
|
959 | + new TimeFactory() |
|
960 | + ); |
|
961 | + }); |
|
962 | + |
|
963 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
964 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
965 | + |
|
966 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
967 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
968 | + |
|
969 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
970 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
971 | + }); |
|
972 | + } |
|
973 | + |
|
974 | + /** |
|
975 | + * @return \OCP\Contacts\IManager |
|
976 | + */ |
|
977 | + public function getContactsManager() { |
|
978 | + return $this->query('ContactsManager'); |
|
979 | + } |
|
980 | + |
|
981 | + /** |
|
982 | + * @return \OC\Encryption\Manager |
|
983 | + */ |
|
984 | + public function getEncryptionManager() { |
|
985 | + return $this->query('EncryptionManager'); |
|
986 | + } |
|
987 | + |
|
988 | + /** |
|
989 | + * @return \OC\Encryption\File |
|
990 | + */ |
|
991 | + public function getEncryptionFilesHelper() { |
|
992 | + return $this->query('EncryptionFileHelper'); |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * @return \OCP\Encryption\Keys\IStorage |
|
997 | + */ |
|
998 | + public function getEncryptionKeyStorage() { |
|
999 | + return $this->query('EncryptionKeyStorage'); |
|
1000 | + } |
|
1001 | + |
|
1002 | + /** |
|
1003 | + * The current request object holding all information about the request |
|
1004 | + * currently being processed is returned from this method. |
|
1005 | + * In case the current execution was not initiated by a web request null is returned |
|
1006 | + * |
|
1007 | + * @return \OCP\IRequest |
|
1008 | + */ |
|
1009 | + public function getRequest() { |
|
1010 | + return $this->query('Request'); |
|
1011 | + } |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * Returns the preview manager which can create preview images for a given file |
|
1015 | + * |
|
1016 | + * @return \OCP\IPreview |
|
1017 | + */ |
|
1018 | + public function getPreviewManager() { |
|
1019 | + return $this->query('PreviewManager'); |
|
1020 | + } |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * Returns the tag manager which can get and set tags for different object types |
|
1024 | + * |
|
1025 | + * @see \OCP\ITagManager::load() |
|
1026 | + * @return \OCP\ITagManager |
|
1027 | + */ |
|
1028 | + public function getTagManager() { |
|
1029 | + return $this->query('TagManager'); |
|
1030 | + } |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * Returns the system-tag manager |
|
1034 | + * |
|
1035 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1036 | + * |
|
1037 | + * @since 9.0.0 |
|
1038 | + */ |
|
1039 | + public function getSystemTagManager() { |
|
1040 | + return $this->query('SystemTagManager'); |
|
1041 | + } |
|
1042 | + |
|
1043 | + /** |
|
1044 | + * Returns the system-tag object mapper |
|
1045 | + * |
|
1046 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1047 | + * |
|
1048 | + * @since 9.0.0 |
|
1049 | + */ |
|
1050 | + public function getSystemTagObjectMapper() { |
|
1051 | + return $this->query('SystemTagObjectMapper'); |
|
1052 | + } |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * Returns the avatar manager, used for avatar functionality |
|
1056 | + * |
|
1057 | + * @return \OCP\IAvatarManager |
|
1058 | + */ |
|
1059 | + public function getAvatarManager() { |
|
1060 | + return $this->query('AvatarManager'); |
|
1061 | + } |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * Returns the root folder of ownCloud's data directory |
|
1065 | + * |
|
1066 | + * @return \OCP\Files\IRootFolder |
|
1067 | + */ |
|
1068 | + public function getRootFolder() { |
|
1069 | + return $this->query('LazyRootFolder'); |
|
1070 | + } |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * Returns the root folder of ownCloud's data directory |
|
1074 | + * This is the lazy variant so this gets only initialized once it |
|
1075 | + * is actually used. |
|
1076 | + * |
|
1077 | + * @return \OCP\Files\IRootFolder |
|
1078 | + */ |
|
1079 | + public function getLazyRootFolder() { |
|
1080 | + return $this->query('LazyRootFolder'); |
|
1081 | + } |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * Returns a view to ownCloud's files folder |
|
1085 | + * |
|
1086 | + * @param string $userId user ID |
|
1087 | + * @return \OCP\Files\Folder|null |
|
1088 | + */ |
|
1089 | + public function getUserFolder($userId = null) { |
|
1090 | + if ($userId === null) { |
|
1091 | + $user = $this->getUserSession()->getUser(); |
|
1092 | + if (!$user) { |
|
1093 | + return null; |
|
1094 | + } |
|
1095 | + $userId = $user->getUID(); |
|
1096 | + } |
|
1097 | + $root = $this->getRootFolder(); |
|
1098 | + return $root->getUserFolder($userId); |
|
1099 | + } |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Returns an app-specific view in ownClouds data directory |
|
1103 | + * |
|
1104 | + * @return \OCP\Files\Folder |
|
1105 | + * @deprecated since 9.2.0 use IAppData |
|
1106 | + */ |
|
1107 | + public function getAppFolder() { |
|
1108 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1109 | + $root = $this->getRootFolder(); |
|
1110 | + if (!$root->nodeExists($dir)) { |
|
1111 | + $folder = $root->newFolder($dir); |
|
1112 | + } else { |
|
1113 | + $folder = $root->get($dir); |
|
1114 | + } |
|
1115 | + return $folder; |
|
1116 | + } |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * @return \OC\User\Manager |
|
1120 | + */ |
|
1121 | + public function getUserManager() { |
|
1122 | + return $this->query('UserManager'); |
|
1123 | + } |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * @return \OC\Group\Manager |
|
1127 | + */ |
|
1128 | + public function getGroupManager() { |
|
1129 | + return $this->query('GroupManager'); |
|
1130 | + } |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * @return \OC\User\Session |
|
1134 | + */ |
|
1135 | + public function getUserSession() { |
|
1136 | + return $this->query('UserSession'); |
|
1137 | + } |
|
1138 | + |
|
1139 | + /** |
|
1140 | + * @return \OCP\ISession |
|
1141 | + */ |
|
1142 | + public function getSession() { |
|
1143 | + return $this->query('UserSession')->getSession(); |
|
1144 | + } |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * @param \OCP\ISession $session |
|
1148 | + */ |
|
1149 | + public function setSession(\OCP\ISession $session) { |
|
1150 | + $this->query(SessionStorage::class)->setSession($session); |
|
1151 | + $this->query('UserSession')->setSession($session); |
|
1152 | + $this->query(Store::class)->setSession($session); |
|
1153 | + } |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1157 | + */ |
|
1158 | + public function getTwoFactorAuthManager() { |
|
1159 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1160 | + } |
|
1161 | + |
|
1162 | + /** |
|
1163 | + * @return \OC\NavigationManager |
|
1164 | + */ |
|
1165 | + public function getNavigationManager() { |
|
1166 | + return $this->query('NavigationManager'); |
|
1167 | + } |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * @return \OCP\IConfig |
|
1171 | + */ |
|
1172 | + public function getConfig() { |
|
1173 | + return $this->query('AllConfig'); |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * @internal For internal use only |
|
1178 | + * @return \OC\SystemConfig |
|
1179 | + */ |
|
1180 | + public function getSystemConfig() { |
|
1181 | + return $this->query('SystemConfig'); |
|
1182 | + } |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Returns the app config manager |
|
1186 | + * |
|
1187 | + * @return \OCP\IAppConfig |
|
1188 | + */ |
|
1189 | + public function getAppConfig() { |
|
1190 | + return $this->query('AppConfig'); |
|
1191 | + } |
|
1192 | + |
|
1193 | + /** |
|
1194 | + * @return \OCP\L10N\IFactory |
|
1195 | + */ |
|
1196 | + public function getL10NFactory() { |
|
1197 | + return $this->query('L10NFactory'); |
|
1198 | + } |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * get an L10N instance |
|
1202 | + * |
|
1203 | + * @param string $app appid |
|
1204 | + * @param string $lang |
|
1205 | + * @return IL10N |
|
1206 | + */ |
|
1207 | + public function getL10N($app, $lang = null) { |
|
1208 | + return $this->getL10NFactory()->get($app, $lang); |
|
1209 | + } |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * @return \OCP\IURLGenerator |
|
1213 | + */ |
|
1214 | + public function getURLGenerator() { |
|
1215 | + return $this->query('URLGenerator'); |
|
1216 | + } |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * @return \OCP\IHelper |
|
1220 | + */ |
|
1221 | + public function getHelper() { |
|
1222 | + return $this->query('AppHelper'); |
|
1223 | + } |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * @return AppFetcher |
|
1227 | + */ |
|
1228 | + public function getAppFetcher() { |
|
1229 | + return $this->query('AppFetcher'); |
|
1230 | + } |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1234 | + * getMemCacheFactory() instead. |
|
1235 | + * |
|
1236 | + * @return \OCP\ICache |
|
1237 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1238 | + */ |
|
1239 | + public function getCache() { |
|
1240 | + return $this->query('UserCache'); |
|
1241 | + } |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * Returns an \OCP\CacheFactory instance |
|
1245 | + * |
|
1246 | + * @return \OCP\ICacheFactory |
|
1247 | + */ |
|
1248 | + public function getMemCacheFactory() { |
|
1249 | + return $this->query('MemCacheFactory'); |
|
1250 | + } |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * Returns an \OC\RedisFactory instance |
|
1254 | + * |
|
1255 | + * @return \OC\RedisFactory |
|
1256 | + */ |
|
1257 | + public function getGetRedisFactory() { |
|
1258 | + return $this->query('RedisFactory'); |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Returns the current session |
|
1264 | + * |
|
1265 | + * @return \OCP\IDBConnection |
|
1266 | + */ |
|
1267 | + public function getDatabaseConnection() { |
|
1268 | + return $this->query('DatabaseConnection'); |
|
1269 | + } |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * Returns the activity manager |
|
1273 | + * |
|
1274 | + * @return \OCP\Activity\IManager |
|
1275 | + */ |
|
1276 | + public function getActivityManager() { |
|
1277 | + return $this->query('ActivityManager'); |
|
1278 | + } |
|
1279 | + |
|
1280 | + /** |
|
1281 | + * Returns an job list for controlling background jobs |
|
1282 | + * |
|
1283 | + * @return \OCP\BackgroundJob\IJobList |
|
1284 | + */ |
|
1285 | + public function getJobList() { |
|
1286 | + return $this->query('JobList'); |
|
1287 | + } |
|
1288 | + |
|
1289 | + /** |
|
1290 | + * Returns a logger instance |
|
1291 | + * |
|
1292 | + * @return \OCP\ILogger |
|
1293 | + */ |
|
1294 | + public function getLogger() { |
|
1295 | + return $this->query('Logger'); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Returns a router for generating and matching urls |
|
1300 | + * |
|
1301 | + * @return \OCP\Route\IRouter |
|
1302 | + */ |
|
1303 | + public function getRouter() { |
|
1304 | + return $this->query('Router'); |
|
1305 | + } |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * Returns a search instance |
|
1309 | + * |
|
1310 | + * @return \OCP\ISearch |
|
1311 | + */ |
|
1312 | + public function getSearch() { |
|
1313 | + return $this->query('Search'); |
|
1314 | + } |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * Returns a SecureRandom instance |
|
1318 | + * |
|
1319 | + * @return \OCP\Security\ISecureRandom |
|
1320 | + */ |
|
1321 | + public function getSecureRandom() { |
|
1322 | + return $this->query('SecureRandom'); |
|
1323 | + } |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * Returns a Crypto instance |
|
1327 | + * |
|
1328 | + * @return \OCP\Security\ICrypto |
|
1329 | + */ |
|
1330 | + public function getCrypto() { |
|
1331 | + return $this->query('Crypto'); |
|
1332 | + } |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * Returns a Hasher instance |
|
1336 | + * |
|
1337 | + * @return \OCP\Security\IHasher |
|
1338 | + */ |
|
1339 | + public function getHasher() { |
|
1340 | + return $this->query('Hasher'); |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Returns a CredentialsManager instance |
|
1345 | + * |
|
1346 | + * @return \OCP\Security\ICredentialsManager |
|
1347 | + */ |
|
1348 | + public function getCredentialsManager() { |
|
1349 | + return $this->query('CredentialsManager'); |
|
1350 | + } |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * Returns an instance of the HTTP helper class |
|
1354 | + * |
|
1355 | + * @deprecated Use getHTTPClientService() |
|
1356 | + * @return \OC\HTTPHelper |
|
1357 | + */ |
|
1358 | + public function getHTTPHelper() { |
|
1359 | + return $this->query('HTTPHelper'); |
|
1360 | + } |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Get the certificate manager for the user |
|
1364 | + * |
|
1365 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1366 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1367 | + */ |
|
1368 | + public function getCertificateManager($userId = '') { |
|
1369 | + if ($userId === '') { |
|
1370 | + $userSession = $this->getUserSession(); |
|
1371 | + $user = $userSession->getUser(); |
|
1372 | + if (is_null($user)) { |
|
1373 | + return null; |
|
1374 | + } |
|
1375 | + $userId = $user->getUID(); |
|
1376 | + } |
|
1377 | + return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1378 | + } |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * Returns an instance of the HTTP client service |
|
1382 | + * |
|
1383 | + * @return \OCP\Http\Client\IClientService |
|
1384 | + */ |
|
1385 | + public function getHTTPClientService() { |
|
1386 | + return $this->query('HttpClientService'); |
|
1387 | + } |
|
1388 | + |
|
1389 | + /** |
|
1390 | + * Create a new event source |
|
1391 | + * |
|
1392 | + * @return \OCP\IEventSource |
|
1393 | + */ |
|
1394 | + public function createEventSource() { |
|
1395 | + return new \OC_EventSource(); |
|
1396 | + } |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * Get the active event logger |
|
1400 | + * |
|
1401 | + * The returned logger only logs data when debug mode is enabled |
|
1402 | + * |
|
1403 | + * @return \OCP\Diagnostics\IEventLogger |
|
1404 | + */ |
|
1405 | + public function getEventLogger() { |
|
1406 | + return $this->query('EventLogger'); |
|
1407 | + } |
|
1408 | + |
|
1409 | + /** |
|
1410 | + * Get the active query logger |
|
1411 | + * |
|
1412 | + * The returned logger only logs data when debug mode is enabled |
|
1413 | + * |
|
1414 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1415 | + */ |
|
1416 | + public function getQueryLogger() { |
|
1417 | + return $this->query('QueryLogger'); |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * Get the manager for temporary files and folders |
|
1422 | + * |
|
1423 | + * @return \OCP\ITempManager |
|
1424 | + */ |
|
1425 | + public function getTempManager() { |
|
1426 | + return $this->query('TempManager'); |
|
1427 | + } |
|
1428 | + |
|
1429 | + /** |
|
1430 | + * Get the app manager |
|
1431 | + * |
|
1432 | + * @return \OCP\App\IAppManager |
|
1433 | + */ |
|
1434 | + public function getAppManager() { |
|
1435 | + return $this->query('AppManager'); |
|
1436 | + } |
|
1437 | + |
|
1438 | + /** |
|
1439 | + * Creates a new mailer |
|
1440 | + * |
|
1441 | + * @return \OCP\Mail\IMailer |
|
1442 | + */ |
|
1443 | + public function getMailer() { |
|
1444 | + return $this->query('Mailer'); |
|
1445 | + } |
|
1446 | + |
|
1447 | + /** |
|
1448 | + * Get the webroot |
|
1449 | + * |
|
1450 | + * @return string |
|
1451 | + */ |
|
1452 | + public function getWebRoot() { |
|
1453 | + return $this->webRoot; |
|
1454 | + } |
|
1455 | + |
|
1456 | + /** |
|
1457 | + * @return \OC\OCSClient |
|
1458 | + */ |
|
1459 | + public function getOcsClient() { |
|
1460 | + return $this->query('OcsClient'); |
|
1461 | + } |
|
1462 | + |
|
1463 | + /** |
|
1464 | + * @return \OCP\IDateTimeZone |
|
1465 | + */ |
|
1466 | + public function getDateTimeZone() { |
|
1467 | + return $this->query('DateTimeZone'); |
|
1468 | + } |
|
1469 | + |
|
1470 | + /** |
|
1471 | + * @return \OCP\IDateTimeFormatter |
|
1472 | + */ |
|
1473 | + public function getDateTimeFormatter() { |
|
1474 | + return $this->query('DateTimeFormatter'); |
|
1475 | + } |
|
1476 | + |
|
1477 | + /** |
|
1478 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1479 | + */ |
|
1480 | + public function getMountProviderCollection() { |
|
1481 | + return $this->query('MountConfigManager'); |
|
1482 | + } |
|
1483 | + |
|
1484 | + /** |
|
1485 | + * Get the IniWrapper |
|
1486 | + * |
|
1487 | + * @return IniGetWrapper |
|
1488 | + */ |
|
1489 | + public function getIniWrapper() { |
|
1490 | + return $this->query('IniWrapper'); |
|
1491 | + } |
|
1492 | + |
|
1493 | + /** |
|
1494 | + * @return \OCP\Command\IBus |
|
1495 | + */ |
|
1496 | + public function getCommandBus() { |
|
1497 | + return $this->query('AsyncCommandBus'); |
|
1498 | + } |
|
1499 | + |
|
1500 | + /** |
|
1501 | + * Get the trusted domain helper |
|
1502 | + * |
|
1503 | + * @return TrustedDomainHelper |
|
1504 | + */ |
|
1505 | + public function getTrustedDomainHelper() { |
|
1506 | + return $this->query('TrustedDomainHelper'); |
|
1507 | + } |
|
1508 | + |
|
1509 | + /** |
|
1510 | + * Get the locking provider |
|
1511 | + * |
|
1512 | + * @return \OCP\Lock\ILockingProvider |
|
1513 | + * @since 8.1.0 |
|
1514 | + */ |
|
1515 | + public function getLockingProvider() { |
|
1516 | + return $this->query('LockingProvider'); |
|
1517 | + } |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * @return \OCP\Files\Mount\IMountManager |
|
1521 | + **/ |
|
1522 | + function getMountManager() { |
|
1523 | + return $this->query('MountManager'); |
|
1524 | + } |
|
1525 | + |
|
1526 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1527 | + function getUserMountCache() { |
|
1528 | + return $this->query('UserMountCache'); |
|
1529 | + } |
|
1530 | + |
|
1531 | + /** |
|
1532 | + * Get the MimeTypeDetector |
|
1533 | + * |
|
1534 | + * @return \OCP\Files\IMimeTypeDetector |
|
1535 | + */ |
|
1536 | + public function getMimeTypeDetector() { |
|
1537 | + return $this->query('MimeTypeDetector'); |
|
1538 | + } |
|
1539 | + |
|
1540 | + /** |
|
1541 | + * Get the MimeTypeLoader |
|
1542 | + * |
|
1543 | + * @return \OCP\Files\IMimeTypeLoader |
|
1544 | + */ |
|
1545 | + public function getMimeTypeLoader() { |
|
1546 | + return $this->query('MimeTypeLoader'); |
|
1547 | + } |
|
1548 | + |
|
1549 | + /** |
|
1550 | + * Get the manager of all the capabilities |
|
1551 | + * |
|
1552 | + * @return \OC\CapabilitiesManager |
|
1553 | + */ |
|
1554 | + public function getCapabilitiesManager() { |
|
1555 | + return $this->query('CapabilitiesManager'); |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * Get the EventDispatcher |
|
1560 | + * |
|
1561 | + * @return EventDispatcherInterface |
|
1562 | + * @since 8.2.0 |
|
1563 | + */ |
|
1564 | + public function getEventDispatcher() { |
|
1565 | + return $this->query('EventDispatcher'); |
|
1566 | + } |
|
1567 | + |
|
1568 | + /** |
|
1569 | + * Get the Notification Manager |
|
1570 | + * |
|
1571 | + * @return \OCP\Notification\IManager |
|
1572 | + * @since 8.2.0 |
|
1573 | + */ |
|
1574 | + public function getNotificationManager() { |
|
1575 | + return $this->query('NotificationManager'); |
|
1576 | + } |
|
1577 | + |
|
1578 | + /** |
|
1579 | + * @return \OCP\Comments\ICommentsManager |
|
1580 | + */ |
|
1581 | + public function getCommentsManager() { |
|
1582 | + return $this->query('CommentsManager'); |
|
1583 | + } |
|
1584 | + |
|
1585 | + /** |
|
1586 | + * @return \OCA\Theming\ThemingDefaults |
|
1587 | + */ |
|
1588 | + public function getThemingDefaults() { |
|
1589 | + return $this->query('ThemingDefaults'); |
|
1590 | + } |
|
1591 | + |
|
1592 | + /** |
|
1593 | + * @return \OC\IntegrityCheck\Checker |
|
1594 | + */ |
|
1595 | + public function getIntegrityCodeChecker() { |
|
1596 | + return $this->query('IntegrityCodeChecker'); |
|
1597 | + } |
|
1598 | + |
|
1599 | + /** |
|
1600 | + * @return \OC\Session\CryptoWrapper |
|
1601 | + */ |
|
1602 | + public function getSessionCryptoWrapper() { |
|
1603 | + return $this->query('CryptoWrapper'); |
|
1604 | + } |
|
1605 | + |
|
1606 | + /** |
|
1607 | + * @return CsrfTokenManager |
|
1608 | + */ |
|
1609 | + public function getCsrfTokenManager() { |
|
1610 | + return $this->query('CsrfTokenManager'); |
|
1611 | + } |
|
1612 | + |
|
1613 | + /** |
|
1614 | + * @return Throttler |
|
1615 | + */ |
|
1616 | + public function getBruteForceThrottler() { |
|
1617 | + return $this->query('Throttler'); |
|
1618 | + } |
|
1619 | + |
|
1620 | + /** |
|
1621 | + * @return IContentSecurityPolicyManager |
|
1622 | + */ |
|
1623 | + public function getContentSecurityPolicyManager() { |
|
1624 | + return $this->query('ContentSecurityPolicyManager'); |
|
1625 | + } |
|
1626 | + |
|
1627 | + /** |
|
1628 | + * @return ContentSecurityPolicyNonceManager |
|
1629 | + */ |
|
1630 | + public function getContentSecurityPolicyNonceManager() { |
|
1631 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1632 | + } |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Not a public API as of 8.2, wait for 9.0 |
|
1636 | + * |
|
1637 | + * @return \OCA\Files_External\Service\BackendService |
|
1638 | + */ |
|
1639 | + public function getStoragesBackendService() { |
|
1640 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1641 | + } |
|
1642 | + |
|
1643 | + /** |
|
1644 | + * Not a public API as of 8.2, wait for 9.0 |
|
1645 | + * |
|
1646 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1647 | + */ |
|
1648 | + public function getGlobalStoragesService() { |
|
1649 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1650 | + } |
|
1651 | + |
|
1652 | + /** |
|
1653 | + * Not a public API as of 8.2, wait for 9.0 |
|
1654 | + * |
|
1655 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1656 | + */ |
|
1657 | + public function getUserGlobalStoragesService() { |
|
1658 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1659 | + } |
|
1660 | + |
|
1661 | + /** |
|
1662 | + * Not a public API as of 8.2, wait for 9.0 |
|
1663 | + * |
|
1664 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1665 | + */ |
|
1666 | + public function getUserStoragesService() { |
|
1667 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1668 | + } |
|
1669 | + |
|
1670 | + /** |
|
1671 | + * @return \OCP\Share\IManager |
|
1672 | + */ |
|
1673 | + public function getShareManager() { |
|
1674 | + return $this->query('ShareManager'); |
|
1675 | + } |
|
1676 | + |
|
1677 | + /** |
|
1678 | + * Returns the LDAP Provider |
|
1679 | + * |
|
1680 | + * @return \OCP\LDAP\ILDAPProvider |
|
1681 | + */ |
|
1682 | + public function getLDAPProvider() { |
|
1683 | + return $this->query('LDAPProvider'); |
|
1684 | + } |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * @return \OCP\Settings\IManager |
|
1688 | + */ |
|
1689 | + public function getSettingsManager() { |
|
1690 | + return $this->query('SettingsManager'); |
|
1691 | + } |
|
1692 | + |
|
1693 | + /** |
|
1694 | + * @return \OCP\Files\IAppData |
|
1695 | + */ |
|
1696 | + public function getAppDataDir($app) { |
|
1697 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1698 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1699 | + return $factory->get($app); |
|
1700 | + } |
|
1701 | + |
|
1702 | + /** |
|
1703 | + * @return \OCP\Lockdown\ILockdownManager |
|
1704 | + */ |
|
1705 | + public function getLockdownManager() { |
|
1706 | + return $this->query('LockdownManager'); |
|
1707 | + } |
|
1708 | + |
|
1709 | + /** |
|
1710 | + * @return \OCP\Federation\ICloudIdManager |
|
1711 | + */ |
|
1712 | + public function getCloudIdManager() { |
|
1713 | + return $this->query(ICloudIdManager::class); |
|
1714 | + } |
|
1715 | 1715 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | |
142 | 142 | |
143 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
143 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
144 | 144 | return new PreviewManager( |
145 | 145 | $c->getConfig(), |
146 | 146 | $c->getRootFolder(), |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | }); |
152 | 152 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
153 | 153 | |
154 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
154 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
155 | 155 | return new \OC\Preview\Watcher( |
156 | 156 | $c->getAppDataDir('preview') |
157 | 157 | ); |
158 | 158 | }); |
159 | 159 | |
160 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
160 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
161 | 161 | $view = new View(); |
162 | 162 | $util = new Encryption\Util( |
163 | 163 | $view, |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | ); |
176 | 176 | }); |
177 | 177 | |
178 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
178 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
179 | 179 | $util = new Encryption\Util( |
180 | 180 | new View(), |
181 | 181 | $c->getUserManager(), |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | return new Encryption\File($util); |
186 | 186 | }); |
187 | 187 | |
188 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
188 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
189 | 189 | $view = new View(); |
190 | 190 | $util = new Encryption\Util( |
191 | 191 | $view, |
@@ -196,32 +196,32 @@ discard block |
||
196 | 196 | |
197 | 197 | return new Encryption\Keys\Storage($view, $util); |
198 | 198 | }); |
199 | - $this->registerService('TagMapper', function (Server $c) { |
|
199 | + $this->registerService('TagMapper', function(Server $c) { |
|
200 | 200 | return new TagMapper($c->getDatabaseConnection()); |
201 | 201 | }); |
202 | 202 | |
203 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
203 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
204 | 204 | $tagMapper = $c->query('TagMapper'); |
205 | 205 | return new TagManager($tagMapper, $c->getUserSession()); |
206 | 206 | }); |
207 | 207 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
208 | 208 | |
209 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
209 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
210 | 210 | $config = $c->getConfig(); |
211 | 211 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
212 | 212 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
213 | 213 | $factory = new $factoryClass($this); |
214 | 214 | return $factory; |
215 | 215 | }); |
216 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
216 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
217 | 217 | return $c->query('SystemTagManagerFactory')->getManager(); |
218 | 218 | }); |
219 | 219 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
220 | 220 | |
221 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
221 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
222 | 222 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
223 | 223 | }); |
224 | - $this->registerService('RootFolder', function (Server $c) { |
|
224 | + $this->registerService('RootFolder', function(Server $c) { |
|
225 | 225 | $manager = \OC\Files\Filesystem::getMountManager(null); |
226 | 226 | $view = new View(); |
227 | 227 | $root = new Root( |
@@ -249,30 +249,30 @@ discard block |
||
249 | 249 | }); |
250 | 250 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
251 | 251 | |
252 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
252 | + $this->registerService(\OCP\IUserManager::class, function(Server $c) { |
|
253 | 253 | $config = $c->getConfig(); |
254 | 254 | return new \OC\User\Manager($config); |
255 | 255 | }); |
256 | 256 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
257 | 257 | |
258 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
258 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
259 | 259 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
260 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
260 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
261 | 261 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
262 | 262 | }); |
263 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
263 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
264 | 264 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
265 | 265 | }); |
266 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
266 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
267 | 267 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
268 | 268 | }); |
269 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
269 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
270 | 270 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
271 | 271 | }); |
272 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
272 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
273 | 273 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
274 | 274 | }); |
275 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
275 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
276 | 276 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
277 | 277 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
278 | 278 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | return new Store($session, $logger, $tokenProvider); |
293 | 293 | }); |
294 | 294 | $this->registerAlias(IStore::class, Store::class); |
295 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
295 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
296 | 296 | $dbConnection = $c->getDatabaseConnection(); |
297 | 297 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
298 | 298 | }); |
299 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
299 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
300 | 300 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
301 | 301 | $crypto = $c->getCrypto(); |
302 | 302 | $config = $c->getConfig(); |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | }); |
307 | 307 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
308 | 308 | |
309 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
309 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
310 | 310 | $manager = $c->getUserManager(); |
311 | 311 | $session = new \OC\Session\Memory(''); |
312 | 312 | $timeFactory = new TimeFactory(); |
@@ -319,40 +319,40 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
322 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
322 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
323 | 323 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
324 | 324 | }); |
325 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
325 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
326 | 326 | /** @var $user \OC\User\User */ |
327 | 327 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
328 | 328 | }); |
329 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
329 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
330 | 330 | /** @var $user \OC\User\User */ |
331 | 331 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
332 | 332 | }); |
333 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
333 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
334 | 334 | /** @var $user \OC\User\User */ |
335 | 335 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
336 | 336 | }); |
337 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
337 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
338 | 338 | /** @var $user \OC\User\User */ |
339 | 339 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
340 | 340 | }); |
341 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
341 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
342 | 342 | /** @var $user \OC\User\User */ |
343 | 343 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
344 | 344 | }); |
345 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
345 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
346 | 346 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
347 | 347 | }); |
348 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
348 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
349 | 349 | /** @var $user \OC\User\User */ |
350 | 350 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
351 | 351 | }); |
352 | - $userSession->listen('\OC\User', 'logout', function () { |
|
352 | + $userSession->listen('\OC\User', 'logout', function() { |
|
353 | 353 | \OC_Hook::emit('OC_User', 'logout', array()); |
354 | 354 | }); |
355 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
|
355 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value) { |
|
356 | 356 | /** @var $user \OC\User\User */ |
357 | 357 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
358 | 358 | }); |
@@ -360,14 +360,14 @@ discard block |
||
360 | 360 | }); |
361 | 361 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
362 | 362 | |
363 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
363 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
364 | 364 | return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
365 | 365 | }); |
366 | 366 | |
367 | 367 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
368 | 368 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
369 | 369 | |
370 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
370 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
371 | 371 | return new \OC\AllConfig( |
372 | 372 | $c->getSystemConfig() |
373 | 373 | ); |
@@ -375,17 +375,17 @@ discard block |
||
375 | 375 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
376 | 376 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
377 | 377 | |
378 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
378 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
379 | 379 | return new \OC\SystemConfig($config); |
380 | 380 | }); |
381 | 381 | |
382 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
382 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
383 | 383 | return new \OC\AppConfig($c->getDatabaseConnection()); |
384 | 384 | }); |
385 | 385 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
386 | 386 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
387 | 387 | |
388 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
388 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
389 | 389 | return new \OC\L10N\Factory( |
390 | 390 | $c->getConfig(), |
391 | 391 | $c->getRequest(), |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | }); |
396 | 396 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
397 | 397 | |
398 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
398 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
399 | 399 | $config = $c->getConfig(); |
400 | 400 | $cacheFactory = $c->getMemCacheFactory(); |
401 | 401 | return new \OC\URLGenerator( |
@@ -405,10 +405,10 @@ discard block |
||
405 | 405 | }); |
406 | 406 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
407 | 407 | |
408 | - $this->registerService('AppHelper', function ($c) { |
|
408 | + $this->registerService('AppHelper', function($c) { |
|
409 | 409 | return new \OC\AppHelper(); |
410 | 410 | }); |
411 | - $this->registerService('AppFetcher', function ($c) { |
|
411 | + $this->registerService('AppFetcher', function($c) { |
|
412 | 412 | return new AppFetcher( |
413 | 413 | $this->getAppDataDir('appstore'), |
414 | 414 | $this->getHTTPClientService(), |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $this->getConfig() |
417 | 417 | ); |
418 | 418 | }); |
419 | - $this->registerService('CategoryFetcher', function ($c) { |
|
419 | + $this->registerService('CategoryFetcher', function($c) { |
|
420 | 420 | return new CategoryFetcher( |
421 | 421 | $this->getAppDataDir('appstore'), |
422 | 422 | $this->getHTTPClientService(), |
@@ -425,21 +425,21 @@ discard block |
||
425 | 425 | ); |
426 | 426 | }); |
427 | 427 | |
428 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
428 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
429 | 429 | return new Cache\File(); |
430 | 430 | }); |
431 | 431 | $this->registerAlias('UserCache', \OCP\ICache::class); |
432 | 432 | |
433 | - $this->registerService(Factory::class, function (Server $c) { |
|
433 | + $this->registerService(Factory::class, function(Server $c) { |
|
434 | 434 | $config = $c->getConfig(); |
435 | 435 | |
436 | 436 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
437 | 437 | $v = \OC_App::getAppVersions(); |
438 | - $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
|
438 | + $v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php')); |
|
439 | 439 | $version = implode(',', $v); |
440 | 440 | $instanceId = \OC_Util::getInstanceId(); |
441 | 441 | $path = \OC::$SERVERROOT; |
442 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
|
442 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT); |
|
443 | 443 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
444 | 444 | $config->getSystemValue('memcache.local', null), |
445 | 445 | $config->getSystemValue('memcache.distributed', null), |
@@ -456,12 +456,12 @@ discard block |
||
456 | 456 | $this->registerAlias('MemCacheFactory', Factory::class); |
457 | 457 | $this->registerAlias(ICacheFactory::class, Factory::class); |
458 | 458 | |
459 | - $this->registerService('RedisFactory', function (Server $c) { |
|
459 | + $this->registerService('RedisFactory', function(Server $c) { |
|
460 | 460 | $systemConfig = $c->getSystemConfig(); |
461 | 461 | return new RedisFactory($systemConfig); |
462 | 462 | }); |
463 | 463 | |
464 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
464 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
465 | 465 | return new \OC\Activity\Manager( |
466 | 466 | $c->getRequest(), |
467 | 467 | $c->getUserSession(), |
@@ -471,14 +471,14 @@ discard block |
||
471 | 471 | }); |
472 | 472 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
473 | 473 | |
474 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
474 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
475 | 475 | return new \OC\Activity\EventMerger( |
476 | 476 | $c->getL10N('lib') |
477 | 477 | ); |
478 | 478 | }); |
479 | 479 | $this->registerAlias(IValidator::class, Validator::class); |
480 | 480 | |
481 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
481 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
482 | 482 | return new AvatarManager( |
483 | 483 | $c->getUserManager(), |
484 | 484 | $c->getAppDataDir('avatar'), |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | }); |
490 | 490 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
491 | 491 | |
492 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
492 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
493 | 493 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
494 | 494 | $logger = Log::getLogClass($logType); |
495 | 495 | call_user_func(array($logger, 'init')); |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | }); |
499 | 499 | $this->registerAlias('Logger', \OCP\ILogger::class); |
500 | 500 | |
501 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
501 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
502 | 502 | $config = $c->getConfig(); |
503 | 503 | return new \OC\BackgroundJob\JobList( |
504 | 504 | $c->getDatabaseConnection(), |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | }); |
509 | 509 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
510 | 510 | |
511 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
511 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
512 | 512 | $cacheFactory = $c->getMemCacheFactory(); |
513 | 513 | $logger = $c->getLogger(); |
514 | 514 | if ($cacheFactory->isAvailable()) { |
@@ -520,32 +520,32 @@ discard block |
||
520 | 520 | }); |
521 | 521 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
522 | 522 | |
523 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
523 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
524 | 524 | return new Search(); |
525 | 525 | }); |
526 | 526 | $this->registerAlias('Search', \OCP\ISearch::class); |
527 | 527 | |
528 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
528 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
529 | 529 | return new SecureRandom(); |
530 | 530 | }); |
531 | 531 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
532 | 532 | |
533 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
533 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
534 | 534 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
535 | 535 | }); |
536 | 536 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
537 | 537 | |
538 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
538 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
539 | 539 | return new Hasher($c->getConfig()); |
540 | 540 | }); |
541 | 541 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
542 | 542 | |
543 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
543 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
544 | 544 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
545 | 545 | }); |
546 | 546 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
547 | 547 | |
548 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
548 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
549 | 549 | $systemConfig = $c->getSystemConfig(); |
550 | 550 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
551 | 551 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | }); |
560 | 560 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
561 | 561 | |
562 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
562 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
563 | 563 | $config = $c->getConfig(); |
564 | 564 | return new HTTPHelper( |
565 | 565 | $config, |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | ); |
568 | 568 | }); |
569 | 569 | |
570 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
570 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
571 | 571 | $user = \OC_User::getUser(); |
572 | 572 | $uid = $user ? $user : null; |
573 | 573 | return new ClientService( |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | }); |
578 | 578 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
579 | 579 | |
580 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
580 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
581 | 581 | if ($c->getSystemConfig()->getValue('debug', false)) { |
582 | 582 | return new EventLogger(); |
583 | 583 | } else { |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | }); |
587 | 587 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
588 | 588 | |
589 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
589 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
590 | 590 | if ($c->getSystemConfig()->getValue('debug', false)) { |
591 | 591 | return new QueryLogger(); |
592 | 592 | } else { |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | }); |
596 | 596 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
597 | 597 | |
598 | - $this->registerService(TempManager::class, function (Server $c) { |
|
598 | + $this->registerService(TempManager::class, function(Server $c) { |
|
599 | 599 | return new TempManager( |
600 | 600 | $c->getLogger(), |
601 | 601 | $c->getConfig() |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | $this->registerAlias('TempManager', TempManager::class); |
605 | 605 | $this->registerAlias(ITempManager::class, TempManager::class); |
606 | 606 | |
607 | - $this->registerService(AppManager::class, function (Server $c) { |
|
607 | + $this->registerService(AppManager::class, function(Server $c) { |
|
608 | 608 | return new \OC\App\AppManager( |
609 | 609 | $c->getUserSession(), |
610 | 610 | $c->getAppConfig(), |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | $this->registerAlias('AppManager', AppManager::class); |
617 | 617 | $this->registerAlias(IAppManager::class, AppManager::class); |
618 | 618 | |
619 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
619 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
620 | 620 | return new DateTimeZone( |
621 | 621 | $c->getConfig(), |
622 | 622 | $c->getSession() |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | }); |
625 | 625 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
626 | 626 | |
627 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
627 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
628 | 628 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
629 | 629 | |
630 | 630 | return new DateTimeFormatter( |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | }); |
635 | 635 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
636 | 636 | |
637 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
637 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
638 | 638 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
639 | 639 | $listener = new UserMountCacheListener($mountCache); |
640 | 640 | $listener->listen($c->getUserManager()); |
@@ -642,10 +642,10 @@ discard block |
||
642 | 642 | }); |
643 | 643 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
644 | 644 | |
645 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
645 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
646 | 646 | $loader = \OC\Files\Filesystem::getLoader(); |
647 | 647 | $mountCache = $c->query('UserMountCache'); |
648 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
648 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
649 | 649 | |
650 | 650 | // builtin providers |
651 | 651 | |
@@ -658,14 +658,14 @@ discard block |
||
658 | 658 | }); |
659 | 659 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
660 | 660 | |
661 | - $this->registerService('IniWrapper', function ($c) { |
|
661 | + $this->registerService('IniWrapper', function($c) { |
|
662 | 662 | return new IniGetWrapper(); |
663 | 663 | }); |
664 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
664 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
665 | 665 | $jobList = $c->getJobList(); |
666 | 666 | return new AsyncBus($jobList); |
667 | 667 | }); |
668 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
668 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
669 | 669 | return new TrustedDomainHelper($this->getConfig()); |
670 | 670 | }); |
671 | 671 | $this->registerService('Throttler', function(Server $c) { |
@@ -676,10 +676,10 @@ discard block |
||
676 | 676 | $c->getConfig() |
677 | 677 | ); |
678 | 678 | }); |
679 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
679 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
680 | 680 | // IConfig and IAppManager requires a working database. This code |
681 | 681 | // might however be called when ownCloud is not yet setup. |
682 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
682 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
683 | 683 | $config = $c->getConfig(); |
684 | 684 | $appManager = $c->getAppManager(); |
685 | 685 | } else { |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | $c->getTempManager() |
698 | 698 | ); |
699 | 699 | }); |
700 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
700 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
701 | 701 | if (isset($this['urlParams'])) { |
702 | 702 | $urlParams = $this['urlParams']; |
703 | 703 | } else { |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | }); |
734 | 734 | $this->registerAlias('Request', \OCP\IRequest::class); |
735 | 735 | |
736 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
736 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
737 | 737 | return new Mailer( |
738 | 738 | $c->getConfig(), |
739 | 739 | $c->getLogger(), |
@@ -745,14 +745,14 @@ discard block |
||
745 | 745 | $this->registerService('LDAPProvider', function(Server $c) { |
746 | 746 | $config = $c->getConfig(); |
747 | 747 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
748 | - if(is_null($factoryClass)) { |
|
748 | + if (is_null($factoryClass)) { |
|
749 | 749 | throw new \Exception('ldapProviderFactory not set'); |
750 | 750 | } |
751 | 751 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
752 | 752 | $factory = new $factoryClass($this); |
753 | 753 | return $factory->getLDAPProvider(); |
754 | 754 | }); |
755 | - $this->registerService('LockingProvider', function (Server $c) { |
|
755 | + $this->registerService('LockingProvider', function(Server $c) { |
|
756 | 756 | $ini = $c->getIniWrapper(); |
757 | 757 | $config = $c->getConfig(); |
758 | 758 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -768,37 +768,37 @@ discard block |
||
768 | 768 | return new NoopLockingProvider(); |
769 | 769 | }); |
770 | 770 | |
771 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
771 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
772 | 772 | return new \OC\Files\Mount\Manager(); |
773 | 773 | }); |
774 | 774 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
775 | 775 | |
776 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
776 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
777 | 777 | return new \OC\Files\Type\Detection( |
778 | 778 | $c->getURLGenerator(), |
779 | 779 | \OC::$configDir, |
780 | - \OC::$SERVERROOT . '/resources/config/' |
|
780 | + \OC::$SERVERROOT.'/resources/config/' |
|
781 | 781 | ); |
782 | 782 | }); |
783 | 783 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
784 | 784 | |
785 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
785 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
786 | 786 | return new \OC\Files\Type\Loader( |
787 | 787 | $c->getDatabaseConnection() |
788 | 788 | ); |
789 | 789 | }); |
790 | 790 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
791 | 791 | |
792 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
792 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
793 | 793 | return new Manager( |
794 | 794 | $c->query(IValidator::class) |
795 | 795 | ); |
796 | 796 | }); |
797 | 797 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
798 | 798 | |
799 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
799 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
800 | 800 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
801 | - $manager->registerCapability(function () use ($c) { |
|
801 | + $manager->registerCapability(function() use ($c) { |
|
802 | 802 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
803 | 803 | }); |
804 | 804 | return $manager; |
@@ -840,13 +840,13 @@ discard block |
||
840 | 840 | } |
841 | 841 | return new \OC_Defaults(); |
842 | 842 | }); |
843 | - $this->registerService(EventDispatcher::class, function () { |
|
843 | + $this->registerService(EventDispatcher::class, function() { |
|
844 | 844 | return new EventDispatcher(); |
845 | 845 | }); |
846 | 846 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
847 | 847 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
848 | 848 | |
849 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
849 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
850 | 850 | // FIXME: Instantiiated here due to cyclic dependency |
851 | 851 | $request = new Request( |
852 | 852 | [ |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | $request |
872 | 872 | ); |
873 | 873 | }); |
874 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
874 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
875 | 875 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
876 | 876 | |
877 | 877 | return new CsrfTokenManager( |
@@ -879,10 +879,10 @@ discard block |
||
879 | 879 | $c->query(SessionStorage::class) |
880 | 880 | ); |
881 | 881 | }); |
882 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
882 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
883 | 883 | return new SessionStorage($c->getSession()); |
884 | 884 | }); |
885 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
885 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
886 | 886 | return new ContentSecurityPolicyManager(); |
887 | 887 | }); |
888 | 888 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
@@ -933,25 +933,25 @@ discard block |
||
933 | 933 | ); |
934 | 934 | return $manager; |
935 | 935 | }); |
936 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
936 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
937 | 937 | return new \OC\Files\AppData\Factory( |
938 | 938 | $c->getRootFolder(), |
939 | 939 | $c->getSystemConfig() |
940 | 940 | ); |
941 | 941 | }); |
942 | 942 | |
943 | - $this->registerService('LockdownManager', function (Server $c) { |
|
943 | + $this->registerService('LockdownManager', function(Server $c) { |
|
944 | 944 | return new LockdownManager(function() use ($c) { |
945 | 945 | return $c->getSession(); |
946 | 946 | }); |
947 | 947 | }); |
948 | 948 | |
949 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
949 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
950 | 950 | return new CloudIdManager(); |
951 | 951 | }); |
952 | 952 | |
953 | 953 | /* To trick DI since we don't extend the DIContainer here */ |
954 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
954 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
955 | 955 | return new CleanPreviewsBackgroundJob( |
956 | 956 | $c->getRootFolder(), |
957 | 957 | $c->getLogger(), |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | * @deprecated since 9.2.0 use IAppData |
1106 | 1106 | */ |
1107 | 1107 | public function getAppFolder() { |
1108 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1108 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1109 | 1109 | $root = $this->getRootFolder(); |
1110 | 1110 | if (!$root->nodeExists($dir)) { |
1111 | 1111 | $folder = $root->newFolder($dir); |
@@ -30,67 +30,67 @@ |
||
30 | 30 | |
31 | 31 | class Manager { |
32 | 32 | |
33 | - /** @var ContactsStore */ |
|
34 | - private $store; |
|
33 | + /** @var ContactsStore */ |
|
34 | + private $store; |
|
35 | 35 | |
36 | - /** @var ActionProviderStore */ |
|
37 | - private $actionProviderStore; |
|
36 | + /** @var ActionProviderStore */ |
|
37 | + private $actionProviderStore; |
|
38 | 38 | |
39 | - /** @var IAppManager */ |
|
40 | - private $appManager; |
|
39 | + /** @var IAppManager */ |
|
40 | + private $appManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param ContactsStore $store |
|
44 | - * @param ActionProviderStore $actionProviderStore |
|
45 | - * @param IAppManager $appManager |
|
46 | - */ |
|
47 | - public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager) { |
|
48 | - $this->store = $store; |
|
49 | - $this->actionProviderStore = $actionProviderStore; |
|
50 | - $this->appManager = $appManager; |
|
51 | - } |
|
42 | + /** |
|
43 | + * @param ContactsStore $store |
|
44 | + * @param ActionProviderStore $actionProviderStore |
|
45 | + * @param IAppManager $appManager |
|
46 | + */ |
|
47 | + public function __construct(ContactsStore $store, ActionProviderStore $actionProviderStore, IAppManager $appManager) { |
|
48 | + $this->store = $store; |
|
49 | + $this->actionProviderStore = $actionProviderStore; |
|
50 | + $this->appManager = $appManager; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $user |
|
55 | - * @param string $filter |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getEntries(IUser $user, $filter) { |
|
59 | - $entries = $this->store->getContacts($user, $filter); |
|
53 | + /** |
|
54 | + * @param string $user |
|
55 | + * @param string $filter |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getEntries(IUser $user, $filter) { |
|
59 | + $entries = $this->store->getContacts($user, $filter); |
|
60 | 60 | |
61 | - $sortedEntries = $this->sortEntries($entries); |
|
62 | - $topEntries = array_slice($sortedEntries, 0, 25); |
|
63 | - $this->processEntries($topEntries, $user); |
|
61 | + $sortedEntries = $this->sortEntries($entries); |
|
62 | + $topEntries = array_slice($sortedEntries, 0, 25); |
|
63 | + $this->processEntries($topEntries, $user); |
|
64 | 64 | |
65 | - $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
66 | - return [ |
|
67 | - 'contacts' => $topEntries, |
|
68 | - 'contactsAppEnabled' => $contactsEnabled, |
|
69 | - ]; |
|
70 | - } |
|
65 | + $contactsEnabled = $this->appManager->isEnabledForUser('contacts', $user); |
|
66 | + return [ |
|
67 | + 'contacts' => $topEntries, |
|
68 | + 'contactsAppEnabled' => $contactsEnabled, |
|
69 | + ]; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param IEntry[] $entries |
|
74 | - * @return IEntry[] |
|
75 | - */ |
|
76 | - private function sortEntries(array $entries) { |
|
77 | - usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
78 | - return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
79 | - }); |
|
80 | - return $entries; |
|
81 | - } |
|
72 | + /** |
|
73 | + * @param IEntry[] $entries |
|
74 | + * @return IEntry[] |
|
75 | + */ |
|
76 | + private function sortEntries(array $entries) { |
|
77 | + usort($entries, function(IEntry $entryA, IEntry $entryB) { |
|
78 | + return strcasecmp($entryA->getFullName(), $entryB->getFullName()); |
|
79 | + }); |
|
80 | + return $entries; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param IEntry[] $entries |
|
85 | - * @param IUser $user |
|
86 | - */ |
|
87 | - private function processEntries(array $entries, IUser $user) { |
|
88 | - $providers = $this->actionProviderStore->getProviders($user); |
|
89 | - foreach ($entries as $entry) { |
|
90 | - foreach ($providers as $provider) { |
|
91 | - $provider->process($entry); |
|
92 | - } |
|
93 | - } |
|
94 | - } |
|
83 | + /** |
|
84 | + * @param IEntry[] $entries |
|
85 | + * @param IUser $user |
|
86 | + */ |
|
87 | + private function processEntries(array $entries, IUser $user) { |
|
88 | + $providers = $this->actionProviderStore->getProviders($user); |
|
89 | + foreach ($entries as $entry) { |
|
90 | + foreach ($providers as $provider) { |
|
91 | + $provider->process($entry); |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | 96 | } |
@@ -30,66 +30,66 @@ |
||
30 | 30 | |
31 | 31 | class ContactsStore { |
32 | 32 | |
33 | - /** @var IManager */ |
|
34 | - private $contactsManager; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param IManager $contactsManager |
|
38 | - */ |
|
39 | - public function __construct(IManager $contactsManager) { |
|
40 | - $this->contactsManager = $contactsManager; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param IUser $user |
|
45 | - * @param string|null $filter |
|
46 | - * @return IEntry[] |
|
47 | - */ |
|
48 | - public function getContacts(IUser $user, $filter) { |
|
49 | - $allContacts = $this->contactsManager->search($filter ?: '', [ |
|
50 | - 'FN', |
|
51 | - ]); |
|
52 | - |
|
53 | - $self = $user->getUID(); |
|
54 | - $entries = array_map(function(array $contact) { |
|
55 | - return $this->contactArrayToEntry($contact); |
|
56 | - }, $allContacts); |
|
57 | - return array_filter($entries, function(IEntry $entry) use ($self) { |
|
58 | - return $entry->getProperty('UID') !== $self; |
|
59 | - }); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @param array $contact |
|
64 | - * @return Entry |
|
65 | - */ |
|
66 | - private function contactArrayToEntry(array $contact) { |
|
67 | - $entry = new Entry(); |
|
68 | - |
|
69 | - if (isset($contact['id'])) { |
|
70 | - $entry->setId($contact['id']); |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($contact['FN'])) { |
|
74 | - $entry->setFullName($contact['FN']); |
|
75 | - } |
|
76 | - |
|
77 | - $avatarPrefix = "VALUE=uri:"; |
|
78 | - if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) { |
|
79 | - $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix))); |
|
80 | - } |
|
81 | - |
|
82 | - if (isset($contact['EMAIL'])) { |
|
83 | - foreach ($contact['EMAIL'] as $email) { |
|
84 | - $entry->addEMailAddress($email); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - // Attach all other properties to the entry too because some |
|
89 | - // providers might make use of it. |
|
90 | - $entry->setProperties($contact); |
|
91 | - |
|
92 | - return $entry; |
|
93 | - } |
|
33 | + /** @var IManager */ |
|
34 | + private $contactsManager; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param IManager $contactsManager |
|
38 | + */ |
|
39 | + public function __construct(IManager $contactsManager) { |
|
40 | + $this->contactsManager = $contactsManager; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param IUser $user |
|
45 | + * @param string|null $filter |
|
46 | + * @return IEntry[] |
|
47 | + */ |
|
48 | + public function getContacts(IUser $user, $filter) { |
|
49 | + $allContacts = $this->contactsManager->search($filter ?: '', [ |
|
50 | + 'FN', |
|
51 | + ]); |
|
52 | + |
|
53 | + $self = $user->getUID(); |
|
54 | + $entries = array_map(function(array $contact) { |
|
55 | + return $this->contactArrayToEntry($contact); |
|
56 | + }, $allContacts); |
|
57 | + return array_filter($entries, function(IEntry $entry) use ($self) { |
|
58 | + return $entry->getProperty('UID') !== $self; |
|
59 | + }); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @param array $contact |
|
64 | + * @return Entry |
|
65 | + */ |
|
66 | + private function contactArrayToEntry(array $contact) { |
|
67 | + $entry = new Entry(); |
|
68 | + |
|
69 | + if (isset($contact['id'])) { |
|
70 | + $entry->setId($contact['id']); |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($contact['FN'])) { |
|
74 | + $entry->setFullName($contact['FN']); |
|
75 | + } |
|
76 | + |
|
77 | + $avatarPrefix = "VALUE=uri:"; |
|
78 | + if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) { |
|
79 | + $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix))); |
|
80 | + } |
|
81 | + |
|
82 | + if (isset($contact['EMAIL'])) { |
|
83 | + foreach ($contact['EMAIL'] as $email) { |
|
84 | + $entry->addEMailAddress($email); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + // Attach all other properties to the entry too because some |
|
89 | + // providers might make use of it. |
|
90 | + $entry->setProperties($contact); |
|
91 | + |
|
92 | + return $entry; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | } |