Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bgsrb committed Oct 18, 2016
1 parent 189fe08 commit 97ccd41
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 1 deletion.
125 changes: 124 additions & 1 deletion README.md
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
}
]
}
*/
22 changes: 22 additions & 0 deletions composer.json
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"
}
16 changes: 16 additions & 0 deletions src/Facade.php
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';
}
}
88 changes: 88 additions & 0 deletions src/ServiceProvider.php
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'];
}
}
28 changes: 28 additions & 0 deletions src/ServiceProviderLaravel4.php
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'));
});
}
}
31 changes: 31 additions & 0 deletions src/ServiceProviderLaravel5.php
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 added src/config/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
return [
'apikey' => '',
];

0 comments on commit 97ccd41

Please sign in to comment.