Skip to content

Commit

Permalink
+ Added command and cleaned up service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tylernathanreed committed Sep 26, 2020
1 parent 7c21888 commit 1bdbd78
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 13 deletions.
64 changes: 64 additions & 0 deletions src/Console/SMSMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Reedware\LaravelSMS\Console;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class SMSMakeCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:sms';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new textable class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'SMS';

/**
* Returns the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__ . '../../stubs/sms.stub';
}

/**
* Returns the default namespace for the class.
*
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\SMS';
}

/**
* Returns the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the textable already exists'],
];
}
}
70 changes: 57 additions & 13 deletions src/SMSServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use Reedware\LaravelSMS\Console\SMSMakeCommand;
use Reedware\LaravelSMS\Contracts\Factory as FactoryContract;
use Reedware\LaravelSMS\Contracts\MessageQueue as MessageQueueContract;
use Reedware\LaravelSMS\Contracts\Provider as ProviderContract;
Expand All @@ -17,19 +18,16 @@ class SMSServiceProvider extends ServiceProvider implements DeferrableProvider
*/
public function register()
{
$this->registerTexter();

$this->mergeConfigFrom(
$this->configPath(), 'sms'
);
$this->registerServices();
$this->registerConfiguration();
}

/**
* Register the sms instance.
* Registers the package services.
*
* @return void
*/
protected function registerTexter()
protected function registerServices()
{
$this->app->singleton('sms.manager', function ($app) {
return new SMSManager($app);
Expand All @@ -39,25 +37,71 @@ protected function registerTexter()
return $app->make('sms.manager')->driver();
});

$this->app->alias('sms.manager', SMSManager::class);
$this->app->alias('sms.manager', FactoryContract::class);
$this->app->alias('sms', Provider::class);
$this->app->alias('sms', ProviderContract::class);
$this->app->alias('sms', MessageQueueContract::class);
$allAliases = [
'sms' => [Provider::class, ProviderContract::class, MessageQueueContract::class],
'sms.manager' => [SMSManager::class, FactoryContract::class]
];

foreach($allAliases as $key => $aliases) {
foreach($aliases as $alias) {
$this->app->alias($key, $aliases);
}
}
}

/**
* Bootstrap any application services.
* Registers the package configuration.
*
* @return void
*/
protected function registerConfiguration()
{
$this->mergeConfigFrom(
$this->configPath(), 'sms'
);
}

/**
* Bootstraps the package services.
*
* @return void
*/
public function boot()
{
$this->publishConfiguration();
$this->registerCommands();
}

/**
* Publishes the package configuration.
*
* @return void
*/
protected function publishConfiguration()
{
$this->publishes([
$this->configPath() => $this->app->configPath('sms.php'),
]);
}

/**
* Registers the package commands.
*
* @return void
*/
protected function registerCommands()
{
if(!$this->app->runningInConsole()) {
return;
}

$this->app->singleton('command.sms.make', function($app) {
return new SMSMakeCommand($app['files']);
});

$this->app->commands(['command.sms.make']);
}

/**
* Returns the path to the local configuration.
*
Expand Down
33 changes: 33 additions & 0 deletions stubs/sms.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace DummyNamespace;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;
use Reedware\LaravelSMS\Textable;

class DummyClass extends Textable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('view.name');
}
}

0 comments on commit 1bdbd78

Please sign in to comment.