From 97ccd41bbf38b9a3095c3bc84c72f8d29b982c9d Mon Sep 17 00:00:00 2001 From: bgsrb88 Date: Wed, 19 Oct 2016 00:57:33 +0330 Subject: [PATCH] first commit --- README.md | 125 +++++++++++++++++++++++++++++++- composer.json | 22 ++++++ src/Facade.php | 16 ++++ src/ServiceProvider.php | 88 ++++++++++++++++++++++ src/ServiceProviderLaravel4.php | 28 +++++++ src/ServiceProviderLaravel5.php | 31 ++++++++ src/config/.gitkeep | 0 src/config/config.php | 4 + 8 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 composer.json create mode 100644 src/Facade.php create mode 100644 src/ServiceProvider.php create mode 100644 src/ServiceProviderLaravel4.php create mode 100644 src/ServiceProviderLaravel5.php create mode 100644 src/config/.gitkeep create mode 100644 src/config/config.php diff --git a/README.md b/README.md index fc1bd46..4079cf8 100644 --- a/README.md +++ b/README.md @@ -1 +1,124 @@ -# kavenegar-laravel \ No newline at end of file +# kavenegar-laravel + +## Requirements + +Laravel 4 or 5. + +## Installation + + +```sh +composer require kavenegar/laravel +``` + +## Laravel 5 + +Add the `Kavenegar\Laravel\ServiceProvider` provider to the `providers` array in `config/app.php`: + +```php +'providers' => [ + ... + Kavenegar\Laravel\ServiceProvider::class, +], +``` + +Then add the facade to your `aliases` array: + +```php +'aliases' => [ + ... + 'Kavenegar' => Kavenegar\Laravel\Facade::class, +], +``` + +Finally, publish the config file with `php artisan vendor:publish`. You'll find it at `config/kavenegar.php`. + +## Laravel 4 + +Add the `Kavenegar\Laravel\ServiceProvider` provider to the `providers` array in `app/config.php`: + +```php +'providers' => [ + ... + 'Kavenegar\Laravel\ServiceProvider', +], +``` + +Then add the facade to your `aliases` array: + +```php +'aliases' => [ + ... + 'Kavenegar' => Kavenegar\Laravel\Facade', +], +``` + +Finally, publish the config file with `php artisan config:publish kavenegar/laravel`. You'll find the config file at `app/config/packages/kavenegar/laravel/config.php`. + +## Configuration + + +## Usage +```php + +use Kavenegar as api; +try{ + $sender = "10004346"; + $message = "خدمات پیام کوتاه کاوه نگار"; + $receptor = array("09123456789","09367891011"); + $result = api->Send($sender,$receptor,$message); + if($result){ + foreach($result as $r){ + echo "messageid = $r->messageid"; + echo "message = $r->message"; + echo "status = $r->status"; + echo "statustext = $r->statustext"; + echo "sender = $r->sender"; + echo "receptor = $r->receptor"; + echo "date = $r->date"; + echo "cost = $r->cost"; + } + } +} +catch(\Kavenegar\Exceptions\ApiException $e){ + // در صورتی که خروجی وب سرویس 200 نباشد این خطا رخ می دهد + echo $e->errorMessage(); +} +catch(\Kavenegar\Exceptions\HttpException $e){ + // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد + echo $e->errorMessage(); +} + +/* +sample output +{ + "return": + { + "status":200, + "message":"تایید شد" + }, + "entries": + [ + { + "messageid":8792343, + "message":"خدمات پیام کوتاه کاوه نگار", + "status":1, + "statustext":"در صف ارسال", + "sender":"10004346", + "receptor":"09123456789", + "date":1356619709, + "cost":120 + }, + { + "messageid":8792344, + "message":"خدمات پیام کوتاه کاوه نگار", + "status":1, + "statustext":"در صف ارسال", + "sender":"10004346", + "receptor":"09367891011", + "date":1356619709, + "cost":120 + } + ] +} +*/ diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c2ac2b5 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "kavenegar/laravel", + "description": "laravel 4 and 5 kavenegar integration", + "type": "laravel-package", + "keywords": ["laravel","kavenegar","sms","api"], + "license": "MIT", + "authors": [ + { + "name" : "Kavenegar API Team", + "email": "support@kavenegar.com" + } + ], + "require": { + "kavenegar/php": "*" + }, + "autoload": { + "psr-4": { + "Kavenegar\\Laravel\\": "src/" + } + }, + "minimum-stability" : "stable" +} diff --git a/src/Facade.php b/src/Facade.php new file mode 100644 index 0000000..753e413 --- /dev/null +++ b/src/Facade.php @@ -0,0 +1,16 @@ +provider = $this->getProvider(); + } + + /** + * Bootstrap the application events. + * + * @return void + */ + public function boot() + { + return $this->provider->boot(); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + return $this->provider->register(); + } + + /** + * Return the service provider for the particular Laravel version. + * + * @return mixed + */ + private function getProvider() + { + $app = $this->app; + + $version = intval($app::VERSION); + + switch ($version) { + case 4: + return new ServiceProviderLaravel4($app); + + case 5: + return new ServiceProviderLaravel5($app); + + default: + throw new RuntimeException('Your version of Laravel is not supported'); + } + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return ['kavenegar']; + } +} diff --git a/src/ServiceProviderLaravel4.php b/src/ServiceProviderLaravel4.php new file mode 100644 index 0000000..32fe07e --- /dev/null +++ b/src/ServiceProviderLaravel4.php @@ -0,0 +1,28 @@ +package('kavenegar/laravel', null, __DIR__); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app['kavenegar'] = $this->app->share(function ($app) { + return new \Kavenegar\KavenegarApi($app['config']->get('kavenegar::apikey')); + }); + } +} diff --git a/src/ServiceProviderLaravel5.php b/src/ServiceProviderLaravel5.php new file mode 100644 index 0000000..d3f438c --- /dev/null +++ b/src/ServiceProviderLaravel5.php @@ -0,0 +1,31 @@ +publishes([__DIR__.'/config/config.php' => config_path('kavenegar.php')]); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom(__DIR__.'/config/config.php', 'kavenegar'); + $this->app['kavenegar'] = $this->app->share(function ($app) { + return new KavenegarApi($app['config']->get('kavenegar.apikey')); + }); + } +} diff --git a/src/config/.gitkeep b/src/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/config/config.php b/src/config/config.php new file mode 100644 index 0000000..2cdb4e1 --- /dev/null +++ b/src/config/config.php @@ -0,0 +1,4 @@ + '', +]; \ No newline at end of file