|
1 | 1 | # Salesforce REST API Client for Laravel <img align="right" src="https://raw.githubusercontent.com/omniphx/images/master/Forrest.png"> |
2 | 2 |
|
3 | | -[](http://laravel.com) |
| 3 | +[](http://laravel.com) |
4 | 4 | [](https://packagist.org/packages/omniphx/forrest) |
5 | 5 | [](https://packagist.org/packages/omniphx/forrest) |
6 | 6 | [](https://packagist.org/packages/omniphx/forrest) |
@@ -597,3 +597,76 @@ $forrest2->authenticate(); |
597 | 597 | ``` |
598 | 598 |
|
599 | 599 | For more information about Guzzle responses and event listeners, refer to their [documentation](http://guzzle.readthedocs.org). |
| 600 | + |
| 601 | +### Creating a custom store |
| 602 | + |
| 603 | +If you'd prefer to use storage other than `session`, `cache` or `object`, you can implement a custom implementation by configuring a custom class instance in `storage.type`: |
| 604 | + |
| 605 | +```php |
| 606 | +'storage' => [ |
| 607 | + 'type' => App\Storage\CustomStorage::class, |
| 608 | +], |
| 609 | +``` |
| 610 | + |
| 611 | +You class can be named anything but it must implement `Omniphx\Forrest\Interfaces\StorageInterface`: |
| 612 | + |
| 613 | +```php |
| 614 | +<?php |
| 615 | + |
| 616 | +namespace App\Storage; |
| 617 | + |
| 618 | +use Session; |
| 619 | +use Omniphx\Forrest\Exceptions\MissingKeyException; |
| 620 | +use Omniphx\Forrest\Interfaces\StorageInterface; |
| 621 | + |
| 622 | +class CustomStorage implements StorageInterface |
| 623 | +{ |
| 624 | + public $path; |
| 625 | + |
| 626 | + public function __construct() |
| 627 | + { |
| 628 | + $this->path = 'app.custom.path'; |
| 629 | + } |
| 630 | + |
| 631 | + /** |
| 632 | + * Store into session. |
| 633 | + * |
| 634 | + * @param $key |
| 635 | + * @param $value |
| 636 | + * |
| 637 | + * @return void |
| 638 | + */ |
| 639 | + public function put($key, $value) |
| 640 | + { |
| 641 | + return Session::put($this->path.$key, $value); |
| 642 | + } |
| 643 | + |
| 644 | + /** |
| 645 | + * Get from session. |
| 646 | + * |
| 647 | + * @param $key |
| 648 | + * |
| 649 | + * @return mixed |
| 650 | + */ |
| 651 | + public function get($key) |
| 652 | + { |
| 653 | + if(!$this->has($key)) { |
| 654 | + throw new MissingKeyException(sprintf('No value for requested key: %s', $key)); |
| 655 | + } |
| 656 | + |
| 657 | + return Session::get($this->path.$key); |
| 658 | + } |
| 659 | + |
| 660 | + /** |
| 661 | + * Check if storage has a key. |
| 662 | + * |
| 663 | + * @param $key |
| 664 | + * |
| 665 | + * @return bool |
| 666 | + */ |
| 667 | + public function has($key) |
| 668 | + { |
| 669 | + return Session::has($this->path.$key); |
| 670 | + } |
| 671 | +} |
| 672 | +``` |
0 commit comments