Skip to content

Commit

Permalink
updated service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mdobydullah committed Mar 25, 2023
1 parent 4bc009e commit b24e030
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,40 @@ php artisan vendor:publish --provider="Obydul\\Larable\\LarableServiceProvider"

The available morphable packages/features.

| Feature/Package | Description |
|-----------------------------------------------------------------------------|-------------------------------------------------------------|
| [overtrue/laravel-subscribe](https://github.com/overtrue/laravel-subscribe) | User subscribe/unsubscribe feature for Laravel Application. |
| [overtrue/laravel-follow](https://github.com/overtrue/laravel-follow) | User follow unfollow system for Laravel. |
| Service Name | Feature/Package | Description |
|--------------|-----------------------------------------------------------------------------|-------------------------------------------------------------|
| Subscribe | [overtrue/laravel-subscribe](https://github.com/overtrue/laravel-subscribe) | User subscribe/unsubscribe feature for Laravel Application. |
| Follow | [overtrue/laravel-follow](https://github.com/overtrue/laravel-follow) | User follow unfollow system for Laravel. |

## Cleanup Unused Services

Currently, there are 2 services. We will keep adding more services. The chances are good that you will not want them all. In order to avoid shipping these dependencies with your code, you can run the ```Obydul\Larable\Task\Composer::cleanup``` task and specify the services you want to keep in ```composer.json```:

```json
{
"require": {
"obydul/larable": "^1.1"
},
"scripts": {
"pre-autoload-dump": "Obydul\\Larable\\Task\\Composer::cleanup"
},
"extra": {
"obydul/larable": [
"Subscribe",
"Follow"
]
}
}
```

This example will remove all services other than "Subscribe" and "Follow" when ```composer update``` or a fresh ```composer install``` is run.

**IMPORTANT**: If you add any services back in ```composer.json```, you will need to remove the ```vendor/obydul/larable``` directory explicitly for the change you made to have effect:

```
rm -r obydul/larable
composer update
```

## License

Expand Down
10 changes: 9 additions & 1 deletion src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ class Helper
// available services
public function services(): array
{
return [
// all services
$all_services = [
'Subscribe',
'Follow',
];

// read root composer.json
$composer_json_path = base_path().'\composer.json';
$composer_json_content = file_get_contents($composer_json_path);
$composer_json_data = json_decode($composer_json_content, true);

return $composer_json_data['extra']['obydul/larable'] ?? $all_services;
}
}
7 changes: 2 additions & 5 deletions src/LarableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ class LarableServiceProvider extends ServiceProvider
{
public function boot()
{
// read root composer.json
$composer_json_path = base_path().'\composer.json';
$composer_json_content = file_get_contents($composer_json_path);
$composer_json_data = json_decode($composer_json_content, true);
$services = $composer_json_data['extra']['obydul/larable'] ?? (new Helper())->services();
// services
$services = (new Helper())->services();

// config files
foreach ($services as $service) {
Expand Down

0 comments on commit b24e030

Please sign in to comment.