Giter VIP home page Giter VIP logo

Comments (2)

weezqyd avatar weezqyd commented on June 15, 2024

Create a manager class that extends SimpleSoftwareIO\SMS\DriverManager register your sms service on this class, Create a copy of SimpleSoftwareIO\SMS\SMSServiceProvider and name it MyCustomServiceProvider on top of this class import these two classes

use MyNamespace\DriverManager;
use SimpleSoftwareIO\SMS\SMS;

Add you custom service to the config file that it can be loaded
Your custom Driver manager

namespace MyNamspace\SMS;

use MyNamespace\SmsSender;
use SimpleSoftwareIO\SMS\DriverManager as Manager;

 class DriverManager extends Manager
{

	public function createSmssenderDriver()
	{
		$config = $this->app['config']->get('sms.smssender', []);

        $provider = new SmsSender(
            $config['api_key'],
            $config['username']
        );

        return $provider;
	}
}

Your custom service provider should be something simillar to this

namespace MyNamespace\SMS;

use MyNamespace\DriverManager;
use SimpleSoftwareIO\SMS\SMS;
use Illuminate\Support\ServiceProvider;

class MyCustomServiceProvider extends ServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Bootstrap the application events.
     */
    public function boot()
    {
        $this->mergeConfigFrom(  __DIR__.'/config/sms.php' ,  'sms.'),;
    }

    /**
     * Register the service provider.
     */
    public function register()
    {
        $this->app->singleton('sms', function ($app) {

            $this->registerSender();
            $sms = new SMS($app['sms.sender']);
            $this->setSMSDependencies($sms, $app);

            //Set the from setting
            if ($app['config']->has('sms.from')) {
                $sms->alwaysFrom($app['config']['sms']['from']);
            }

            return $sms;
        });
    }

    /**
     * Register the correct driver based on the config file.
     */
    public function registerSender()
    {
        $this->app['sms.sender'] = $this->app->share(function ($app) {
            return (new DriverManager($app))->driver();
        });
    }

    /**
     * Set a few dependencies on the sms instance.
     *
     * @param SMS $sms
     * @param  $app
     */
    private function setSMSDependencies($sms, $app)
    {
        $sms->setContainer($app);
        $sms->setQueue($app['queue']);
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return array('sms', 'sms.sender');
    }
}

thats it your new service will now work with smplle-sms package Custom Package

from simple-sms.

ngugijames avatar ngugijames commented on June 15, 2024

Thanks @weezqyd
With a few modifications this worked very well.

from simple-sms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.