name = $name->name(); $this->path = $name->path(); $this->remote = $name->isRemote(); return; } if (is_null($remote)) { $remote = Str::startsWith($path, ['http://', 'https://', '://']); } $this->name = $name; $this->path = $path; $this->remote = $remote; } /** * Make a remote URL. * * @param string $path * @return static */ public static function remote($path) { return new static(md5($path), $path, true); } /** * Get asset name. * * @return string */ public function name() { return $this->name; } /** * Get asset path. * * @return string|null */ public function path() { return $this->path; } /** * Determine if URL is remote. * * @return bool */ public function isRemote() { return $this->remote; } /** * Create an HTTP response that represents the object. * * @param \Illuminate\Http\Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function toResponse($request) { abort_if($this->isRemote() || is_null($this->path), 404); return response( file_get_contents($this->path), 200, $this->toResponseHeaders(), )->setLastModified(DateTime::createFromFormat('U', (string) filemtime($this->path))); } /** * Get the Asset URL. * * @return string */ abstract public function url(); /** * Get response headers. * * @return array */ abstract public function toResponseHeaders(); }