Skip to content

Commit

Permalink
Merge pull request #2 from ARCANEDEV/feature-1
Browse files Browse the repository at this point in the history
Updating the PackageServiceProvider + README.md
  • Loading branch information
arcanedev-maroc committed Apr 17, 2016
2 parents eadd48c + d8f77a7 commit bbe6d6b
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 38 deletions.
53 changes: 38 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
# Support [![Packagist License][badge_license]](LICENSE.md) [![For Laravel 5][badge_laravel]](https://github.com/ARCANEDEV/Support#support)
# Support [![Packagist License][badge_license]](LICENSE.md) [![For Laravel 5][badge_laravel]][link-github-repo]

[![Travis Status][badge_build]](https://travis-ci.org/ARCANEDEV/Support)
[![HHVM Status][badge_hhvm]](http://hhvm.h4cc.de/package/arcanedev/support)
[![Coverage Status][badge_coverage]](https://scrutinizer-ci.com/g/ARCANEDEV/Support/?branch=master)
[![Scrutinizer Code Quality][badge_quality]](https://scrutinizer-ci.com/g/ARCANEDEV/Support/?branch=master)
[![SensioLabs Insight][badge_insight]](https://insight.sensiolabs.com/projects/de0353dd-df17-4656-b9c0-1eea95aa30a2)
[![Github Issues][badge_issues]](https://github.com/ARCANEDEV/Support/issues)
[![Travis Status][badge_build]][link-travis]
[![HHVM Status][badge_hhvm]][link-hhvm]
[![Coverage Status][badge_coverage]][link-scrutinizer]
[![Scrutinizer Code Quality][badge_quality]][link-scrutinizer]
[![SensioLabs Insight][badge_insight]][link-insight]
[![Github Issues][badge_issues]][link-github-issues]

[![Packagist][badge_package]](https://packagist.org/packages/arcanedev/support)
[![Packagist Release][badge_release]](https://packagist.org/packages/arcanedev/support)
[![Packagist Downloads][badge_downloads]](https://packagist.org/packages/arcanedev/support)
[![Packagist][badge_package]][link-packagist]
[![Packagist Release][badge_release]][link-packagist]
[![Packagist Downloads][badge_downloads]][link-packagist]

*By [ARCANEDEV©](http://www.arcanedev.net/)*

Support package is a collection of helpers and tools for ARCANEDEV + Laravel projects.

Feel free to check out the [releases](https://github.com/ARCANEDEV/Support/releases), [license](LICENSE.md), and [contribution guidelines](CONTRIBUTING.md).

## Contribution

Any ideas are welcome. Feel free to submit any issues or pull requests, please check the [contribution guidelines](CONTRIBUTING.md).

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [ARCANEDEV][link-author]
- [All Contributors][link-contributors]

[badge_license]: http://img.shields.io/packagist/l/arcanedev/support.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/For-Laravel%205.1|5.2-orange.svg?style=flat-square

[badge_build]: http://img.shields.io/travis/ARCANEDEV/Support.svg?style=flat-square
[badge_hhvm]: https://img.shields.io/hhvm/arcanedev/support.svg?style=flat-square
[badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/Support.svg?style=flat-square
[badge_quality]: https://img.shields.io/scrutinizer/g/ARCANEDEV/Support.svg?style=flat-square
[badge_insight]: https://img.shields.io/sensiolabs/i/de0353dd-df17-4656-b9c0-1eea95aa30a2.svg?style=flat-square
[badge_issues]: https://img.shields.io/github/issues/ARCANEDEV/Support.svg?style=flat-square

[badge_package]: https://img.shields.io/badge/package-arcanedev/support-blue.svg?style=flat-square
[badge_release]: https://img.shields.io/packagist/v/arcanedev/support.svg?style=flat-square
[badge_downloads]: https://img.shields.io/packagist/dt/arcanedev/support.svg?style=flat-square

*By [ARCANEDEV©](http://www.arcanedev.net/)*

Support package is a collection of helpers and tools for ARCANEDEV + Laravel projects.
[link-author]: https://github.com/arcanedev-maroc
[link-github-repo]: https://github.com/ARCANEDEV/Support
[link-github-issues]: https://github.com/ARCANEDEV/Support/issues
[link-contributors]: https://github.com/ARCANEDEV/Support/graphs/contributors
[link-packagist]: https://packagist.org/packages/arcanedev/support
[link-travis]: https://travis-ci.org/ARCANEDEV/Support
[link-hhvm]: http://hhvm.h4cc.de/package/arcanedev/support
[link-scrutinizer]: https://scrutinizer-ci.com/g/ARCANEDEV/Support/?branch=master
[link-insight]: https://insight.sensiolabs.com/projects/de0353dd-df17-4656-b9c0-1eea95aa30a2
117 changes: 95 additions & 22 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @package Arcanedev\Support\Laravel
* @author ARCANEDEV <[email protected]>
*
* @todo Redo the PackageServiceProvider
* @todo Clean/Redo the PackageServiceProvider
*/
abstract class PackageServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -56,21 +56,21 @@ abstract class PackageServiceProvider extends ServiceProvider
| ------------------------------------------------------------------------------------------------
*/
/**
* Get config folder.
* Get the base path of the package.
*
* @return string
*/
protected function getConfigFolder()
{
return realpath($this->getBasePath() . DS .'config');
}
abstract public function getBasePath();

/**
* Get the base path of the package.
* Get config folder.
*
* @return string
*/
abstract public function getBasePath();
protected function getConfigFolder()
{
return realpath($this->getBasePath() . DS .'config');
}

/**
* Get config key.
Expand All @@ -89,7 +89,7 @@ protected function getConfigKey()
*/
protected function getConfigFile()
{
return $this->getConfigFolder() . DS . $this->package . '.php';
return $this->getConfigFolder() . DS . "{$this->package}.php";
}

/* ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -127,13 +127,10 @@ protected function setup()
*/
protected function registerConfig($separator = '.')
{
if ($this->multiConfigs) {
if ($this->multiConfigs)
$this->registerMultipleConfigs($separator);

return;
}

$this->mergeConfigFrom($this->getConfigFile(), $this->getConfigKey());
else
$this->mergeConfigFrom($this->getConfigFile(), $this->getConfigKey());
}

/**
Expand All @@ -144,12 +141,90 @@ protected function registerConfig($separator = '.')
private function registerMultipleConfigs($separator = '.')
{
foreach (glob($this->getConfigFolder() . '/*.php') as $configPath) {
$key = $this->getConfigKey() . $separator . basename($configPath, '.php');

$this->mergeConfigFrom($configPath, $key);
$this->mergeConfigFrom(
$configPath,
$this->getConfigKey() . $separator . basename($configPath, '.php')
);
}
}

/**
* Publish the config file.
*/
protected function publishConfig()
{
$this->publishes([
$this->getConfigFile() => config_path("{$this->package}.php"),
], 'config');
}

/**
* Publish the migration files.
*/
protected function publishMigrations()
{
$this->publishes([
$this->getBasePath() . '/database/migrations/' => database_path('migrations'),
], 'migrations');
}

/**
* Publish and load the views if $load argument is true.
*
* @param bool $load
*/
protected function publishViews($load = true)
{
$this->publishes([
$this->getBasePath() . '/resources/views' => base_path("resources/views/vendor/{$this->package}"),
], 'views');

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

/**
* Publish and load the translations if $load argument is true.
*
* @param bool $load
*/
protected function publishTranslations($load = true)
{
$this->publishes([
$this->getBasePath() . '/resources/lang' => base_path("resources/lang/vendor/{$this->package}"),
], 'lang');

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

/**
* Publish all the package files.
*
* @param bool $load
*/
protected function publishAll($load = true)
{
$this->publishConfig();
$this->publishMigrations();
$this->publishViews($load);
$this->publishTranslations($load);
}

/**
* Load the views files.
*/
protected function loadViews()
{
$this->loadViewsFrom($this->getBasePath() . '/resources/views', $this->package);
}

/**
* Load the translations files.
*/
protected function loadTranslations()
{
$this->loadTranslationsFrom($this->getBasePath() . '/resources/lang', $this->package);
}

/* ------------------------------------------------------------------------------------------------
| Check Functions
| ------------------------------------------------------------------------------------------------
Expand All @@ -161,11 +236,9 @@ private function registerMultipleConfigs($separator = '.')
*/
private function checkPackageName()
{
if ( ! empty($this->package) ) {
return;
if (empty($this->package) || empty($this->package)) {
throw new PackageException('You must specify the vendor/package name.');
}

throw new PackageException('You must specify the name of the package');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Providers/PackageServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function it_can_register_config()
* @test
*
* @expectedException \Arcanedev\Support\Exceptions\PackageException
* @expectedExceptionMessage You must specify the name of the package
* @expectedExceptionMessage You must specify the vendor/package name.
*/
public function it_must_throw_a_package_exception()
{
Expand Down

0 comments on commit bbe6d6b

Please sign in to comment.