Skip to content

Commit 58e0e07

Browse files
Added Readme
Added library subclass to permit dependency injection usage.
1 parent 7304a82 commit 58e0e07

File tree

5 files changed

+108
-6
lines changed

5 files changed

+108
-6
lines changed

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
Laravel Prestashop Web Service
2+
========
3+
4+
Laravel 5 wrapper for Prestashop Web Service Library
5+
6+
Installation
7+
------------
8+
9+
Require this package with composer using the following command:
10+
11+
```shell
12+
composer require protechstudio/laravel-prestashop-webservice
13+
```
14+
15+
After updating composer, add the service provider to the `providers` array in `config/app.php`
16+
17+
```php
18+
Protechstudio\PrestashopWebService\PrestashopWebServiceProvider::class,
19+
```
20+
21+
You may also add the Facade in the `aliases` array in `config/app.php`
22+
23+
```php
24+
'Prestashop' => Protechstudio\PrestashopWebService\PrestashopWebServiceFacade::class,
25+
```
26+
27+
Finally publish the configuration file using the artisan command
28+
29+
```shell
30+
php artisan vendor:publish --provider="Protechstudio\PrestashopWebService\PrestashopWebServiceProvider"
31+
```
32+
33+
Configuration
34+
-------------
35+
36+
Open the published configuration file at `config/prestashop-webservice.php`:
37+
38+
```php
39+
return [
40+
'url' => 'http://domain.com',
41+
'token' => '',
42+
'debug' => env('APP_DEBUG', false)
43+
];
44+
```
45+
46+
Then populate the `url` field with the **root url** of the targeted Prestashop installation and `token` field with the API token obtained from Prestashop control panel in Web Service section. If `debug` is `true` Prestashop will return debug information when responding to API requests.
47+
48+
Usage
49+
-----
50+
51+
You may use the Prestashop Web Service wrapper in two ways:
52+
### Using the dependency or method injection
53+
54+
```php
55+
...
56+
use Protechstudio\PrestashopWebService\PrestashopWebService;
57+
58+
class FooController extends Controller
59+
{
60+
private $prestashop;
61+
62+
public function __construct(PrestashopWebService $prestashop)
63+
{
64+
$this->prestashop = $prestashop;
65+
}
66+
67+
public function bar()
68+
{
69+
$opt['resource'] = 'customers';
70+
$xml=$this->prestashop->get($opt);
71+
}
72+
}
73+
```
74+
### Using the Facade
75+
76+
```php
77+
...
78+
use Prestashop;
79+
80+
...
81+
82+
public function bar()
83+
{
84+
$opt['resource'] = 'customers';
85+
$xml=Prestashop::get($opt);
86+
}
87+
```
88+
89+
PS Underlying library usage
90+
---------------------------
91+
92+
You may find complete documentation and tutorials regarding Prestashop Web Service Library in the [Prestashop Documentation](http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service).

src/PrestashopWebService.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Protechstudio\PrestashopWebService;
4+
5+
use PrestaShopWebservice as PSLibrary;
6+
7+
class PrestashopWebService extends PSLibrary
8+
{
9+
10+
}

src/PrestashopWebServiceFacade.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55

66
use Illuminate\Support\Facades\Facade;
7-
use PrestaShopWebservice;
87

98
class PrestashopWebServiceFacade extends Facade
109
{
1110

1211
protected static function getFacadeAccessor()
1312
{
14-
return PrestaShopWebservice::class;
13+
return PrestashopWebService::class;
1514
}
1615

1716
}

src/PrestashopWebServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Protechstudio\PrestashopWebService;
44

55
use Illuminate\Support\ServiceProvider;
6-
use PrestaShopWebservice;
6+
77

88
class PrestashopWebServiceProvider extends ServiceProvider
99
{
@@ -27,8 +27,8 @@ public function register()
2727
{
2828
$this->registerConfig();
2929

30-
$this->app->singleton(PrestaShopWebservice::class, function () {
31-
return new PrestaShopWebservice(config('prestashop-webservice.url'),
30+
$this->app->singleton(PrestashopWebService::class, function () {
31+
return new PrestashopWebService(config('prestashop-webservice.url'),
3232
config('prestashop-webservice.token', config('prestashop-webservice.debug')));
3333
});
3434
}

tests/PrestashopWebServiceTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Illuminate\Foundation\Testing\WithoutMiddleware;
44
use Illuminate\Foundation\Testing\DatabaseMigrations;
55
use Illuminate\Foundation\Testing\DatabaseTransactions;
6+
use Protechstudio\PrestashopWebService\PrestashopWebService;
67

78
class PrestashopWebServiceTest extends TestCase
89
{
@@ -12,6 +13,6 @@ class PrestashopWebServiceTest extends TestCase
1213
*/
1314
public function it_is_correctly_installed()
1415
{
15-
$this->assertInstanceOf(PrestaShopWebservice::class, Prestashop::getFacadeRoot());
16+
$this->assertInstanceOf(PrestashopWebService::class, Prestashop::getFacadeRoot());
1617
}
1718
}

0 commit comments

Comments
 (0)