| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Api; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
final class Api |
| 8 |
{ |
| 9 |
|
| 10 |
private $app; |
| 11 |
|
| 12 |
public function __construct($app) |
| 13 |
{ |
| 14 |
$this->app = $app; |
| 15 |
$this->register(); |
| 16 |
} |
| 17 |
|
| 18 |
private function register() |
| 19 |
{ |
| 20 |
foreach ($this->getClasses() as $key => $class) { |
| 21 |
$this->app->singleton($this->key($key), function($app) use ($class) { |
| 22 |
return new FSApi($app->make($class)); |
| 23 |
}); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
private function getClasses() |
| 28 |
{ |
| 29 |
return require_once( |
| 30 |
$this->app['path.app'].'Api/config.php' |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
private function key($key) |
| 35 |
{ |
| 36 |
return '__fluentsupport_api__.' . $key; |
| 37 |
} |
| 38 |
|
| 39 |
public function __get($key) |
| 40 |
{ |
| 41 |
try { |
| 42 |
return $this->app[$this->key($key)]; |
| 43 |
} catch(\Exception $e) { |
| 44 |
throw new \Exception(sprintf('The %s doesn\'t exist in FluentSupportApi.', esc_html($key))); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|