Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete Upgrade for Lumen 9.x #30

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
{
"name": "irazasyed/larasupport",
"name": "cryental/larasupport",
"type": "library",
"description": "Adds Laravel Package Support in Lumen.",
"keywords": [
"laravel",
"laravel lumen support",
"lumen packages",
"laravel packages",
"lumen support",
"larasupport",
"laravel package support"
],
"license": "MIT",
"authors": [
{
"name": "Irfaq Syed",
"email": "syed+gh@lukonet.com",
"homepage": "https://github.com/irazasyed"
},
{
"name": "Cryental",
"email": "contact@cryental.dev",
"homepage": "https://cryental.dev"
}
],
"require": {
"league/flysystem": "^1.0"
"league/flysystem": "^3.2"
},
"config": {
"preferred-install": "dist",
Expand Down
100 changes: 76 additions & 24 deletions src/Console/VendorPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Events\VendorTagPublished;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Adapter\Local as LocalAdapter;
use Illuminate\Support\Str;
use League\Flysystem\Filesystem as Flysystem;
use League\Flysystem\Local\LocalFilesystemAdapter as LocalAdapter;
use League\Flysystem\MountManager;
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
use League\Flysystem\Visibility;
use Symfony\Component\Console\Attribute\AsCommand;

class VendorPublishCommand extends Command
{
Expand Down Expand Up @@ -38,11 +43,24 @@ class VendorPublishCommand extends Command
*
* @var string
*/
protected $signature = 'vendor:publish {--force : Overwrite any existing files}
protected $signature = 'vendor:publish
{--existing : Publish and overwrite only the files that have already been published}
{--force : Overwrite any existing files}
{--all : Publish assets for all service providers without prompt}
{--provider= : The service provider that has assets you want to publish}
{--tag=* : One or many tags that have assets you want to publish}';

/**
* The name of the console command.
*
* This name is used to identify the command during lazy loading.
*
* @var string|null
*
* @deprecated
*/
protected static $defaultName = 'vendor:publish';

/**
* The console command description.
*
Expand Down Expand Up @@ -75,8 +93,6 @@ public function handle()
foreach ($this->tags ?: [null] as $tag) {
$this->publishTag($tag);
}

$this->info('Publishing complete.');
}

/**
Expand Down Expand Up @@ -106,7 +122,7 @@ protected function determineWhatShouldBePublished()
*/
protected function promptForProviderOrTag()
{
$choice = $this->choice(
$choice = $this->components->choice(
"Which provider or tag's files would you like to publish?",
$choices = $this->publishableChoices()
);
Expand All @@ -127,8 +143,8 @@ protected function publishableChoices()
{
return array_merge(
['<comment>Publish files from all providers and tags listed below</comment>'],
preg_filter('/^/', '<comment>Provider: </comment>', Arr::sort(ServiceProvider::publishableProviders())),
preg_filter('/^/', '<comment>Tag: </comment>', Arr::sort(ServiceProvider::publishableGroups()))
preg_filter('/^/', '<fg=gray>Provider:</> ', Arr::sort(ServiceProvider::publishableProviders())),
preg_filter('/^/', '<fg=gray>Tag:</> ', Arr::sort(ServiceProvider::publishableGroups()))
);
}

Expand Down Expand Up @@ -159,14 +175,23 @@ protected function publishTag($tag)
{
$published = false;

foreach ($this->pathsToPublish($tag) as $from => $to) {
$this->publishItem($from, $to);
$pathsToPublish = $this->pathsToPublish($tag);

if ($publishing = count($pathsToPublish) > 0) {
$this->components->info(sprintf(
'Publishing %sassets',
$tag ? "[$tag] " : '',
));
}

$published = true;
foreach ($pathsToPublish as $from => $to) {
$this->publishItem($from, $to);
}

if ($published === false) {
$this->error('Unable to locate publishable resources.');
if ($publishing === false) {
$this->components->info('No publishable resources for tag ['.$tag.'].');
} else {
$this->newLine();
}
}

Expand All @@ -179,8 +204,7 @@ protected function publishTag($tag)
protected function pathsToPublish($tag)
{
return ServiceProvider::pathsToPublish(
$this->provider,
$tag
$this->provider, $tag
);
}

Expand All @@ -199,7 +223,7 @@ protected function publishItem($from, $to)
return $this->publishDirectory($from, $to);
}

$this->error("Can't locate path: <{$from}>");
$this->components->error("Can't locate path: <{$from}>");
}

/**
Expand All @@ -211,12 +235,25 @@ protected function publishItem($from, $to)
*/
protected function publishFile($from, $to)
{
if (! $this->files->exists($to) || $this->option('force')) {
if ((! $this->option('existing') && (! $this->files->exists($to) || $this->option('force')))
|| ($this->option('existing') && $this->files->exists($to))) {
$this->createParentDirectory(dirname($to));

$this->files->copy($from, $to);

$this->status($from, $to, 'File');
$this->status($from, $to, 'file');
} else {
if ($this->option('existing')) {
$this->components->twoColumnDetail(sprintf(
'File [%s] does not exist',
str_replace(base_path().'/', '', $to),
), '<fg=yellow;options=bold>SKIPPED</>');
} else {
$this->components->twoColumnDetail(sprintf(
'File [%s] already exists',
str_replace(base_path().'/', '', realpath($to)),
), '<fg=yellow;options=bold>SKIPPED</>');
}
}
}

Expand All @@ -229,12 +266,14 @@ protected function publishFile($from, $to)
*/
protected function publishDirectory($from, $to)
{
$visibility = PortableVisibilityConverter::fromArray([], Visibility::PUBLIC);

$this->moveManagedFiles(new MountManager([
'from' => new Flysystem(new LocalAdapter($from)),
'to' => new Flysystem(new LocalAdapter($to)),
'to' => new Flysystem(new LocalAdapter($to, $visibility)),
]));

$this->status($from, $to, 'Directory');
$this->status($from, $to, 'directory');
}

/**
Expand All @@ -246,8 +285,16 @@ protected function publishDirectory($from, $to)
protected function moveManagedFiles($manager)
{
foreach ($manager->listContents('from://', true) as $file) {
if ($file['type'] === 'file' && (! $manager->has('to://' . $file['path']) || $this->option('force'))) {
$manager->put('to://' . $file['path'], $manager->read('from://' . $file['path']));
$path = Str::after($file['path'], 'from://');

if (
$file['type'] === 'file'
&& (
(! $this->option('existing') && (! $manager->fileExists('to://'.$path) || $this->option('force')))
|| ($this->option('existing') && $manager->fileExists('to://'.$path))
)
) {
$manager->write('to://'.$path, $manager->read($file['path']));
}
}
}
Expand Down Expand Up @@ -275,10 +322,15 @@ protected function createParentDirectory($directory)
*/
protected function status($from, $to, $type)
{
$from = str_replace(base_path(), '', realpath($from));
$from = str_replace(base_path().'/', '', realpath($from));

$to = str_replace(base_path(), '', realpath($to));
$to = str_replace(base_path().'/', '', realpath($to));

$this->line('<info>Copied ' . $type . '</info> <comment>[' . $from . ']</comment> <info>To</info> <comment>[' . $to . ']</comment>');
$this->components->task(sprintf(
'Copying %s [%s] to [%s]',
$type,
$from,
$to,
));
}
}
6 changes: 6 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Support\Arr;
use Carbon\Carbon;

if (! function_exists('route_parameter')) {
/**
Expand Down Expand Up @@ -72,3 +73,8 @@ function bcrypt($value, $options = [])
return app('hash')->driver('bcrypt')->make($value, $options);
}
}

function now($timezone = null)
{
return Carbon::now($timezone);
}