Skip to content

Commit

Permalink
Merge pull request #9 from ARCANEDEV/patch-package_service_provider
Browse files Browse the repository at this point in the history
Updating Package Service Provider
  • Loading branch information
arcanedev-maroc authored Sep 18, 2016
2 parents daa8c5a + 1cac1ef commit 9dfe987
Showing 1 changed file with 32 additions and 77 deletions.
109 changes: 32 additions & 77 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*
* @package Arcanedev\Support\Laravel
* @author ARCANEDEV <[email protected]>
*
* @todo Clean/Redo the PackageServiceProvider
*/
abstract class PackageServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -37,13 +35,6 @@ abstract class PackageServiceProvider extends ServiceProvider
*/
protected $basePath = '';

/**
* Paths collection.
*
* @var array
*/
protected $paths = [];

/**
* Merge multiple config files into one instance (package name as root key)
*
Expand Down Expand Up @@ -83,7 +74,7 @@ protected function getConfigKey()
}

/**
* Get config file path
* Get config file path.
*
* @return string
*/
Expand Down Expand Up @@ -116,7 +107,6 @@ public function boot()
protected function setup()
{
$this->checkPackageName();
$this->setupPaths();
$this->registerConfig();
}

Expand Down Expand Up @@ -174,9 +164,11 @@ protected function publishConfig()
*/
protected function publishMigrations()
{
$this->publishes([
$this->getBasePath() . '/database/migrations/' => database_path('migrations'),
], 'migrations');
if (is_dir($path = ($this->getBasePath() . '/database/migrations/'))) {
$this->publishes([
$path => database_path('migrations'),
], 'migrations');
}
}

/**
Expand All @@ -186,11 +178,13 @@ protected function publishMigrations()
*/
protected function publishViews($load = true)
{
$this->publishes([
$this->getBasePath() . '/resources/views' => base_path("resources/views/vendor/{$this->package}"),
], 'views');
if (is_dir($path = ($this->getBasePath() . '/resources/views'))) {
$this->publishes([
$path => base_path("resources/views/vendor/{$this->package}"),
], 'views');

if ($load) $this->loadViews();
if ($load) $this->loadViews();
}
}

/**
Expand All @@ -200,11 +194,25 @@ protected function publishViews($load = true)
*/
protected function publishTranslations($load = true)
{
$this->publishes([
$this->getBasePath() . '/resources/lang' => base_path("resources/lang/vendor/{$this->package}"),
], 'lang');
if (is_dir($path = ($this->getBasePath() . '/resources/lang'))) {
$this->publishes([
$path => base_path("resources/lang/vendor/{$this->package}"),
], 'lang');

if ($load) $this->loadTranslations();
if ($load) $this->loadTranslations();
}
}

/**
* Publish the factories.
*/
protected function publishFactories()
{
if (is_dir($path = ($this->getBasePath() . '/database/factories'))) {
$this->publishes([
$path => database_path('factories'),
], 'factories');
}
}

/**
Expand All @@ -218,6 +226,7 @@ protected function publishAll($load = true)
$this->publishMigrations();
$this->publishViews($load);
$this->publishTranslations($load);
$this->publishFactories();
}

/**
Expand All @@ -241,7 +250,7 @@ protected function loadTranslations()
| ------------------------------------------------------------------------------------------------
*/
/**
* Check package name
* Check package name.
*
* @throws PackageException
*/
Expand All @@ -261,58 +270,4 @@ protected function hasPackageConfig()
{
return $this->getConfigFile() !== false;
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Setup paths.
*
* @return self
*/
private function setupPaths()
{
$this->basePath = $this->getBasePath();
$this->paths = [
'config' => [
'src' => $this->getSourcePath('config'),
'dest' => config_path('%s'),
],
'migrations' => [
'src' => $this->getSourcePath('database/migrations'),
'dest' => database_path('migrations/%s_%s'),
],
'views' => [
'src' => $this->getSourcePath('resources/views'),
'dest' => base_path('resources/views/' . $this->vendor . '/%s'),
],
'trans' => [
'src' => $this->getSourcePath('resources/lang'),
'dest' => base_path('resources/lang/%s'),
],
'assets' => [
'src' => $this->getSourcePath('resources/assets'),
'dest' => public_path('vendor/%s'),
],
'seeds' => [
'src' => $this->getSourcePath('src/Seeds'),
'dest' => database_path('seeds/%s'),
],
];

return $this;
}

/**
* Get source path.
*
* @param string $path
*
* @return string
*/
private function getSourcePath($path)
{
return str_replace('/', DS, $this->basePath . DS . $path);
}
}

0 comments on commit 9dfe987

Please sign in to comment.