tjventurini/service-provider

A simple laravel ServiceProvider class for standardized packages.

v0.0.2 2021-03-05 23:40 UTC

This package is auto-updated.

Last update: 2024-05-06 06:16:07 UTC


README

This package provides a the SimpleServiceProvider class that you can use to speed up your laravel package development.

This package was not inspired but highly influenced by spatie/lravel-package-tools 😉

Installation

To install this package you can run the following.

composer require tjventurini/service-provider

In order to use it in a package you should add it as a dependency in your composer.json file.

Features

  • Automatically detect resources provided by your package 🔍
  • Can handle and autodetect configuration
  • Can handle and autodetect migrations
  • Can handle and autodetect translations
  • Can handle and autodetect views
  • Can handle artisan commands
  • Can handle services
  • Can handle and autodetect graphql schema
  • Can handle graphql namespaces
  • Can handle route files

Usage

To use the SimpleServiceProvider class just extend it on your ServiceProvider.

use Tjventurini\ServiceProvider\SimpleServiceProvider;

class YourPackageServiceProvider extends SimpleServiceProvider

Per default the service provider will try to detect and setup the resources provided by your package without further steps required from you. If you want or need more flexibility for your setup, read on.

Configuration

use Tjventurini\ServiceProvider\SimpleServiceProvider;

class YourPackageServiceProvider extends SimpleServiceProvider
{
    /**
     * Setup the configuration for the given package.
     *
     * @param  Package $Package
     * @return void
     */
    public function configurePackage(Package $Package): void
    {
        $Package
            ->setPackageSlug('your-package-slug')
            ->hasConfig()
            ->hasMigrations()
            ->hasTranslations()
            ->hasCommands([
                SomeCommand::class,
                AnotherCommand::class
            ])
            ->hasGraphQLSchema()
            ->hasGraphQLNamespaces([
                'models' => 'Foo\\Bar'
            ])
            ->registerService(SomeService::class)
            ->registerService(ServiceWithConfig::class, ['api_key' => 'some-key'])
            ->hasWebRoutes()
            ->hasApiRoutes()
            ->registerRouteFile('routes/admin.php');
    }
}

For more information check out the SimpleServiceProvider and Package classes 🕵

Roadmap 🛣

  • Autodetect commands
  • Autodetect services
  • Autodetect graphql namespaces
  • Enable handling of multiple configuration files
  • Enable handling of multiple graphql schema files