| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\App\Api; |
| 4 |
|
| 5 |
/** |
| 6 |
* Internal PHP API Class |
| 7 |
* |
| 8 |
* Please do not use this class directly. use FluentBoardsApi($module) instead. |
| 9 |
* |
| 10 |
* @package FluentBoards\App\Api\Classes |
| 11 |
* |
| 12 |
* @version 1.0.0 |
| 13 |
*/ |
| 14 |
|
| 15 |
final class Api |
| 16 |
{ |
| 17 |
public function __construct($app) |
| 18 |
{ |
| 19 |
$this->app = $app; |
| 20 |
$this->register(); |
| 21 |
} |
| 22 |
|
| 23 |
private function register() |
| 24 |
{ |
| 25 |
foreach ($this->getClasses() as $key => $class) { |
| 26 |
$this->app->singleton($this->key($key), function($app) use ($class) { |
| 27 |
return new FBSApi($app->make($class)); |
| 28 |
}); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
private function getClasses() |
| 33 |
{ |
| 34 |
return require_once( |
| 35 |
$this->app['path.app'].'Api/config.php' |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
private function key($key) |
| 40 |
{ |
| 41 |
return '__fluentboards_api__.' . $key; |
| 42 |
} |
| 43 |
|
| 44 |
public function __get($key) |
| 45 |
{ |
| 46 |
try { |
| 47 |
return $this->app[$this->key($key)]; |
| 48 |
} catch(\Exception $e) { |
| 49 |
throw new \Exception("The '$key' doesn't exist in FluentBoardsApi."); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|