/** * Execute the console command. * * @return void */ public function fire() { $this->registerClassAutoloadExceptions(); $bindings = array(); foreach ($this->getAbstracts() as $abstract) { // Validator and seeder cause problems if (in_array($abstract, ['validator', 'seeder'])) { continue; } try { $concrete = $this->laravel->make($abstract); if (is_object($concrete)) { $class = get_class($concrete); if (strpos($class, 'Proxy_') === 0) { $class = get_parent_class($class); } $bindings[$abstract] = $class; } } catch (\Exception $e) { if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $this->comment("Cannot make '{$abstract}': " . $e->getMessage()); } } } $content = $this->view->make('ide-helper::meta', ['bindings' => $bindings, 'methods' => $this->methods])->render(); $filename = $this->option('filename'); $written = $this->files->put($filename, $content); if ($written !== false) { $this->info("A new meta file was written to {$filename}"); } else { $this->error("The meta file could not be created at {$filename}"); } }
/** * {@inheritdoc} */ public function writeCss($uri, $css) { $ok = $this->files->put($this->storage . '/' . urlencode($uri) . '.css', $css); if (!$ok) { throw new CssWriteException(sprintf('Unable to write the critical-path CSS for the URI [%s] to [%s].', $uri, $css)); } return $ok; }
/** * Return the directory where all files of the given media are stored. * * @param \Spatie\MediaLibrary\Media $media * * @return string */ public function getMediaDirectory(Media $media) { $this->disk->put('.gitignore', Gitignore::getContents()); $directory = $media->id; $this->disk->makeDirectory($directory); $this->disk->makeDirectory($directory . '/conversions'); return $directory; }
/** * @param UploadedFile $image * @param string $visibility * @return $this */ public function store(UploadedFile $image, $visibility = Filesystem::VISIBILITY_PUBLIC) { $info = getimagesize($image->getPathname()); $this->width = $info[0]; $this->height = $info[1]; $this->cloud->put($this->path, file_get_contents($image), $visibility); return $this; }
/** * Write the PDF * * @param string $template * @param array $data * @return string */ public function write($template, array $data) { $filename = sprintf('export-%s.pdf', time()); $this->storage->put($filename, view($template, $data)); $path = storage_path(sprintf('app/%s', $filename)); $phantom = base_path('bin/phantom/phantomjs'); $config = base_path('bin/phantom/config.js'); $command = sprintf('%s —ssl-protocol=any %s %s', $phantom, $config, $path); $process = (new Process($command, __DIR__))->setTimeout(10)->mustRun(); return $path; }
/** * @return string */ public function make() : string { $fields = array_keys(Entry::getFieldsAndTypes()); $types = Entry::getFieldsAndTypes(); $configuration = ['date-format' => 'Y-m-d', 'has-headers' => true, 'map' => [], 'roles' => [], 'mapped' => [], 'specifix' => []]; foreach ($fields as $field) { $configuration['roles'][] = $types[$field]; } $file = $this->job->key . '-configuration.json'; $this->exportDisk->put($file, json_encode($configuration, JSON_PRETTY_PRINT)); return $file; }
/** * Upload Image * * @param UploadedFile $file Uploaded File * @param string $folder String Folder * @param string $name String Name * @param array $options Array Options * @param bool $override Boolean Over Ride * * @return bool */ public function uploadImage(UploadedFile $file, $folder = null, $name = null, array $options = array(), $override = false) { $pathImage = $file->getPathname(); $data = $this->parseFile($file, $folder, $name, $override); if ($this->imagineFactory) { $width = isset($options['width']) ? intval($options['width']) : 0; $height = isset($options['height']) ? intval($options['height']) : 0; $scale = isset($options['scale']) ? (bool) $options['scale'] : true; $opacity = isset($options['opacity']) ? (double) $options['opacity'] : null; $watermark = isset($options['watermark']) ? $options['watermark'] : null; $quality = isset($options['quality']) ? intval($options['quality']) : 85; // Quality Deufault: 85; $imagine = $this->imagineFactory->make($pathImage); $imagine->resize($width, $height, !$scale); $imagine->opacity($opacity); $imagine->watermark($watermark); $content = $imagine->encode($data['extension'], $quality)->getEncoded(); } else { $content = file_get_contents($file); } $success = $this->storage->put($data['filename'], $content); if ($success) { return $data; } return false; }
/** * create filtered image * * @param string $hash * @param string $filename * @param string[]|string $filters * @return void */ public function create($hash, $filename, $filters) { $filteredImages = []; $imageContent = $this->filesystem->get(config('image-service.path') . '/original/' . $hash . '/' . $filename); $image = $this->imageManager->make($imageContent); // if just one filter as string if (is_string($filters)) { $filters = [$filters]; } foreach ($filters as $filterName) { $filterData = config('image-service.filters.' . $filterName); /** @var Filter $filter */ $filter = app('image.filters.' . $filterData['type']); $filteredImage = $filter->process($image, isset($filterData['options']) ? $filterData['options'] : []); // cache if needed if (isset($filterData['cache']) && $filterData['cache'] === true) { $filterPath = config('image-service.path') . '/' . $filterName . '/' . $hash; $this->filesystem->makeDirectory($filterPath); $this->filesystem->put($filterPath . '/' . $filename, $filteredImage->encode(null, 100)); } // save to return it $filteredImages[$filterName] = $filteredImage; } return $filteredImages; }
/** * * @param UploadedFile $file * @param Model $model * * @return Attachment */ protected function processFile(UploadedFile $file, Model $model) : Attachment { $validation = $this->validateUpload($file, $model); if ($validation === false) { return new Attachment(); } $attachment = new Attachment(); // create Attachment object. $attachment->user()->associate(auth()->user()); $attachment->attachable()->associate($model); $attachment->md5 = md5_file($file->getRealPath()); $attachment->filename = $file->getClientOriginalName(); $attachment->mime = $file->getMimeType(); $attachment->size = $file->getSize(); $attachment->uploaded = 0; $attachment->save(); $fileObject = $file->openFile('r'); $fileObject->rewind(); $content = $fileObject->fread($file->getSize()); $encrypted = Crypt::encrypt($content); // store it: $this->uploadDisk->put($attachment->fileName(), $encrypted); $attachment->uploaded = 1; // update attachment $attachment->save(); $name = e($file->getClientOriginalName()); // add message: $msg = (string) trans('validation.file_attached', ['name' => $name]); $this->messages->add('attachments', $msg); // return it. return $attachment; }
/** * 文件上传处理 * * @param \Illuminate\Http\UploadedFile $file * @param array $configs * @return array */ public function handle($file, $configs = []) { if (is_array($file)) { $jsonFormatDataArr = []; foreach ($file as $uploadedFile) { $jsonFormatDataArr[] = $this->handle($uploadedFile, $configs); } return $jsonFormatDataArr; } else { try { $configs = array_merge($this->configs, $configs); if (is_null($file)) { throw new UploadFileException('Upload file can not be null!'); } if (!$this->isUploadedFile($file)) { throw new UploadFileException('Upload file is not a \\Illuminate\\Http\\UploadedFile instance!'); } $jsonFormatData = $this->getJosnFormatData($file); if (!$this->isValidUploadFileSize($jsonFormatData['size'], $configs['max_size'])) { throw new UploadFileException('The upload file may not be greater than ' . $this->size2mb($configs['max_size']) . '.'); } if (!$this->isValidUploadFileExtension($jsonFormatData['extension'], $configs['extensions'])) { throw new UploadFileException("The upload file suffix may only " . implode(', ', $configs['extensions']) . '.'); } if (!$this->isValidUploadFileMimeType($jsonFormatData['mime_type'], $configs['mime_types'])) { throw new UploadFileException('The upload file mime-type may only ' . implode(', ', $configs['mime_types']) . '.'); } $jsonFormatData['savename'] = $this->makeFilename($file); $jsonFormatData['savepath'] = $this->getSavepath($configs['directory'], $configs['timestamps']); if (empty($jsonFormatData['savepath'])) { $jsonFormatData['fullpath'] = $jsonFormatData['savename']; } else { $jsonFormatData['fullpath'] = "{$jsonFormatData['savepath']}/{$jsonFormatData['savename']}"; } $result = $this->filesystem->put($jsonFormatData['fullpath'], file_get_contents($file->getRealPath())); if (!$result) { throw new UploadFileException('Unknown reason cause upload failed!'); } $jsonFormatData['status'] = 'success'; } catch (UploadFileException $e) { $jsonFormatData['status'] = 'failure'; $jsonFormatData['error'] = $e->getMessage(); } return $jsonFormatData; } }
/** * @param Attachment $attachment * @return void */ public function addAttachment(Attachment $attachment) { /** @var \League\Flysystem\Adapter\AbstractAdapter $adapter */ $adapter = $this->storage->getAdapter(); $attachmentPath = 'attachments' . DIRECTORY_SEPARATOR . $attachment->getName(); $this->storage->put($attachmentPath, $attachment->getContent()); $this->attachments[$attachmentPath] = $adapter->getPathPrefix() . $attachmentPath; }
/** * Helper for small image uploading * * @param array $data * @param $url * @return string */ protected function uploadSmallImage(array $data, $url) { $name = sprintf('post_%s.jpg', $data['slug']); $date = sprintf('%s/%s', date('Y'), date('m')); $format = 'uploads/posts/%s/' . $date . '/'; $smallDir = sprintf($format, 'small'); $this->ensureDirectoryExistence($smallDir); $small = $this->imageManager->make($url)->fit(261, 126); $this->filesystem->put($smallDir . $name, (string) $small->encode()); return $smallDir . $name; }
/** * Execute the console command. * * @return void */ public function fire() { $bindings = array(); foreach ($this->getAbstracts() as $abstract) { try { $concrete = $this->laravel->make($abstract); if (is_object($concrete)) { $bindings[$abstract] = get_class($concrete); } } catch (\Exception $e) { $this->error("Cannot make {$abstract}: " . $e->getMessage()); } } $content = $this->view->make('ide-helper::meta', ['bindings' => $bindings, 'methods' => $this->methods])->render(); $filename = $this->option('filename'); $written = $this->files->put($filename, $content); if ($written !== false) { $this->info("A new meta file was written to {$filename}"); } else { $this->error("The meta file could not be created at {$filename}"); } }
/** * Upload a file. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\RedirectResponse */ public function addFile(Request $request) { $maxSize = $this->config->get('media.max_file_size', 3); $validator = $this->getValidationFactory()->make($request->all(), ['file' => 'required|mimes:' . $this->getAcceptedFiles() . '|max:' . $maxSize * 1024]); if ($validator->fails()) { return response($validator->getMessageBag()->get('file')[0], 500); } $filename = trim($request->file('file')->getClientOriginalName()); if ($this->storage->exists($request->input('current_directory') . '/' . $filename)) { return response($filename . " already exists.", 500); } $this->storage->put($request->input('current_directory') . '/' . $filename, file_get_contents($request->file('file'))); return redirect()->back(); }
/** * @param string $entry */ private function saveOldImportFile(string $entry) { $content = ''; try { $content = Crypt::decrypt($this->uploadDisk->get($entry)); } catch (DecryptException $e) { Log::error('Could not decrypt old CSV import file ' . $entry . '. Skipped because ' . $e->getMessage()); } if (strlen($content) > 0) { // add to export disk. $date = $this->getOriginalUploadDate($entry); $file = $this->job->key . '-Old import dated ' . $date . '.csv'; $this->exportDisk->put($file, $content); $this->getFiles()->push($file); } }
public function syncRef($ref, $type, Closure $progress = null) { $this->fire('git.syncer.start', [$ref, $type]); $owner = $this->setting('owner'); $repo = $this->setting('repository'); $docPath = $this->setting('sync.paths.docs'); $menuPath = $this->setting('sync.paths.menu'); $indexPath = $this->setting('sync.paths.index'); $remote = $this->client($this->setting('remote')); $rfs = $remote->getFilesystem($repo, $owner, $ref); $files = $rfs->allFiles($this->setting('sync.paths.docs')); if (!$rfs->exists($indexPath)) { return $this->log('error', 'syncRef could not find the index file', [$indexPath]); } if (!$rfs->exists($menuPath)) { return $this->log('error', 'syncRef could not find the menu file', [$indexPath]); } $destinationDir = $this->project->path($ref); $menuContent = $rfs->get($this->setting('sync.paths.menu')); //#base64_decode($menu[ 'content' ]); $menuArray = Yaml::parse($menuContent); $unfilteredPages = []; $this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages); $this->ensureDirectory($destinationDir); $files = $rfs->allFiles($this->setting('sync.paths.docs')); $total = count($files); $syncer = $this; foreach ($files as $current => $file) { $localPath = Path::makeRelative($file, $this->setting('sync.paths.docs')); if ($progress instanceof Closure) { #$file = new \SplFileInfo(path_join($this->project->getPath(), $destinationDir, $localPath)); $this->project->getContainer()->call($progress, compact('current', 'total', 'file', 'files', 'syncer')); } $localPath = Path::join($destinationDir, $localPath); $dir = Path::getDirectory($localPath); $this->ensureDirectory($dir); $this->files->put($localPath, $rfs->get($file)); } // index.md resolving $indexFile = $rfs->get($this->setting('sync.paths.index')); $this->files->put(Path::join($destinationDir, 'index.md'), $indexFile); if ($type === 'branch') { $branch = $remote->getBranch($this->setting('repository'), $ref, $this->setting('owner')); $this->cache->forever(md5($this->project->getName() . $branch['name']), $branch['sha']); } $this->fire('git.syncer.finish', [$ref, $type]); }
/** * @param Attachment $attachment * * @return bool */ private function exportAttachment(Attachment $attachment) : bool { $file = $attachment->fileName(); if ($this->uploadDisk->exists($file)) { try { $decrypted = Crypt::decrypt($this->uploadDisk->get($file)); $exportFile = $this->exportFileName($attachment); $this->exportDisk->put($exportFile, $decrypted); $this->getFiles()->push($exportFile); // explain: $this->explain($attachment); } catch (DecryptException $e) { Log::error('Catchable error: could not decrypt attachment #' . $attachment->id . ' because: ' . $e->getMessage()); } } return true; }
public function syncRef($ref, $type) { $this->project->getFactory()->log('info', 'codex.hooks.git.syncer.sync.start', compact('ref', 'type')); $this->runHook('git:syncer:start', [$this, $ref, $type]); $owner = $this->setting('owner'); $repo = $this->setting('repository'); $docPath = $this->setting('sync.paths.docs'); $indexPath = $this->setting('sync.paths.docs'); $remote = $this->client($this->setting('remote')); $rfs = $remote->getFilesystem($repo, $owner, $ref); $files = $rfs->allFiles($this->setting('sync.paths.docs')); $indexExists = $rfs->exists(Path::join($this->setting('sync.paths.docs'), 'index.md')); $menuExists = $rfs->exists(Path::join($this->setting('sync.paths.docs'), 'menu.yml')); $a = 'b'; if (!$indexExists || !$menuExists) { return; } $destinationDir = Path::join($this->project->getPath(), $ref); $menuContent = $rfs->get($this->setting('sync.paths.menu')); //#base64_decode($menu[ 'content' ]); $menuArray = Yaml::parse($menuContent); $unfilteredPages = []; $this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages); $this->ensureDirectory($destinationDir); foreach ($rfs->allFiles($this->setting('sync.paths.docs')) as $path) { $localPath = Path::makeRelative($path, $this->setting('sync.paths.docs')); $localPath = Path::join($destinationDir, $localPath); $dir = Path::getDirectory($localPath); $this->ensureDirectory($dir); $this->files->put($localPath, $rfs->get($path)); } if ($type === 'branch') { $branch = $remote->getBranch($this->setting('repository'), $ref, $this->setting('owner')); $this->cache->forever(md5($this->project->getName() . $branch['name']), $branch['sha']); } $this->runHook('git:syncer:done', [$this, $ref, $type]); $this->project->getFactory()->log('info', 'codex.hooks.git.syncer.sync.end', compact('ref', 'type')); }
/** * Uploads and attaches files for the current relation. * * @param Filesystem $filesystem * * @return bool|array */ public function handle(Filesystem $filesystem) { $files = $this->request->file('files'); if (is_array($files)) { $uploaded = []; foreach ($files as $file) { // Double check that we have an uploaded file instance. if ($file instanceof UploadedFile) { // Generates the unique file name. $name = implode('.', [uuid(), $file->getClientOriginalExtension()]); // Generates the complete storage path. $path = implode(DIRECTORY_SEPARATOR, [$this->path, $name]); // Try and move the uploaded file into storage. if ($filesystem->put($path, file_get_contents($file->getRealPath()))) { // Successfully moved uploaded file, create the record. $attributes = ['user_id' => auth()->id(), 'name' => $file->getClientOriginalName(), 'file_name' => $name, 'file_path' => $path]; $uploaded[] = $this->relation->create($attributes); } } } return $uploaded; } return false; }
/** * @param $fs Filesystem * @param $scrapers Collection **/ protected function processChunk(Filesystem $fs, Collection $scrapers) { $lastJob = 0; if ($fs->exists('lastScraperRun')) { $lastJob = $fs->get('lastScraperRun'); } $scrapers->slice($lastJob, self::JOBS_PER_CALL); $this->scheduleScrapers($scrapers); $nextJob = 0; if ($lastJob + self::JOBS_PER_CALL > $scrapers->count()) { $nextJob = $lastJob + self::JOBS_PER_CALL; } $fs->put('lastScraperRun', $nextJob); }
/** * Write an ignore-file on the given disk in the given directory. * * @param \Illuminate\Contracts\Filesystem\Filesystem $disk * @param string $dumpDirectory */ protected function writeIgnoreFile($disk, $dumpDirectory) { $gitIgnoreContents = '*' . PHP_EOL . '!.gitignore'; $disk->put($dumpDirectory . '/.gitignore', $gitIgnoreContents); }
/** * Write the contents of a file. * * @param string $path * @param string|resource $contents * @param string $visibility * * @return bool */ public function put($path, $contents, $visibility = null) { $path = $this->getPathPrefix($path); return $this->drive->put($path, $contents, $visibility); }
/** * @param $path * @param $contents * @return bool|mixed */ public function put($path, $contents) { return $this->storage->put($path, $contents); }
/** * Save current custom website config to file * * @return void */ public function save() { $this->storage->put($this->config . ".php", "<?php\n return " . var_export(Config::get("website"), true) . ";"); }
public function syncRef($ref, $type) { $content = new GitSyncContent($this->setting('owner'), $this->setting('repository'), $this->github); $hasDocs = $content->exists($this->setting('sync.paths.docs'), $ref); if (!$hasDocs) { return; } $destinationDir = Path::join($this->project->getPath(), $ref); $menu = $content->show($this->setting('sync.paths.menu'), $ref); $menuContent = base64_decode($menu['content']); $menuArray = Yaml::parse($menuContent); $unfilteredPages = []; $this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages); $filteredPages = []; # filter out pages that link to external sites foreach ($unfilteredPages as $page) { if (Str::startsWith($page, 'http', true) || Str::startsWith($page, '//', true) || Str::startsWith($page, 'git', true)) { continue; } if (!in_array($page, $filteredPages, true)) { $filteredPages[] = $page; } } # get all pages their content and save to local foreach ($filteredPages as $pagePath) { $path = Path::join($this->setting('sync.paths.docs'), $pagePath . '.md'); # check if page exists on remote $exists = $content->exists($path, $ref); if (!$exists) { continue; } # the raw github page content response $pageRaw = $content->show('/' . $path, $ref); # transform remote directory path to local directory path $dir = Str::remove($pageRaw['path'], $this->setting('sync.paths.docs')); $dir = Str::remove($dir, $pageRaw['name']); $dir = Path::canonicalize(Path::join($destinationDir, $dir)); if (!$this->files->exists($dir)) { $this->files->makeDirectory($dir); } # raw github page to utf8 and save it to local $this->files->put(Path::join($dir, $pageRaw['name']), base64_decode($pageRaw['content'])); } # save the menu to local $this->files->put(Path::join($destinationDir, 'menu.yml'), $menuContent); # if enabled, Get phpdoc structure and save it if ($this->setting('phpdoc')) { $hasStructure = $content->exists($this->setting('paths.phpdoc'), $ref); if ($hasStructure) { $structure = $content->show($this->setting('paths.phpdoc'), $ref); $structureXml = base64_decode($structure['content']); $destination = Path::join($destinationDir, 'structure.xml'); $destinationDir = Path::getDirectory($destination); if (!$this->files->exists($destinationDir)) { $this->files->makeDirectory($destinationDir); } $this->files->put($destination, $structureXml); } } # set cache sha for branches, not for tags (obviously) if ($type === 'branch') { $branchData = $this->github->repositories()->branches($this->setting('owner'), $this->setting('repository'), $ref); $this->cache->forever(md5($this->project->getName() . $branchData['name']), $branchData['commit']['sha']); } }
public function createFile(array $data) { $project = $this->repository->skipPresenter()->find($data['project_id']); $projectFile = $project->files()->create($data); $this->storage->put($projectFile->name . "." . $data['extension'], $this->filesystem->get($data['file'])); }
/** * @inheritdoc */ public function saveFile($path, $contents, array $options) { $visibility = array_get($options, 'visibility'); return $this->filesystem->put($this->directory . '/' . $path, $contents, $visibility); }
public function getLocal(Filesystem $filesystem) { $filesystem->put('test.txt', 'I am using local'); return 'done'; }