/**
  * Get the decoded contents from the main composer.json file
  * @return object
  */
 private function getComposerFile()
 {
     $composerFile = $this->cache->remember('app.version', 1440, function () {
         return $this->filesystem->get('composer.json');
     });
     return json_decode($composerFile);
 }
 /**
  * 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}");
     }
 }
Esempio n. 3
0
 public function contribute(Filesystem $fs)
 {
     $markdown = $fs->get('providers/CONTRIBUTING.md');
     $markdown = preg_replace('/^.+\\n/', '', $markdown);
     $html = \Parsedown::instance()->parse($markdown);
     return view('contribute', compact('html'));
 }
Esempio n. 4
0
 /**
  * @param NewImageEvent $event
  */
 private function transferImageFiles(NewImageEvent $event)
 {
     $preProcessed = $this->imagePreProcessor->preProcess($event->image());
     /** @var ImagickContract $imagick */
     foreach ($preProcessed as $imagick) {
         $this->publicFilesystem->getDriver()->put("image/{$imagick->getFilename()}", $imagick->getImageBlob(), self::fileConfig());
     }
 }
 /**
  * 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;
 }
Esempio n. 6
0
 /**
  * Get the exact installed version for the specified package.
  *
  * @param string $packageName
  *
  * @return string mixed
  */
 public function getPackageInfo($packageName)
 {
     $composerLock = json_decode($this->finder->get('composer.lock'));
     foreach ($composerLock->packages as $package) {
         if ($package->name == $packageName) {
             return $package;
         }
     }
 }
Esempio n. 7
0
 public function allLinks($from)
 {
     $files = $this->filesystem->allFiles($this->getBaseDir() . DIRECTORY_SEPARATOR . $from);
     $links = [];
     foreach ($files as $key => $file) {
         $links[$key] = url(env('LOCAL_BASE_DIR') . DIRECTORY_SEPARATOR . $file);
         $files[$key] = $this->filesystem->getDriver()->getAdapter()->getPathPrefix() . $files[$key];
     }
     return ['files' => $files, 'links' => $links];
 }
Esempio n. 8
0
 /**
  * Write messages to build log.
  *
  * @param  \KevinDierkx\Muse\Events\Console\Satis\WriteEventInterface  $event
  * @return bool
  */
 protected function writeToLog(WriteEventInterface $event)
 {
     $buildFile = 'build/build-' . $event->getBuildAt()->format('YmdHis') . '.log';
     if (!$event->getNewline()) {
         return false;
     }
     if (is_array($messages = $event->getMessages())) {
         return $this->storage->append($buildFile, implode(PHP_EOL, $event->getMessages()));
     }
     return $this->storage->append($buildFile, $messages);
 }
Esempio n. 9
0
 /**
  * Deletes the current attachment as well as the file.
  *
  * @param Filesystem $filesystem
  *
  * @throws \Exception
  *
  * @return bool
  */
 public function handle(Filesystem $filesystem)
 {
     try {
         if ($filesystem->delete($this->attachment->getStorageFilePath())) {
             return $this->attachment->delete();
         }
     } catch (FileNotFoundException $e) {
         //
     }
     return false;
 }
Esempio n. 10
0
 /**
  * Get the hydrated models.
  *
  * @param  array  $files
  * @return \Illuminate\Support\Collection
  */
 protected function getModels(array $files)
 {
     $collection = new Collection();
     foreach ($files as $path) {
         if (strpos($path, 'build-') !== false) {
             $contents = $this->storage->get($path);
             $collection->push($this->createModel(['path' => $path]));
         }
     }
     return $collection;
 }
Esempio n. 11
0
 /**
  * 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;
 }
Esempio n. 12
0
 /**
  * @param  \Codex\Codex\Project                   $project
  * @param  Filesystem                             $files
  * @param  \Illuminate\Contracts\Cache\Repository $cache
  * @param  string                                 $path
  * @return void
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function __construct(Project $project, Filesystem $files, Cache $cache, $path)
 {
     $this->cache = $cache;
     $this->files = $files;
     $this->path = $path;
     $this->project = $project;
     Factory::run('menu:ready', [$this]);
     $this->raw = $files->get($path);
     $this->menu = $this->parse($this->raw);
     Factory::run('menu:done', [$this]);
 }
 /**
  * @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;
 }
Esempio n. 14
0
 public function isReachable() : bool
 {
     if (is_null($this->disk)) {
         return false;
     }
     try {
         $this->disk->allFiles($this->backupName);
         return true;
     } catch (Exception $exception) {
         $this->connectionError = $exception;
         return false;
     }
 }
Esempio n. 15
0
 /**
  * @param Filesystem $filesystem
  * @param Repository $config
  * @return CommandResult
  */
 public function handle(Filesystem $filesystem, Repository $config)
 {
     $path = is_null($this->path) ? DIRECTORY_SEPARATOR : $this->path;
     $response = [];
     $response['files'] = $filesystem->files($path);
     $response['directories'] = $filesystem->directories($path);
     $response['base_path'] = $config->get('filesystems.disks.local.root');
     $response['paths'] = $this->breakDownPath($path);
     $response['current_path'] = $this->path;
     $response['is_empty'] = $this->isResultIsEmpty($response['files'], $response['directories']);
     // all good
     return new CommandResult(true, "List command successful.", $response, 200);
 }
Esempio n. 16
0
 protected function loadConfig(Filesystem $fs, $scraperDir)
 {
     $scraperConfigFile = $scraperDir . '/scraper.yml';
     if (!$fs->exists($scraperConfigFile)) {
         return null;
     }
     $configString = $fs->get($scraperConfigFile);
     $parser = new Parser();
     $config = $parser->parse($configString);
     if (!is_array($config) || !count($config) >= 2) {
         return null;
     }
     return $config;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(ValidaInscripcionRequest $request, Filesystem $filesystem)
 {
     //Obtengo la foto del request que envia el usuario
     $file1 = $request->file('foto1');
     $file2 = $request->file('foto2');
     $file3 = $request->file('foto3');
     //obtengo las extensiones
     $extension1 = explode(".", $file1->getClientOriginalName());
     $extension2 = explode(".", $file2->getClientOriginalName());
     $extension3 = explode(".", $file3->getClientOriginalName());
     //armo los nombres
     $nombre1 = $request->persona_id . '_frente.' . $extension1[1];
     $nombre2 = $request->persona_id . '_perfil.' . $extension1[1];
     $nombre3 = $request->persona_id . '_carnaval.' . $extension1[1];
     //valido y guardo el archivo en el disco
     if ($file1->isValid()) {
         $stream = fopen($file1->getRealPath(), 'r+');
         $filesystem->writeStream($nombre1, $stream);
         fclose($stream);
     }
     if ($file2->isValid()) {
         $stream = fopen($file2->getRealPath(), 'r+');
         $filesystem->writeStream($nombre2, $stream);
         fclose($stream);
     }
     if ($file3->isValid()) {
         $stream = fopen($file3->getRealPath(), 'r+');
         $filesystem->writeStream($nombre3, $stream);
         fclose($stream);
     }
     //busco la persona y grabo los datos en la base
     $persona = Persona::find($request->persona_id);
     $persona->fill($request->all());
     $persona->foto1 = $request->persona_id . '_frente';
     $persona->foto2 = $request->persona_id . '_perfil';
     $persona->foto3 = $request->persona_id . '_carnaval';
     $persona->status = true;
     //status en true es para que no vuelva a modificar
     $persona->save();
     //envio el correo
     Mail::send('mails.cuerpo', $request->all(), function ($msj) use($persona, $extension1, $extension2, $extension3) {
         $msj->subject('Inscripcion Mari - Mari 2016 ');
         $msj->to('*****@*****.**');
         $msj->cc('*****@*****.**', "Javier Parra");
         $msj->attach(storage_path() . '/app/fotos/' . $persona->id . "_perfil." . $extension1[1]);
         $msj->attach(storage_path() . '/app/fotos/' . $persona->id . "_frente." . $extension2[1]);
         $msj->attach(storage_path() . '/app/fotos/' . $persona->id . "_carnaval." . $extension3[1]);
     });
     return view('new')->with('email', $persona->email);
 }
 /**
  * @param Filesystem $filesystem
  * @return CommandResult
  */
 public function handle(Filesystem $filesystem)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['media.manage'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     $path = is_null($this->path) ? '/' : $this->path;
     if (!($dir = $filesystem->makeDirectory($this->normalizePath($path) . $this->dirName))) {
         return new CommandResult(false, "Failed to create directory.", null, 400);
     }
     // all good
     return new CommandResult(true, "Make directory command successful.", array($dir), 201);
 }
 /**
  *
  * @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;
 }
Esempio n. 20
0
 /**
  * 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;
 }
Esempio n. 21
0
 /**
  * 文件上传处理
  *
  * @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 Filesystem $filesystem
  * @return CommandResult
  */
 public function handle(Filesystem $filesystem)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['media.delete'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     if (is_null($this->paths)) {
         return new CommandResult(false, "No file path given.", null, 400);
     }
     // begin delete
     if (!$filesystem->delete($this->paths)) {
         return new CommandResult(false, "Failed to delete file.", null, 400);
     }
     // all good
     return new CommandResult(true, "File(s) successfully deleted.", null, 200);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if ($this->option('filter')) {
         $this->filesystem->deleteDirectory(config('image-service.path') . '/' . $this->option('filter'));
         $this->info('Deleted all cached images for "' . $this->option('filter') . '" filter.');
     } elseif ($this->option('cached')) {
         foreach ($this->filesystem->directories(config('image-service.path')) as $dir) {
             // don't delete the original source image
             if (!preg_match("/original\$/mi", $dir)) {
                 $this->filesystem->deleteDirectory($dir);
             }
         }
         $this->info('Deleted all cached images.');
     } else {
         $this->filesystem->deleteDirectory(config('image-service.path'));
         $this->info('All images has been deleted.');
     }
 }
Esempio n. 24
0
 /**
  * Delete a single file from request.
  *
  * @param \Illuminate\Http\Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 protected function deleteFile(Request $request)
 {
     try {
         $file = $request->input('s');
         $this->storage->delete($file);
         return $this->notifySuccess($file . ' successfully deleted!');
     } catch (\ErrorException $e) {
         return $this->notifyError($e->getMessage());
     }
 }
Esempio n. 25
0
 /**
  * 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}");
     }
 }
 /**
  * @param Filesystem $filesystem
  * @return CommandResult
  */
 public function handle(Filesystem $filesystem)
 {
     // check if user has permission
     if (!$this->disablePermissionChecking) {
         if (!$this->user->hasAnyPermission(['media.delete'])) {
             return new CommandResult(false, "Not enough permission.", null, 403);
         }
     }
     if (is_null($this->paths)) {
         return new CommandResult(false, "No file path given.", null, 400);
     }
     // begin delete
     if (is_array($this->paths)) {
         foreach ($this->paths as $dir) {
             $filesystem->deleteDirectory($dir);
         }
     } else {
         $filesystem->deleteDirectory($this->paths);
     }
     // all good
     return new CommandResult(true, "directories successfully deleted.", null, 200);
 }
Esempio n. 27
0
 /**
  * @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);
 }
Esempio n. 28
0
 /**
  * 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 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);
     }
 }
 /**
  * @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;
 }