container = $container; } /** * @param $name * @return mixed|null * @throws DependencyException * @throws NotFoundException */ public function __get($name) { if ($this->container->has($name)) { return $this->container->get($name); } return null; } /** * @param $id * @return int */ protected function getUsedSpaceByUser($id): int { $medias = $this->database->query('SELECT `uploads`.`storage_path` FROM `uploads` WHERE `user_id` = ?', $id); $totalSize = 0; $filesystem = $this->storage; foreach ($medias as $media) { try { $totalSize += $filesystem->getSize($media->storage_path); } catch (FileNotFoundException $e) { $this->logger->error('Error calculating file size', ['exception' => $e]); } } return $totalSize; } /** * @param Request $request * @param $id * @param bool $authorize * @return mixed * @throws HttpNotFoundException * @throws HttpUnauthorizedException */ protected function getUser(Request $request, $id, $authorize = false) { $user = $this->database->query('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', $id)->fetch(); if (!$user) { throw new HttpNotFoundException($request); } if ($authorize && $user->id !== $this->session->get('user_id') && !$this->session->get('admin', false)) { throw new HttpUnauthorizedException($request); } return $user; } }