-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
313 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,124 @@ | ||
# kavenegar-laravel | ||
# 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 | ||
} | ||
] | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"kavenegar/php": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Kavenegar\\Laravel\\": "src/" | ||
} | ||
}, | ||
"minimum-stability" : "stable" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Kavenegar\Laravel; | ||
|
||
class Facade extends \Illuminate\Support\Facades\Facade | ||
{ | ||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'kavenegar'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Kavenegar\Laravel; | ||
|
||
use RuntimeException; | ||
|
||
class ServiceProvider extends \Illuminate\Support\ServiceProvider | ||
{ | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* The actual provider. | ||
* | ||
* @var \Illuminate\Support\ServiceProvider | ||
*/ | ||
protected $provider; | ||
|
||
/** | ||
* Instantiate the service provider. | ||
* | ||
* @param mixed $app | ||
* @return void | ||
*/ | ||
public function __construct($app) | ||
{ | ||
parent::__construct($app); | ||
|
||
$this->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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Kavenegar\Laravel; | ||
|
||
class ServiceProviderLaravel4 extends \Illuminate\Support\ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->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')); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Kavenegar\Laravel; | ||
|
||
use Kavenegar\KavenegarApi as KavenegarApi; | ||
|
||
class ServiceProviderLaravel5 extends \Illuminate\Support\ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->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')); | ||
}); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
return [ | ||
'apikey' => '', | ||
]; |