@@ -36,54 +36,54 @@ |
||
36 | 36 | * @method void setName(string $name) |
37 | 37 | */ |
38 | 38 | class Tag extends Entity { |
39 | - protected $owner; |
|
40 | - protected $type; |
|
41 | - protected $name; |
|
39 | + protected $owner; |
|
40 | + protected $type; |
|
41 | + protected $name; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param string $owner The tag's owner |
|
47 | - * @param string $type The type of item this tag is used for |
|
48 | - * @param string $name The tag's name |
|
49 | - */ |
|
50 | - public function __construct($owner = null, $type = null, $name = null) { |
|
51 | - $this->setOwner($owner); |
|
52 | - $this->setType($type); |
|
53 | - $this->setName($name); |
|
54 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param string $owner The tag's owner |
|
47 | + * @param string $type The type of item this tag is used for |
|
48 | + * @param string $name The tag's name |
|
49 | + */ |
|
50 | + public function __construct($owner = null, $type = null, $name = null) { |
|
51 | + $this->setOwner($owner); |
|
52 | + $this->setType($type); |
|
53 | + $this->setName($name); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Transform a database columnname to a property |
|
58 | - * |
|
59 | - * @param string $columnName the name of the column |
|
60 | - * @return string the property name |
|
61 | - * @todo migrate existing database columns to the correct names |
|
62 | - * to be able to drop this direct mapping |
|
63 | - */ |
|
64 | - public function columnToProperty($columnName) { |
|
65 | - if ($columnName === 'category') { |
|
66 | - return 'name'; |
|
67 | - } elseif ($columnName === 'uid') { |
|
68 | - return 'owner'; |
|
69 | - } else { |
|
70 | - return parent::columnToProperty($columnName); |
|
71 | - } |
|
72 | - } |
|
56 | + /** |
|
57 | + * Transform a database columnname to a property |
|
58 | + * |
|
59 | + * @param string $columnName the name of the column |
|
60 | + * @return string the property name |
|
61 | + * @todo migrate existing database columns to the correct names |
|
62 | + * to be able to drop this direct mapping |
|
63 | + */ |
|
64 | + public function columnToProperty($columnName) { |
|
65 | + if ($columnName === 'category') { |
|
66 | + return 'name'; |
|
67 | + } elseif ($columnName === 'uid') { |
|
68 | + return 'owner'; |
|
69 | + } else { |
|
70 | + return parent::columnToProperty($columnName); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Transform a property to a database column name |
|
76 | - * |
|
77 | - * @param string $property the name of the property |
|
78 | - * @return string the column name |
|
79 | - */ |
|
80 | - public function propertyToColumn($property) { |
|
81 | - if ($property === 'name') { |
|
82 | - return 'category'; |
|
83 | - } elseif ($property === 'owner') { |
|
84 | - return 'uid'; |
|
85 | - } else { |
|
86 | - return parent::propertyToColumn($property); |
|
87 | - } |
|
88 | - } |
|
74 | + /** |
|
75 | + * Transform a property to a database column name |
|
76 | + * |
|
77 | + * @param string $property the name of the property |
|
78 | + * @return string the column name |
|
79 | + */ |
|
80 | + public function propertyToColumn($property) { |
|
81 | + if ($property === 'name') { |
|
82 | + return 'category'; |
|
83 | + } elseif ($property === 'owner') { |
|
84 | + return 'uid'; |
|
85 | + } else { |
|
86 | + return parent::propertyToColumn($property); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @package OC\AppFramework\Middleware\Security\Exceptions |
33 | 33 | */ |
34 | 34 | class StrictCookieMissingException extends SecurityException { |
35 | - public function __construct() { |
|
36 | - parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | - } |
|
35 | + public function __construct() { |
|
36 | + parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | + } |
|
38 | 38 | } |
@@ -85,7 +85,7 @@ |
||
85 | 85 | $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
86 | 86 | $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
87 | 87 | $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
88 | - $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
88 | + $rateLimitIdentifier = get_class($controller).'::'.$methodName; |
|
89 | 89 | if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
90 | 90 | $this->limiter->registerUserRequest( |
91 | 91 | $rateLimitIdentifier, |
@@ -50,80 +50,80 @@ |
||
50 | 50 | * @package OC\AppFramework\Middleware\Security |
51 | 51 | */ |
52 | 52 | class RateLimitingMiddleware extends Middleware { |
53 | - /** @var IRequest $request */ |
|
54 | - private $request; |
|
55 | - /** @var IUserSession */ |
|
56 | - private $userSession; |
|
57 | - /** @var ControllerMethodReflector */ |
|
58 | - private $reflector; |
|
59 | - /** @var Limiter */ |
|
60 | - private $limiter; |
|
53 | + /** @var IRequest $request */ |
|
54 | + private $request; |
|
55 | + /** @var IUserSession */ |
|
56 | + private $userSession; |
|
57 | + /** @var ControllerMethodReflector */ |
|
58 | + private $reflector; |
|
59 | + /** @var Limiter */ |
|
60 | + private $limiter; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param IRequest $request |
|
64 | - * @param IUserSession $userSession |
|
65 | - * @param ControllerMethodReflector $reflector |
|
66 | - * @param Limiter $limiter |
|
67 | - */ |
|
68 | - public function __construct(IRequest $request, |
|
69 | - IUserSession $userSession, |
|
70 | - ControllerMethodReflector $reflector, |
|
71 | - Limiter $limiter) { |
|
72 | - $this->request = $request; |
|
73 | - $this->userSession = $userSession; |
|
74 | - $this->reflector = $reflector; |
|
75 | - $this->limiter = $limiter; |
|
76 | - } |
|
62 | + /** |
|
63 | + * @param IRequest $request |
|
64 | + * @param IUserSession $userSession |
|
65 | + * @param ControllerMethodReflector $reflector |
|
66 | + * @param Limiter $limiter |
|
67 | + */ |
|
68 | + public function __construct(IRequest $request, |
|
69 | + IUserSession $userSession, |
|
70 | + ControllerMethodReflector $reflector, |
|
71 | + Limiter $limiter) { |
|
72 | + $this->request = $request; |
|
73 | + $this->userSession = $userSession; |
|
74 | + $this->reflector = $reflector; |
|
75 | + $this->limiter = $limiter; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * {@inheritDoc} |
|
80 | - * @throws RateLimitExceededException |
|
81 | - */ |
|
82 | - public function beforeController($controller, $methodName) { |
|
83 | - parent::beforeController($controller, $methodName); |
|
78 | + /** |
|
79 | + * {@inheritDoc} |
|
80 | + * @throws RateLimitExceededException |
|
81 | + */ |
|
82 | + public function beforeController($controller, $methodName) { |
|
83 | + parent::beforeController($controller, $methodName); |
|
84 | 84 | |
85 | - $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
86 | - $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
87 | - $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
88 | - $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
89 | - $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
90 | - if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
91 | - $this->limiter->registerUserRequest( |
|
92 | - $rateLimitIdentifier, |
|
93 | - $userLimit, |
|
94 | - $userPeriod, |
|
95 | - $this->userSession->getUser() |
|
96 | - ); |
|
97 | - } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
98 | - $this->limiter->registerAnonRequest( |
|
99 | - $rateLimitIdentifier, |
|
100 | - $anonLimit, |
|
101 | - $anonPeriod, |
|
102 | - $this->request->getRemoteAddress() |
|
103 | - ); |
|
104 | - } |
|
105 | - } |
|
85 | + $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); |
|
86 | + $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period'); |
|
87 | + $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit'); |
|
88 | + $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period'); |
|
89 | + $rateLimitIdentifier = get_class($controller) . '::' . $methodName; |
|
90 | + if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) { |
|
91 | + $this->limiter->registerUserRequest( |
|
92 | + $rateLimitIdentifier, |
|
93 | + $userLimit, |
|
94 | + $userPeriod, |
|
95 | + $this->userSession->getUser() |
|
96 | + ); |
|
97 | + } elseif ($anonLimit !== '' && $anonPeriod !== '') { |
|
98 | + $this->limiter->registerAnonRequest( |
|
99 | + $rateLimitIdentifier, |
|
100 | + $anonLimit, |
|
101 | + $anonPeriod, |
|
102 | + $this->request->getRemoteAddress() |
|
103 | + ); |
|
104 | + } |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * {@inheritDoc} |
|
109 | - */ |
|
110 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
111 | - if ($exception instanceof RateLimitExceededException) { |
|
112 | - if (stripos($this->request->getHeader('Accept'), 'html') === false) { |
|
113 | - $response = new DataResponse([], $exception->getCode()); |
|
114 | - } else { |
|
115 | - $response = new TemplateResponse( |
|
116 | - 'core', |
|
117 | - '429', |
|
118 | - [], |
|
119 | - TemplateResponse::RENDER_AS_GUEST |
|
120 | - ); |
|
121 | - $response->setStatus($exception->getCode()); |
|
122 | - } |
|
107 | + /** |
|
108 | + * {@inheritDoc} |
|
109 | + */ |
|
110 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
111 | + if ($exception instanceof RateLimitExceededException) { |
|
112 | + if (stripos($this->request->getHeader('Accept'), 'html') === false) { |
|
113 | + $response = new DataResponse([], $exception->getCode()); |
|
114 | + } else { |
|
115 | + $response = new TemplateResponse( |
|
116 | + 'core', |
|
117 | + '429', |
|
118 | + [], |
|
119 | + TemplateResponse::RENDER_AS_GUEST |
|
120 | + ); |
|
121 | + $response->setStatus($exception->getCode()); |
|
122 | + } |
|
123 | 123 | |
124 | - return $response; |
|
125 | - } |
|
124 | + return $response; |
|
125 | + } |
|
126 | 126 | |
127 | - throw $exception; |
|
128 | - } |
|
127 | + throw $exception; |
|
128 | + } |
|
129 | 129 | } |
@@ -70,8 +70,8 @@ |
||
70 | 70 | 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
71 | 71 | ]; |
72 | 72 | |
73 | - $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
74 | - $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
73 | + $meta['totalitems'] = $this->itemsCount !== null ? (string) $this->itemsCount : ''; |
|
74 | + $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string) $this->itemsPerPage : ''; |
|
75 | 75 | |
76 | 76 | return $this->renderResult($meta); |
77 | 77 | } |
@@ -29,52 +29,52 @@ |
||
29 | 29 | |
30 | 30 | class V1Response extends BaseResponse { |
31 | 31 | |
32 | - /** |
|
33 | - * The V1 endpoint has very limited http status codes basically everything |
|
34 | - * is status 200 except 401 |
|
35 | - * |
|
36 | - * @return int |
|
37 | - */ |
|
38 | - public function getStatus() { |
|
39 | - $status = parent::getStatus(); |
|
40 | - if ($status === OCSController::RESPOND_UNAUTHORISED) { |
|
41 | - return Http::STATUS_UNAUTHORIZED; |
|
42 | - } |
|
32 | + /** |
|
33 | + * The V1 endpoint has very limited http status codes basically everything |
|
34 | + * is status 200 except 401 |
|
35 | + * |
|
36 | + * @return int |
|
37 | + */ |
|
38 | + public function getStatus() { |
|
39 | + $status = parent::getStatus(); |
|
40 | + if ($status === OCSController::RESPOND_UNAUTHORISED) { |
|
41 | + return Http::STATUS_UNAUTHORIZED; |
|
42 | + } |
|
43 | 43 | |
44 | - return Http::STATUS_OK; |
|
45 | - } |
|
44 | + return Http::STATUS_OK; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * In v1 all OK is 100 |
|
49 | - * |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function getOCSStatus() { |
|
53 | - $status = parent::getOCSStatus(); |
|
47 | + /** |
|
48 | + * In v1 all OK is 100 |
|
49 | + * |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function getOCSStatus() { |
|
53 | + $status = parent::getOCSStatus(); |
|
54 | 54 | |
55 | - if ($status === Http::STATUS_OK) { |
|
56 | - return 100; |
|
57 | - } |
|
55 | + if ($status === Http::STATUS_OK) { |
|
56 | + return 100; |
|
57 | + } |
|
58 | 58 | |
59 | - return $status; |
|
60 | - } |
|
59 | + return $status; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Construct the meta part of the response |
|
64 | - * And then late the base class render |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function render() { |
|
69 | - $meta = [ |
|
70 | - 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure', |
|
71 | - 'statuscode' => $this->getOCSStatus(), |
|
72 | - 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
|
73 | - ]; |
|
62 | + /** |
|
63 | + * Construct the meta part of the response |
|
64 | + * And then late the base class render |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function render() { |
|
69 | + $meta = [ |
|
70 | + 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure', |
|
71 | + 'statuscode' => $this->getOCSStatus(), |
|
72 | + 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
|
73 | + ]; |
|
74 | 74 | |
75 | - $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
76 | - $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
75 | + $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
76 | + $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
77 | 77 | |
78 | - return $this->renderResult($meta); |
|
79 | - } |
|
78 | + return $this->renderResult($meta); |
|
79 | + } |
|
80 | 80 | } |
@@ -147,7 +147,7 @@ |
||
147 | 147 | if (isset($this->entityTypeCollections[$name])) { |
148 | 148 | return $this->entityTypeCollections[$name]; |
149 | 149 | } |
150 | - throw new NotFound('Entity type "' . $name . '" not found."'); |
|
150 | + throw new NotFound('Entity type "'.$name.'" not found."'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -37,168 +37,168 @@ |
||
37 | 37 | |
38 | 38 | class RootCollection implements ICollection { |
39 | 39 | |
40 | - /** @var EntityTypeCollection[]|null */ |
|
41 | - private $entityTypeCollections; |
|
42 | - |
|
43 | - /** @var ICommentsManager */ |
|
44 | - protected $commentsManager; |
|
45 | - |
|
46 | - /** @var string */ |
|
47 | - protected $name = 'comments'; |
|
48 | - |
|
49 | - protected LoggerInterface $logger; |
|
50 | - |
|
51 | - /** @var IUserManager */ |
|
52 | - protected $userManager; |
|
53 | - |
|
54 | - /** @var IUserSession */ |
|
55 | - protected $userSession; |
|
56 | - |
|
57 | - /** @var EventDispatcherInterface */ |
|
58 | - protected $dispatcher; |
|
59 | - |
|
60 | - public function __construct( |
|
61 | - ICommentsManager $commentsManager, |
|
62 | - IUserManager $userManager, |
|
63 | - IUserSession $userSession, |
|
64 | - EventDispatcherInterface $dispatcher, |
|
65 | - LoggerInterface $logger) { |
|
66 | - $this->commentsManager = $commentsManager; |
|
67 | - $this->logger = $logger; |
|
68 | - $this->userManager = $userManager; |
|
69 | - $this->userSession = $userSession; |
|
70 | - $this->dispatcher = $dispatcher; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * initializes the collection. At this point of time, we need the logged in |
|
75 | - * user. Since it is not the case when the instance is created, we cannot |
|
76 | - * have this in the constructor. |
|
77 | - * |
|
78 | - * @throws NotAuthenticated |
|
79 | - */ |
|
80 | - protected function initCollections() { |
|
81 | - if ($this->entityTypeCollections !== null) { |
|
82 | - return; |
|
83 | - } |
|
84 | - $user = $this->userSession->getUser(); |
|
85 | - if (is_null($user)) { |
|
86 | - throw new NotAuthenticated(); |
|
87 | - } |
|
88 | - |
|
89 | - $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY); |
|
90 | - $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event); |
|
91 | - |
|
92 | - $this->entityTypeCollections = []; |
|
93 | - foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
94 | - $this->entityTypeCollections[$entity] = new EntityTypeCollection( |
|
95 | - $entity, |
|
96 | - $this->commentsManager, |
|
97 | - $this->userManager, |
|
98 | - $this->userSession, |
|
99 | - $this->logger, |
|
100 | - $entityExistsFunction |
|
101 | - ); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Creates a new file in the directory |
|
107 | - * |
|
108 | - * @param string $name Name of the file |
|
109 | - * @param resource|string $data Initial payload |
|
110 | - * @return null|string |
|
111 | - * @throws Forbidden |
|
112 | - */ |
|
113 | - public function createFile($name, $data = null) { |
|
114 | - throw new Forbidden('Cannot create comments by id'); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Creates a new subdirectory |
|
119 | - * |
|
120 | - * @param string $name |
|
121 | - * @throws Forbidden |
|
122 | - */ |
|
123 | - public function createDirectory($name) { |
|
124 | - throw new Forbidden('Permission denied to create collections'); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Returns a specific child node, referenced by its name |
|
129 | - * |
|
130 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
131 | - * exist. |
|
132 | - * |
|
133 | - * @param string $name |
|
134 | - * @return \Sabre\DAV\INode |
|
135 | - * @throws NotFound |
|
136 | - */ |
|
137 | - public function getChild($name) { |
|
138 | - $this->initCollections(); |
|
139 | - if (isset($this->entityTypeCollections[$name])) { |
|
140 | - return $this->entityTypeCollections[$name]; |
|
141 | - } |
|
142 | - throw new NotFound('Entity type "' . $name . '" not found."'); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Returns an array with all the child nodes |
|
147 | - * |
|
148 | - * @return \Sabre\DAV\INode[] |
|
149 | - */ |
|
150 | - public function getChildren() { |
|
151 | - $this->initCollections(); |
|
152 | - return $this->entityTypeCollections; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Checks if a child-node with the specified name exists |
|
157 | - * |
|
158 | - * @param string $name |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - public function childExists($name) { |
|
162 | - $this->initCollections(); |
|
163 | - return isset($this->entityTypeCollections[$name]); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Deleted the current node |
|
168 | - * |
|
169 | - * @throws Forbidden |
|
170 | - */ |
|
171 | - public function delete() { |
|
172 | - throw new Forbidden('Permission denied to delete this collection'); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Returns the name of the node. |
|
177 | - * |
|
178 | - * This is used to generate the url. |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function getName() { |
|
183 | - return $this->name; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Renames the node |
|
188 | - * |
|
189 | - * @param string $name The new name |
|
190 | - * @throws Forbidden |
|
191 | - */ |
|
192 | - public function setName($name) { |
|
193 | - throw new Forbidden('Permission denied to rename this collection'); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Returns the last modification time, as a unix timestamp |
|
198 | - * |
|
199 | - * @return int |
|
200 | - */ |
|
201 | - public function getLastModified() { |
|
202 | - return null; |
|
203 | - } |
|
40 | + /** @var EntityTypeCollection[]|null */ |
|
41 | + private $entityTypeCollections; |
|
42 | + |
|
43 | + /** @var ICommentsManager */ |
|
44 | + protected $commentsManager; |
|
45 | + |
|
46 | + /** @var string */ |
|
47 | + protected $name = 'comments'; |
|
48 | + |
|
49 | + protected LoggerInterface $logger; |
|
50 | + |
|
51 | + /** @var IUserManager */ |
|
52 | + protected $userManager; |
|
53 | + |
|
54 | + /** @var IUserSession */ |
|
55 | + protected $userSession; |
|
56 | + |
|
57 | + /** @var EventDispatcherInterface */ |
|
58 | + protected $dispatcher; |
|
59 | + |
|
60 | + public function __construct( |
|
61 | + ICommentsManager $commentsManager, |
|
62 | + IUserManager $userManager, |
|
63 | + IUserSession $userSession, |
|
64 | + EventDispatcherInterface $dispatcher, |
|
65 | + LoggerInterface $logger) { |
|
66 | + $this->commentsManager = $commentsManager; |
|
67 | + $this->logger = $logger; |
|
68 | + $this->userManager = $userManager; |
|
69 | + $this->userSession = $userSession; |
|
70 | + $this->dispatcher = $dispatcher; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * initializes the collection. At this point of time, we need the logged in |
|
75 | + * user. Since it is not the case when the instance is created, we cannot |
|
76 | + * have this in the constructor. |
|
77 | + * |
|
78 | + * @throws NotAuthenticated |
|
79 | + */ |
|
80 | + protected function initCollections() { |
|
81 | + if ($this->entityTypeCollections !== null) { |
|
82 | + return; |
|
83 | + } |
|
84 | + $user = $this->userSession->getUser(); |
|
85 | + if (is_null($user)) { |
|
86 | + throw new NotAuthenticated(); |
|
87 | + } |
|
88 | + |
|
89 | + $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY); |
|
90 | + $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event); |
|
91 | + |
|
92 | + $this->entityTypeCollections = []; |
|
93 | + foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) { |
|
94 | + $this->entityTypeCollections[$entity] = new EntityTypeCollection( |
|
95 | + $entity, |
|
96 | + $this->commentsManager, |
|
97 | + $this->userManager, |
|
98 | + $this->userSession, |
|
99 | + $this->logger, |
|
100 | + $entityExistsFunction |
|
101 | + ); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Creates a new file in the directory |
|
107 | + * |
|
108 | + * @param string $name Name of the file |
|
109 | + * @param resource|string $data Initial payload |
|
110 | + * @return null|string |
|
111 | + * @throws Forbidden |
|
112 | + */ |
|
113 | + public function createFile($name, $data = null) { |
|
114 | + throw new Forbidden('Cannot create comments by id'); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Creates a new subdirectory |
|
119 | + * |
|
120 | + * @param string $name |
|
121 | + * @throws Forbidden |
|
122 | + */ |
|
123 | + public function createDirectory($name) { |
|
124 | + throw new Forbidden('Permission denied to create collections'); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Returns a specific child node, referenced by its name |
|
129 | + * |
|
130 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
131 | + * exist. |
|
132 | + * |
|
133 | + * @param string $name |
|
134 | + * @return \Sabre\DAV\INode |
|
135 | + * @throws NotFound |
|
136 | + */ |
|
137 | + public function getChild($name) { |
|
138 | + $this->initCollections(); |
|
139 | + if (isset($this->entityTypeCollections[$name])) { |
|
140 | + return $this->entityTypeCollections[$name]; |
|
141 | + } |
|
142 | + throw new NotFound('Entity type "' . $name . '" not found."'); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Returns an array with all the child nodes |
|
147 | + * |
|
148 | + * @return \Sabre\DAV\INode[] |
|
149 | + */ |
|
150 | + public function getChildren() { |
|
151 | + $this->initCollections(); |
|
152 | + return $this->entityTypeCollections; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Checks if a child-node with the specified name exists |
|
157 | + * |
|
158 | + * @param string $name |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + public function childExists($name) { |
|
162 | + $this->initCollections(); |
|
163 | + return isset($this->entityTypeCollections[$name]); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Deleted the current node |
|
168 | + * |
|
169 | + * @throws Forbidden |
|
170 | + */ |
|
171 | + public function delete() { |
|
172 | + throw new Forbidden('Permission denied to delete this collection'); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Returns the name of the node. |
|
177 | + * |
|
178 | + * This is used to generate the url. |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function getName() { |
|
183 | + return $this->name; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Renames the node |
|
188 | + * |
|
189 | + * @param string $name The new name |
|
190 | + * @throws Forbidden |
|
191 | + */ |
|
192 | + public function setName($name) { |
|
193 | + throw new Forbidden('Permission denied to rename this collection'); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Returns the last modification time, as a unix timestamp |
|
198 | + * |
|
199 | + * @return int |
|
200 | + */ |
|
201 | + public function getLastModified() { |
|
202 | + return null; |
|
203 | + } |
|
204 | 204 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | foreach (['id', 'name'] as $property) { |
69 | 69 | $$property = trim($$property); |
70 | 70 | if (empty($$property) || !is_string($$property)) { |
71 | - throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
71 | + throw new \InvalidArgumentException('"'.$property.'" parameter must be non-empty string'); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | $this->id = $id; |
@@ -41,154 +41,154 @@ |
||
41 | 41 | * @package OCA\DAV\Comments |
42 | 42 | */ |
43 | 43 | class EntityCollection extends RootCollection implements IProperties { |
44 | - public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
44 | + public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker'; |
|
45 | 45 | |
46 | - /** @var string */ |
|
47 | - protected $id; |
|
46 | + /** @var string */ |
|
47 | + protected $id; |
|
48 | 48 | |
49 | - protected LoggerInterface $logger; |
|
49 | + protected LoggerInterface $logger; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $id |
|
53 | - * @param string $name |
|
54 | - * @param ICommentsManager $commentsManager |
|
55 | - * @param IUserManager $userManager |
|
56 | - * @param IUserSession $userSession |
|
57 | - * @param LoggerInterface $logger |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - $id, |
|
61 | - $name, |
|
62 | - ICommentsManager $commentsManager, |
|
63 | - IUserManager $userManager, |
|
64 | - IUserSession $userSession, |
|
65 | - LoggerInterface $logger |
|
66 | - ) { |
|
67 | - foreach (['id', 'name'] as $property) { |
|
68 | - $$property = trim($$property); |
|
69 | - if (empty($$property) || !is_string($$property)) { |
|
70 | - throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
71 | - } |
|
72 | - } |
|
73 | - $this->id = $id; |
|
74 | - $this->name = $name; |
|
75 | - $this->commentsManager = $commentsManager; |
|
76 | - $this->logger = $logger; |
|
77 | - $this->userManager = $userManager; |
|
78 | - $this->userSession = $userSession; |
|
79 | - } |
|
51 | + /** |
|
52 | + * @param string $id |
|
53 | + * @param string $name |
|
54 | + * @param ICommentsManager $commentsManager |
|
55 | + * @param IUserManager $userManager |
|
56 | + * @param IUserSession $userSession |
|
57 | + * @param LoggerInterface $logger |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + $id, |
|
61 | + $name, |
|
62 | + ICommentsManager $commentsManager, |
|
63 | + IUserManager $userManager, |
|
64 | + IUserSession $userSession, |
|
65 | + LoggerInterface $logger |
|
66 | + ) { |
|
67 | + foreach (['id', 'name'] as $property) { |
|
68 | + $$property = trim($$property); |
|
69 | + if (empty($$property) || !is_string($$property)) { |
|
70 | + throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string'); |
|
71 | + } |
|
72 | + } |
|
73 | + $this->id = $id; |
|
74 | + $this->name = $name; |
|
75 | + $this->commentsManager = $commentsManager; |
|
76 | + $this->logger = $logger; |
|
77 | + $this->userManager = $userManager; |
|
78 | + $this->userSession = $userSession; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * returns the ID of this entity |
|
83 | - * |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function getId() { |
|
87 | - return $this->id; |
|
88 | - } |
|
81 | + /** |
|
82 | + * returns the ID of this entity |
|
83 | + * |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function getId() { |
|
87 | + return $this->id; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Returns a specific child node, referenced by its name |
|
92 | - * |
|
93 | - * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
94 | - * exist. |
|
95 | - * |
|
96 | - * @param string $name |
|
97 | - * @return \Sabre\DAV\INode |
|
98 | - * @throws NotFound |
|
99 | - */ |
|
100 | - public function getChild($name) { |
|
101 | - try { |
|
102 | - $comment = $this->commentsManager->get($name); |
|
103 | - return new CommentNode( |
|
104 | - $this->commentsManager, |
|
105 | - $comment, |
|
106 | - $this->userManager, |
|
107 | - $this->userSession, |
|
108 | - $this->logger |
|
109 | - ); |
|
110 | - } catch (NotFoundException $e) { |
|
111 | - throw new NotFound(); |
|
112 | - } |
|
113 | - } |
|
90 | + /** |
|
91 | + * Returns a specific child node, referenced by its name |
|
92 | + * |
|
93 | + * This method must throw Sabre\DAV\Exception\NotFound if the node does not |
|
94 | + * exist. |
|
95 | + * |
|
96 | + * @param string $name |
|
97 | + * @return \Sabre\DAV\INode |
|
98 | + * @throws NotFound |
|
99 | + */ |
|
100 | + public function getChild($name) { |
|
101 | + try { |
|
102 | + $comment = $this->commentsManager->get($name); |
|
103 | + return new CommentNode( |
|
104 | + $this->commentsManager, |
|
105 | + $comment, |
|
106 | + $this->userManager, |
|
107 | + $this->userSession, |
|
108 | + $this->logger |
|
109 | + ); |
|
110 | + } catch (NotFoundException $e) { |
|
111 | + throw new NotFound(); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Returns an array with all the child nodes |
|
117 | - * |
|
118 | - * @return \Sabre\DAV\INode[] |
|
119 | - */ |
|
120 | - public function getChildren() { |
|
121 | - return $this->findChildren(); |
|
122 | - } |
|
115 | + /** |
|
116 | + * Returns an array with all the child nodes |
|
117 | + * |
|
118 | + * @return \Sabre\DAV\INode[] |
|
119 | + */ |
|
120 | + public function getChildren() { |
|
121 | + return $this->findChildren(); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Returns an array of comment nodes. Result can be influenced by offset, |
|
126 | - * limit and date time parameters. |
|
127 | - * |
|
128 | - * @param int $limit |
|
129 | - * @param int $offset |
|
130 | - * @param \DateTime|null $datetime |
|
131 | - * @return CommentNode[] |
|
132 | - */ |
|
133 | - public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) { |
|
134 | - $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime); |
|
135 | - $result = []; |
|
136 | - foreach ($comments as $comment) { |
|
137 | - $result[] = new CommentNode( |
|
138 | - $this->commentsManager, |
|
139 | - $comment, |
|
140 | - $this->userManager, |
|
141 | - $this->userSession, |
|
142 | - $this->logger |
|
143 | - ); |
|
144 | - } |
|
145 | - return $result; |
|
146 | - } |
|
124 | + /** |
|
125 | + * Returns an array of comment nodes. Result can be influenced by offset, |
|
126 | + * limit and date time parameters. |
|
127 | + * |
|
128 | + * @param int $limit |
|
129 | + * @param int $offset |
|
130 | + * @param \DateTime|null $datetime |
|
131 | + * @return CommentNode[] |
|
132 | + */ |
|
133 | + public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) { |
|
134 | + $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime); |
|
135 | + $result = []; |
|
136 | + foreach ($comments as $comment) { |
|
137 | + $result[] = new CommentNode( |
|
138 | + $this->commentsManager, |
|
139 | + $comment, |
|
140 | + $this->userManager, |
|
141 | + $this->userSession, |
|
142 | + $this->logger |
|
143 | + ); |
|
144 | + } |
|
145 | + return $result; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Checks if a child-node with the specified name exists |
|
150 | - * |
|
151 | - * @param string $name |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - public function childExists($name) { |
|
155 | - try { |
|
156 | - $this->commentsManager->get($name); |
|
157 | - return true; |
|
158 | - } catch (NotFoundException $e) { |
|
159 | - return false; |
|
160 | - } |
|
161 | - } |
|
148 | + /** |
|
149 | + * Checks if a child-node with the specified name exists |
|
150 | + * |
|
151 | + * @param string $name |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + public function childExists($name) { |
|
155 | + try { |
|
156 | + $this->commentsManager->get($name); |
|
157 | + return true; |
|
158 | + } catch (NotFoundException $e) { |
|
159 | + return false; |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Sets the read marker to the specified date for the logged in user |
|
165 | - * |
|
166 | - * @param \DateTime $value |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - public function setReadMarker($value) { |
|
170 | - $dateTime = new \DateTime($value); |
|
171 | - $user = $this->userSession->getUser(); |
|
172 | - $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user); |
|
173 | - return true; |
|
174 | - } |
|
163 | + /** |
|
164 | + * Sets the read marker to the specified date for the logged in user |
|
165 | + * |
|
166 | + * @param \DateTime $value |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function setReadMarker($value) { |
|
170 | + $dateTime = new \DateTime($value); |
|
171 | + $user = $this->userSession->getUser(); |
|
172 | + $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user); |
|
173 | + return true; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @inheritdoc |
|
178 | - */ |
|
179 | - public function propPatch(PropPatch $propPatch) { |
|
180 | - $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']); |
|
181 | - } |
|
176 | + /** |
|
177 | + * @inheritdoc |
|
178 | + */ |
|
179 | + public function propPatch(PropPatch $propPatch) { |
|
180 | + $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @inheritdoc |
|
185 | - */ |
|
186 | - public function getProperties($properties) { |
|
187 | - $marker = null; |
|
188 | - $user = $this->userSession->getUser(); |
|
189 | - if (!is_null($user)) { |
|
190 | - $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user); |
|
191 | - } |
|
192 | - return [self::PROPERTY_NAME_READ_MARKER => $marker]; |
|
193 | - } |
|
183 | + /** |
|
184 | + * @inheritdoc |
|
185 | + */ |
|
186 | + public function getProperties($properties) { |
|
187 | + $marker = null; |
|
188 | + $user = $this->userSession->getUser(); |
|
189 | + if (!is_null($user)) { |
|
190 | + $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user); |
|
191 | + } |
|
192 | + return [self::PROPERTY_NAME_READ_MARKER => $marker]; |
|
193 | + } |
|
194 | 194 | } |
@@ -77,7 +77,7 @@ |
||
77 | 77 | $path = array_pop($path); |
78 | 78 | |
79 | 79 | $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
80 | - $url = $request->getBaseUrl() . $newName; |
|
80 | + $url = $request->getBaseUrl().$newName; |
|
81 | 81 | $request->setUrl($url); |
82 | 82 | } |
83 | 83 | } |
@@ -35,51 +35,51 @@ |
||
35 | 35 | */ |
36 | 36 | class FilesDropPlugin extends ServerPlugin { |
37 | 37 | |
38 | - /** @var View */ |
|
39 | - private $view; |
|
38 | + /** @var View */ |
|
39 | + private $view; |
|
40 | 40 | |
41 | - /** @var bool */ |
|
42 | - private $enabled = false; |
|
41 | + /** @var bool */ |
|
42 | + private $enabled = false; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param View $view |
|
46 | - */ |
|
47 | - public function setView($view) { |
|
48 | - $this->view = $view; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param View $view |
|
46 | + */ |
|
47 | + public function setView($view) { |
|
48 | + $this->view = $view; |
|
49 | + } |
|
50 | 50 | |
51 | - public function enable() { |
|
52 | - $this->enabled = true; |
|
53 | - } |
|
51 | + public function enable() { |
|
52 | + $this->enabled = true; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * This initializes the plugin. |
|
58 | - * |
|
59 | - * @param \Sabre\DAV\Server $server Sabre server |
|
60 | - * |
|
61 | - * @return void |
|
62 | - * @throws MethodNotAllowed |
|
63 | - */ |
|
64 | - public function initialize(\Sabre\DAV\Server $server) { |
|
65 | - $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
66 | - $this->enabled = false; |
|
67 | - } |
|
56 | + /** |
|
57 | + * This initializes the plugin. |
|
58 | + * |
|
59 | + * @param \Sabre\DAV\Server $server Sabre server |
|
60 | + * |
|
61 | + * @return void |
|
62 | + * @throws MethodNotAllowed |
|
63 | + */ |
|
64 | + public function initialize(\Sabre\DAV\Server $server) { |
|
65 | + $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
66 | + $this->enabled = false; |
|
67 | + } |
|
68 | 68 | |
69 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
70 | - if (!$this->enabled) { |
|
71 | - return; |
|
72 | - } |
|
69 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
70 | + if (!$this->enabled) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - if ($request->getMethod() !== 'PUT') { |
|
75 | - throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
76 | - } |
|
74 | + if ($request->getMethod() !== 'PUT') { |
|
75 | + throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
76 | + } |
|
77 | 77 | |
78 | - $path = explode('/', $request->getPath()); |
|
79 | - $path = array_pop($path); |
|
78 | + $path = explode('/', $request->getPath()); |
|
79 | + $path = array_pop($path); |
|
80 | 80 | |
81 | - $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
82 | - $url = $request->getBaseUrl() . $newName; |
|
83 | - $request->setUrl($url); |
|
84 | - } |
|
81 | + $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
82 | + $url = $request->getBaseUrl() . $newName; |
|
83 | + $request->setUrl($url); |
|
84 | + } |
|
85 | 85 | } |
@@ -54,7 +54,7 @@ |
||
54 | 54 | $output->writeln('Syncing users ...'); |
55 | 55 | $progress = new ProgressBar($output); |
56 | 56 | $progress->start(); |
57 | - $this->syncService->syncInstance(function () use ($progress) { |
|
57 | + $this->syncService->syncInstance(function() use ($progress) { |
|
58 | 58 | $progress->advance(); |
59 | 59 | }); |
60 | 60 |
@@ -32,37 +32,37 @@ |
||
32 | 32 | |
33 | 33 | class SyncSystemAddressBook extends Command { |
34 | 34 | |
35 | - /** @var SyncService */ |
|
36 | - private $syncService; |
|
35 | + /** @var SyncService */ |
|
36 | + private $syncService; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param SyncService $syncService |
|
40 | - */ |
|
41 | - public function __construct(SyncService $syncService) { |
|
42 | - parent::__construct(); |
|
43 | - $this->syncService = $syncService; |
|
44 | - } |
|
38 | + /** |
|
39 | + * @param SyncService $syncService |
|
40 | + */ |
|
41 | + public function __construct(SyncService $syncService) { |
|
42 | + parent::__construct(); |
|
43 | + $this->syncService = $syncService; |
|
44 | + } |
|
45 | 45 | |
46 | - protected function configure() { |
|
47 | - $this |
|
48 | - ->setName('dav:sync-system-addressbook') |
|
49 | - ->setDescription('Synchronizes users to the system addressbook'); |
|
50 | - } |
|
46 | + protected function configure() { |
|
47 | + $this |
|
48 | + ->setName('dav:sync-system-addressbook') |
|
49 | + ->setDescription('Synchronizes users to the system addressbook'); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param InputInterface $input |
|
54 | - * @param OutputInterface $output |
|
55 | - */ |
|
56 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
57 | - $output->writeln('Syncing users ...'); |
|
58 | - $progress = new ProgressBar($output); |
|
59 | - $progress->start(); |
|
60 | - $this->syncService->syncInstance(function () use ($progress) { |
|
61 | - $progress->advance(); |
|
62 | - }); |
|
52 | + /** |
|
53 | + * @param InputInterface $input |
|
54 | + * @param OutputInterface $output |
|
55 | + */ |
|
56 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
57 | + $output->writeln('Syncing users ...'); |
|
58 | + $progress = new ProgressBar($output); |
|
59 | + $progress->start(); |
|
60 | + $this->syncService->syncInstance(function () use ($progress) { |
|
61 | + $progress->advance(); |
|
62 | + }); |
|
63 | 63 | |
64 | - $progress->finish(); |
|
65 | - $output->writeln(''); |
|
66 | - return 0; |
|
67 | - } |
|
64 | + $progress->finish(); |
|
65 | + $output->writeln(''); |
|
66 | + return 0; |
|
67 | + } |
|
68 | 68 | } |
@@ -58,7 +58,7 @@ |
||
58 | 58 | public function getChild($name) { |
59 | 59 | $elements = pathinfo($name); |
60 | 60 | $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
61 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
61 | + $size = (int) (isset($elements['filename']) ? $elements['filename'] : '64'); |
|
62 | 62 | if (!in_array($ext, ['jpeg', 'png'], true)) { |
63 | 63 | throw new MethodNotAllowed('File format not allowed'); |
64 | 64 | } |
@@ -34,87 +34,87 @@ |
||
34 | 34 | |
35 | 35 | class AvatarHome implements ICollection { |
36 | 36 | |
37 | - /** @var array */ |
|
38 | - private $principalInfo; |
|
39 | - /** @var IAvatarManager */ |
|
40 | - private $avatarManager; |
|
37 | + /** @var array */ |
|
38 | + private $principalInfo; |
|
39 | + /** @var IAvatarManager */ |
|
40 | + private $avatarManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * AvatarHome constructor. |
|
44 | - * |
|
45 | - * @param array $principalInfo |
|
46 | - * @param IAvatarManager $avatarManager |
|
47 | - */ |
|
48 | - public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
49 | - $this->principalInfo = $principalInfo; |
|
50 | - $this->avatarManager = $avatarManager; |
|
51 | - } |
|
42 | + /** |
|
43 | + * AvatarHome constructor. |
|
44 | + * |
|
45 | + * @param array $principalInfo |
|
46 | + * @param IAvatarManager $avatarManager |
|
47 | + */ |
|
48 | + public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
49 | + $this->principalInfo = $principalInfo; |
|
50 | + $this->avatarManager = $avatarManager; |
|
51 | + } |
|
52 | 52 | |
53 | - public function createFile($name, $data = null) { |
|
54 | - throw new Forbidden('Permission denied to create a file'); |
|
55 | - } |
|
53 | + public function createFile($name, $data = null) { |
|
54 | + throw new Forbidden('Permission denied to create a file'); |
|
55 | + } |
|
56 | 56 | |
57 | - public function createDirectory($name) { |
|
58 | - throw new Forbidden('Permission denied to create a folder'); |
|
59 | - } |
|
57 | + public function createDirectory($name) { |
|
58 | + throw new Forbidden('Permission denied to create a folder'); |
|
59 | + } |
|
60 | 60 | |
61 | - public function getChild($name) { |
|
62 | - $elements = pathinfo($name); |
|
63 | - $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
64 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
65 | - if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
66 | - throw new MethodNotAllowed('File format not allowed'); |
|
67 | - } |
|
68 | - if ($size <= 0 || $size > 1024) { |
|
69 | - throw new MethodNotAllowed('Invalid image size'); |
|
70 | - } |
|
71 | - $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
72 | - if (!$avatar->exists()) { |
|
73 | - throw new NotFound(); |
|
74 | - } |
|
75 | - return new AvatarNode($size, $ext, $avatar); |
|
76 | - } |
|
61 | + public function getChild($name) { |
|
62 | + $elements = pathinfo($name); |
|
63 | + $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
64 | + $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
65 | + if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
66 | + throw new MethodNotAllowed('File format not allowed'); |
|
67 | + } |
|
68 | + if ($size <= 0 || $size > 1024) { |
|
69 | + throw new MethodNotAllowed('Invalid image size'); |
|
70 | + } |
|
71 | + $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
72 | + if (!$avatar->exists()) { |
|
73 | + throw new NotFound(); |
|
74 | + } |
|
75 | + return new AvatarNode($size, $ext, $avatar); |
|
76 | + } |
|
77 | 77 | |
78 | - public function getChildren() { |
|
79 | - try { |
|
80 | - return [ |
|
81 | - $this->getChild('96.jpeg') |
|
82 | - ]; |
|
83 | - } catch (NotFound $exception) { |
|
84 | - return []; |
|
85 | - } |
|
86 | - } |
|
78 | + public function getChildren() { |
|
79 | + try { |
|
80 | + return [ |
|
81 | + $this->getChild('96.jpeg') |
|
82 | + ]; |
|
83 | + } catch (NotFound $exception) { |
|
84 | + return []; |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - public function childExists($name) { |
|
89 | - try { |
|
90 | - $ret = $this->getChild($name); |
|
91 | - return $ret !== null; |
|
92 | - } catch (NotFound $ex) { |
|
93 | - return false; |
|
94 | - } catch (MethodNotAllowed $ex) { |
|
95 | - return false; |
|
96 | - } |
|
97 | - } |
|
88 | + public function childExists($name) { |
|
89 | + try { |
|
90 | + $ret = $this->getChild($name); |
|
91 | + return $ret !== null; |
|
92 | + } catch (NotFound $ex) { |
|
93 | + return false; |
|
94 | + } catch (MethodNotAllowed $ex) { |
|
95 | + return false; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - public function delete() { |
|
100 | - throw new Forbidden('Permission denied to delete this folder'); |
|
101 | - } |
|
99 | + public function delete() { |
|
100 | + throw new Forbidden('Permission denied to delete this folder'); |
|
101 | + } |
|
102 | 102 | |
103 | - public function getName() { |
|
104 | - [,$name] = Uri\split($this->principalInfo['uri']); |
|
105 | - return $name; |
|
106 | - } |
|
103 | + public function getName() { |
|
104 | + [,$name] = Uri\split($this->principalInfo['uri']); |
|
105 | + return $name; |
|
106 | + } |
|
107 | 107 | |
108 | - public function setName($name) { |
|
109 | - throw new Forbidden('Permission denied to rename this folder'); |
|
110 | - } |
|
108 | + public function setName($name) { |
|
109 | + throw new Forbidden('Permission denied to rename this folder'); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Returns the last modification time, as a unix timestamp |
|
114 | - * |
|
115 | - * @return int|null |
|
116 | - */ |
|
117 | - public function getLastModified() { |
|
118 | - return null; |
|
119 | - } |
|
112 | + /** |
|
113 | + * Returns the last modification time, as a unix timestamp |
|
114 | + * |
|
115 | + * @return int|null |
|
116 | + */ |
|
117 | + public function getLastModified() { |
|
118 | + return null; |
|
119 | + } |
|
120 | 120 | } |