upload($newFilepath); @unlink($newFilepath); } else { $url = $this->upload($filepath); @unlink($filepath); } return $this->trimBaseUrl($url); } public function getImageUrl(string $location): string { return sprintf('%s/%s', trim($this->getBaseUrl(), '/'), trim($location, '/')); } protected function trimBaseUrl(string $url): string { $baseUrl = trim($this->getBaseUrl(), '/') . "/"; if (str_starts_with($url, $baseUrl)) { return substr($url, strlen($baseUrl)); } return $url; } public static function getDriver(string $name = null): Storage { $driver = $name ?: get_setting("image_hosting.driver"); if (isset(self::$drivers[$driver])) { return self::$drivers[$driver]; } $result = null; if ($driver == self::DRIVER_CHEVERETO) { $result = new Chevereto(); } else if ($driver == self::DRIVER_LSKY) { $result = new Lsky(); } else if ($driver == self::DRIVER_LOCAL) { $result = new Local(); } if ($result) { return self::$drivers[$driver] = $result; } throw new \Exception("Unsupported driver: $driver"); } }