settings = $settings; $this->app = $app; } /** * {@inheritdoc} */ public function data(ServerRequestInterface $request, Document $document) { $this->assertAdmin($request->getAttribute('actor')); $file = Arr::get($request->getUploadedFiles(), 'logo'); $tmpFile = tempnam($this->app->storagePath().'/tmp', 'logo'); $file->moveTo($tmpFile); $manager = new ImageManager; $encodedImage = $manager->make($tmpFile)->heighten(60, function ($constraint) { $constraint->upsize(); })->encode('png'); file_put_contents($tmpFile, $encodedImage); $mount = new MountManager([ 'source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($this->app->publicPath().'/assets')), ]); if (($path = $this->settings->get('logo_path')) && $mount->has($file = "target://$path")) { $mount->delete($file); } $uploadName = 'logo-'.Str::lower(Str::random(8)).'.png'; $mount->move('source://'.pathinfo($tmpFile, PATHINFO_BASENAME), "target://$uploadName"); $this->settings->set('logo_path', $uploadName); return parent::data($request, $document); } }