laravel-commode/silent-service

There is no license information available for the latest version (dev-master) of this package.

dev-master 2015-10-02 09:08 UTC

This package is not auto-updated.

Last update: 2024-04-27 16:19:59 UTC


README

#Commode: Silent Service

Build Status Code Climate Coverage Status

laravel-commode/silent-service is a customized service provider with useful features for designed for laravel-commode package environment or laravel 5.1 package development.

####Contents

##Installing

You can install laravel-commode/silent-service using composer:

"require": {
    "laravel-commode/silent-service": "dev-master"
}

There are two ways to register service provider. First one is a classic registration in app.php config file, but it's optional, since any SilentService instance does dependency checks on other service providers and if they are not registered, their registration is being enforced.

<?php
    // apppath/config/app.php
    return [
        // config code...
        
        'providers' => [
            // your app providers... ,
            LaravelCommode\SilentService\SilentServiceServiceProvider::class
            // or any your SilentService instance
        ]
    ];

##Usage

laravel-commode/silent-service was developed to provide service dependency loading and alias binding without modifying app.php code, for example if service provider of your package depends on five different from different package, you would need to make config modification for all five packages - this way your service is responsible for dependency control, but not the "final developer".

To create a silent service provider you need to extend LaravelCommode\SilentService\SilentService class and implement two protected methods: SilentService::registering() and SilentService::launching().

To declare dependencies on different service providers you need to override protected method SilentService::uses(). This method must return an array of service providers' class names, which need to be registered before SilentService::registering() is triggered.

If your service provider needs to implement aliases on laravel facades you need to override protected method SilentService::aliases(). This method must return an array of strings, where array keys are alias names and array values are facade class names.

Since the usage of service providers is not always for registering new features, but also modifying the old ones and still there are a lot of facade haters among the community, silent service providers protected method SilentService::with(array $resolvable, callable $do), which usage you will see in example. Note that it can resolve not only service names, but everything that is found in IoC of can be resolved|instantiated.

<?php
    namespace MyVendor\MyPackage;
    
    use LaravelCommode\SilentService\SilentService;
    
    use Illuminate\View\Factory;
    use Illuminate\Http\Request;
    
    class MyPackageServiceProvider extends SilentService
    {
        protected function uses()
        {
            return [\CustomVendor\CustomPackage\CustomPackageServiceProvider::class];
        }
        
        protected function aliases()
        {
            return [
                'MyFacade' => 'MyVendor\MyPackage\MyPackageFacade'
            ];
        }
        
        /**
         * This method will be triggered instead
         * of original ServiceProvider::register().
         * @return mixed
         */
         public function registering()
         {
            $this->with(['view', 'request'], function (Factory $view, Request $request) {
                // do registrations
            });
         }
    
    
        /**
         * This method will be triggered instead
         * when application's booting event is fired.
         * @return mixed
         */
         public function launching()
         {
         
         }
    }