Skip to content

Commit

Permalink
Adding publish commands
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Dec 3, 2016
1 parent 97ea808 commit 677319c
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/Console/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php namespace Arcanesoft\Media\Console;

use Arcanedev\Support\Bases\Command as BaseCommand;

/**
* Class Command
*
* @package Arcanesoft\Media\Console
* @author ARCANEDEV <[email protected]>
*/
abstract class Command extends BaseCommand
{
//
}
44 changes: 44 additions & 0 deletions src/Console/PublishCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php namespace Arcanesoft\Media\Console;

use Arcanesoft\Media\MediaServiceProvider;

/**
* Class PublishCommand
*
* @package Arcanesoft\Media\Console
* @author ARCANEDEV <[email protected]>
*/
class PublishCommand extends Command
{
/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
*/
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'media:publish';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Publish media config, assets and other stuff.';

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Execute the console command.
*/
public function handle()
{
$this->call('vendor:publish', [
'--provider' => MediaServiceProvider::class,
]);
}
}
32 changes: 25 additions & 7 deletions src/MediaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ public function register()
$this->syncFilesystemConfig();
}

private function syncFilesystemConfig()
{
foreach ($this->config()->get('arcanesoft.media.filesystem.disks', []) as $disk => $config) {
$this->config()->set("filesystems.disks.$disk", $config);
}
}

/**
* Boot the service provider.
*/
Expand All @@ -78,6 +71,7 @@ public function boot()
$this->publishViews();
$this->publishTranslations();
$this->publishSidebarItems();
$this->publishAssets();
}

/**
Expand All @@ -91,4 +85,28 @@ public function provides()
//
];
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Sync the filesystem config.
*/
private function syncFilesystemConfig()
{
foreach ($this->config()->get('arcanesoft.media.filesystem.disks', []) as $disk => $config) {
$this->config()->set("filesystems.disks.$disk", $config);
}
}

/**
* Publish the assets.
*/
private function publishAssets()
{
$this->publishes([
$this->getBasePath() . '/resources/assets/js' => resource_path("assets/back/js/components/{$this->vendor}/{$this->package}"),
], 'assets-js');
}
}
40 changes: 40 additions & 0 deletions src/Providers/CommandServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
<?php namespace Arcanesoft\Media\Providers;

use Arcanedev\Support\ServiceProvider;
use Arcanesoft\Media\Console;

/**
* Class CommandServiceProvider
*
* @package Arcanesoft\Media\Providers
* @author ARCANEDEV <[email protected]>
*/
class CommandServiceProvider extends ServiceProvider
{
/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
*/
/**
* Console commands.
*
* @var array
*/
protected $commands = [
Console\PublishCommand::class,
];

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Register the service provider.
*/
public function register()
{
$this->commands($this->commands);
}

/**
* Get the provided commands.
*
* @return array
*/
public function provides()
{
return $this->commands;
}
}
65 changes: 65 additions & 0 deletions tests/Providers/CommandServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php namespace Arcanesoft\Media\Tests\Providers;

use Arcanesoft\Media\Tests\TestCase;

/**
* Class CommandServiceProviderTest
*
* @package Arcanesoft\Media\Tests\Providers
* @author ARCANEDEV <[email protected]>
*/
class CommandServiceProviderTest extends TestCase
{
/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
*/
/** @var \Arcanesoft\Media\Providers\CommandServiceProvider */
private $provider;

/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
public function setUp()
{
parent::setUp();

$this->provider = $this->app->getProvider(\Arcanesoft\Media\Providers\CommandServiceProvider::class);
}

public function tearDown()
{
unset($this->provider);

parent::tearDown();
}

/* ------------------------------------------------------------------------------------------------
| Test Functions
| ------------------------------------------------------------------------------------------------
*/
/** @test */
public function it_can_be_instantiated()
{
$expectations = [
\Illuminate\Support\ServiceProvider::class,
\Arcanedev\Support\ServiceProvider::class,
\Arcanesoft\Media\Providers\CommandServiceProvider::class,
];

foreach ($expectations as $expected) {
$this->assertInstanceOf($expected, $this->provider);
}
}

/** @test */
public function it_can_provides()
{
$expected = [
\Arcanesoft\Media\Console\PublishCommand::class,
];

$this->assertSame($expected, $this->provider->provides());
}
}

0 comments on commit 677319c

Please sign in to comment.