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

[5.5] Add prompt to vendor:publish to specify which provider/tag to publish #18230

Merged
merged 3 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 23 additions & 1 deletion src/Illuminate/Foundation/Console/VendorPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class VendorPublishCommand extends Command
* @var string
*/
protected $signature = 'vendor:publish {--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.}';

Expand Down Expand Up @@ -76,6 +77,27 @@ protected function publishTag($tag)
$this->info('Publishing complete.');
}

/**
* Determine the provider to publish.
*
* @return mixed
*/
protected function providerToPublish()
{
if ($this->option('all')) {
return null;
}

if ($this->option('provider')) {
return $this->option('provider');
}

return $this->choice(
"Which package's files would you like to publish?",
ServiceProvider::providersAvailableToPublish()
);
Copy link

@MarkVaughn MarkVaughn Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might work

        $choice = $this->choice(
            "Which package's files would you like to publish?",
            array_merge(
                ['All'],
                ServiceProvider::providersAvailableToPublish()
            ),
            0
        );
        
        return $choice === 'All' ? null : $choice;

}

/**
* Get all of the paths to publish.
*
Expand All @@ -85,7 +107,7 @@ protected function publishTag($tag)
protected function pathsToPublish($tag)
{
return ServiceProvider::pathsToPublish(
$this->option('provider'), $tag
$this->providerToPublish(), $tag
);
}

Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Support/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ protected function addPublishGroup($group, $paths)
);
}

/**
* Get the service providers available for publishing.
*
* @return array
*/
public static function providersAvailableToPublish()
{
return array_keys(static::$publishes);
}

/**
* Get the paths to publish.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Support/SupportServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public function tearDown()
m::close();
}

public function testGetAvailableServiceProvidersToPublish()
{
$availableToPublish = ServiceProvider::providersAvailableToPublish();
$expected = [
'Illuminate\Tests\Support\ServiceProviderForTestingOne',
'Illuminate\Tests\Support\ServiceProviderForTestingTwo',
];
$this->assertEquals($expected, $availableToPublish, 'Publishable service providers do not return expected set of providers.');
}

public function testSimpleAssetsArePublishedCorrectly()
{
$toPublish = ServiceProvider::pathsToPublish('Illuminate\Tests\Support\ServiceProviderForTestingOne');
Expand Down