-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Service providers for laravel projects
- Loading branch information
1 parent
8cda4fe
commit 37cdc4b
Showing
2 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php namespace Arcanedev\Support\Laravel; | ||
|
||
use ReflectionClass; | ||
|
||
/** | ||
* Class PackageServiceProvider | ||
* @package Arcanedev\Moduly\Bases | ||
*/ | ||
abstract class PackageServiceProvider extends ServiceProvider | ||
{ | ||
/* ------------------------------------------------------------------------------------------------ | ||
| Properties | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Package name | ||
* | ||
* @var string | ||
*/ | ||
protected $package = ''; | ||
|
||
/** | ||
* Paths collection | ||
* | ||
* @var array | ||
*/ | ||
protected $paths = []; | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Getters & Setters | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Get package base path | ||
* | ||
* @return string | ||
*/ | ||
protected function getPackagePath() | ||
{ | ||
$path = (new ReflectionClass(get_class($this))) | ||
->getFileName(); | ||
|
||
return dirname(dirname($path)); | ||
} | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Main Functions | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
public function boot() | ||
{ | ||
if (empty($this->package) ) { | ||
throw new \Exception('You must specify the name of the package'); | ||
} | ||
} | ||
|
||
/** | ||
* Setup package | ||
* | ||
* @param string $path | ||
* | ||
* @return self | ||
*/ | ||
public function setup($path) | ||
{ | ||
$this->setupPaths($path); | ||
|
||
return $this; | ||
} | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Other Functions | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Register all package configs | ||
* | ||
* @return self | ||
*/ | ||
protected function registerConfigs() | ||
{ | ||
array_map(function ($path) { | ||
$this->mergeConfig($path); | ||
}, glob($this->getPackagePath() . '/config/*.php')); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Merge config files | ||
* | ||
* @param string $path | ||
* | ||
* @return self | ||
*/ | ||
private function mergeConfig($path) | ||
{ | ||
$this->mergeConfigFrom($path, | ||
$this->package . '.' . basename($path, '.php') | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Setup paths | ||
* | ||
* @param string $path | ||
* | ||
* @return self | ||
*/ | ||
private function setupPaths($path) | ||
{ | ||
$this->paths = [ | ||
'migrations' => [ | ||
'src' => $path . '/../database/migrations', | ||
'dest' => database_path('/migrations/%s_%s'), | ||
], | ||
'seeds' => [ | ||
'src' => $path . '/Seeds', | ||
'dest' => database_path('/seeds/%s'), | ||
], | ||
'config' => [ | ||
'src' => $path . '/../config', | ||
'dest' => config_path('%s'), | ||
], | ||
'views' => [ | ||
'src' => $path . '/../resources/views', | ||
'dest' => base_path('resources/views/vendor/%s'), | ||
], | ||
'trans' => [ | ||
'src' => $path . '/../resources/lang', | ||
'dest' => base_path('resources/lang/%s'), | ||
], | ||
'assets' => [ | ||
'src' => $path . '/../resources/assets', | ||
'dest' => public_path('vendor/%s'), | ||
], | ||
'routes' => [ | ||
'src' => $path . '/../start/routes.php', | ||
'dest' => null, | ||
], | ||
]; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php namespace Arcanedev\Support\Laravel; | ||
|
||
use Illuminate\Foundation\AliasLoader; | ||
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider; | ||
|
||
/** | ||
* Class ServiceProvider | ||
* @package Arcanedev\Foundation\Bases | ||
*/ | ||
abstract class ServiceProvider extends IlluminateServiceProvider | ||
{ | ||
/* ------------------------------------------------------------------------------------------------ | ||
| Other Functions | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Add Aliases into the app | ||
* | ||
* @param array $aliases | ||
* | ||
* @return self | ||
*/ | ||
protected function addAliases(array $aliases) | ||
{ | ||
if (count($aliases)) { | ||
$loader = AliasLoader::getInstance(); | ||
|
||
foreach ($aliases as $alias => $class) { | ||
$loader->alias($alias, $class); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
} |