| 1 |
<?php |
| 2 |
/** |
| 3 |
* Client Service Provider Class |
| 4 |
* |
| 5 |
* @package Easy_Invoice |
| 6 |
* @subpackage Providers |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace EasyInvoice\Providers; |
| 10 |
|
| 11 |
use EasyInvoice\Interfaces\ClientRepositoryInterface; |
| 12 |
use EasyInvoice\Repositories\ClientRepository; |
| 13 |
|
| 14 |
/** |
| 15 |
* ClientServiceProvider Class |
| 16 |
* |
| 17 |
* Handles registration of client-related services. |
| 18 |
*/ |
| 19 |
class ClientServiceProvider { |
| 20 |
/** |
| 21 |
* The repository instance |
| 22 |
* |
| 23 |
* @var ClientRepositoryInterface |
| 24 |
*/ |
| 25 |
protected static $repository = null; |
| 26 |
|
| 27 |
/** |
| 28 |
* Register client services |
| 29 |
*/ |
| 30 |
public function register() { |
| 31 |
// Register actions and filters |
| 32 |
add_action('after_setup_theme', [$this, 'registerClientRole']); |
| 33 |
|
| 34 |
// Register client repository |
| 35 |
$this->registerClientRepository(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Register client role if it doesn't exist |
| 40 |
*/ |
| 41 |
public function registerClientRole() { |
| 42 |
$role = get_role('customer'); |
| 43 |
|
| 44 |
if (!$role) { |
| 45 |
add_role('customer', __('Customer', 'easy-invoice'), [ |
| 46 |
'read' => true, |
| 47 |
]); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Register client repository |
| 53 |
*/ |
| 54 |
protected function registerClientRepository() { |
| 55 |
// Create and store the repository instance |
| 56 |
self::$repository = new ClientRepository(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Get the client repository |
| 61 |
* |
| 62 |
* @return ClientRepositoryInterface The client repository |
| 63 |
*/ |
| 64 |
public static function getClientRepository() { |
| 65 |
// Create the repository if it doesn't exist |
| 66 |
if (self::$repository === null) { |
| 67 |
self::$repository = new ClientRepository(); |
| 68 |
} |
| 69 |
|
| 70 |
return self::$repository; |
| 71 |
} |
| 72 |
} |