@@ -22,18 +22,18 @@ |
||
22 | 22 | |
23 | 23 | class FileLoggerFactory implements LoggerFactory |
24 | 24 | { |
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - private $filePath; |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + private $filePath; |
|
29 | 29 | |
30 | - public function __construct(string $filePath) |
|
31 | - { |
|
32 | - $this->filePath = $filePath; |
|
33 | - } |
|
30 | + public function __construct(string $filePath) |
|
31 | + { |
|
32 | + $this->filePath = $filePath; |
|
33 | + } |
|
34 | 34 | |
35 | - public function createLogger(): LoggerInterface |
|
36 | - { |
|
37 | - return new FileLogger($this->filePath); |
|
38 | - } |
|
35 | + public function createLogger(): LoggerInterface |
|
36 | + { |
|
37 | + return new FileLogger($this->filePath); |
|
38 | + } |
|
39 | 39 | } |
@@ -10,19 +10,19 @@ |
||
10 | 10 | |
11 | 11 | class FactoryMethodTest extends TestCase |
12 | 12 | { |
13 | - public function testCanCreateStdoutLogging() |
|
14 | - { |
|
15 | - $loggerFactory = new StdoutLoggerFactory(); |
|
16 | - $logger = $loggerFactory->createLogger(); |
|
13 | + public function testCanCreateStdoutLogging() |
|
14 | + { |
|
15 | + $loggerFactory = new StdoutLoggerFactory(); |
|
16 | + $logger = $loggerFactory->createLogger(); |
|
17 | 17 | |
18 | - $this->assertInstanceOf(StdoutLogger::class, $logger); |
|
19 | - } |
|
18 | + $this->assertInstanceOf(StdoutLogger::class, $logger); |
|
19 | + } |
|
20 | 20 | |
21 | - public function testCanCreateFileLogging() |
|
22 | - { |
|
23 | - $loggerFactory = new FileLoggerFactory(sys_get_temp_dir()); |
|
24 | - $logger = $loggerFactory->createLogger(); |
|
21 | + public function testCanCreateFileLogging() |
|
22 | + { |
|
23 | + $loggerFactory = new FileLoggerFactory(sys_get_temp_dir()); |
|
24 | + $logger = $loggerFactory->createLogger(); |
|
25 | 25 | |
26 | - $this->assertInstanceOf(FileLogger::class, $logger); |
|
27 | - } |
|
26 | + $this->assertInstanceOf(FileLogger::class, $logger); |
|
27 | + } |
|
28 | 28 | } |
@@ -22,8 +22,8 @@ |
||
22 | 22 | |
23 | 23 | class StdoutLogger implements LoggerInterface |
24 | 24 | { |
25 | - public function log(string $message) |
|
26 | - { |
|
27 | - echo $message; |
|
28 | - } |
|
25 | + public function log(string $message) |
|
26 | + { |
|
27 | + echo $message; |
|
28 | + } |
|
29 | 29 | } |
@@ -22,5 +22,5 @@ |
||
22 | 22 | |
23 | 23 | interface LoggerInterface |
24 | 24 | { |
25 | - public function log(string $message); |
|
25 | + public function log(string $message); |
|
26 | 26 | } |
@@ -22,18 +22,18 @@ |
||
22 | 22 | |
23 | 23 | class FileLogger implements LoggerInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - private $filePath; |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + private $filePath; |
|
29 | 29 | |
30 | - public function __construct(string $filePath) |
|
31 | - { |
|
32 | - $this->filePath = $filePath; |
|
33 | - } |
|
30 | + public function __construct(string $filePath) |
|
31 | + { |
|
32 | + $this->filePath = $filePath; |
|
33 | + } |
|
34 | 34 | |
35 | - public function log(string $message) |
|
36 | - { |
|
37 | - file_put_contents($this->filePath, $message . PHP_EOL, FILE_APPEND); |
|
38 | - } |
|
35 | + public function log(string $message) |
|
36 | + { |
|
37 | + file_put_contents($this->filePath, $message . PHP_EOL, FILE_APPEND); |
|
38 | + } |
|
39 | 39 | } |
@@ -22,8 +22,8 @@ |
||
22 | 22 | |
23 | 23 | class StdoutLoggerFactory implements LoggerFactory |
24 | 24 | { |
25 | - public function createLogger(): LoggerInterface |
|
26 | - { |
|
27 | - return new StdoutLogger(); |
|
28 | - } |
|
25 | + public function createLogger(): LoggerInterface |
|
26 | + { |
|
27 | + return new StdoutLogger(); |
|
28 | + } |
|
29 | 29 | } |
@@ -27,61 +27,61 @@ |
||
27 | 27 | |
28 | 28 | class Mmanager |
29 | 29 | { |
30 | - protected $user_id; |
|
30 | + protected $user_id; |
|
31 | 31 | |
32 | - public function __construct() { |
|
33 | - $this->Customer = new CustomerRepository(new CIQueryBuilder); |
|
34 | - $this->Invoice = new InvoiceRepository(new CIQueryBuilder); |
|
35 | - $this->user_id = get_user_id(); |
|
36 | - } |
|
37 | - public function setUserID($user_id = null) { |
|
38 | - $this->user_id = isset($user_id) ? $user_id : get_user_id(); |
|
39 | - return $this; |
|
40 | - } |
|
41 | - public function getUserID() |
|
42 | - { |
|
43 | - return $this->user_id; |
|
44 | - } |
|
45 | - public static function getUrl($request_url) { |
|
46 | - $ch = curl_init(); |
|
47 | - curl_setopt($ch, CURLOPT_URL, $request_url); |
|
48 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
49 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
50 | - $response = curl_exec($ch); |
|
51 | - curl_close($ch); |
|
32 | + public function __construct() { |
|
33 | + $this->Customer = new CustomerRepository(new CIQueryBuilder); |
|
34 | + $this->Invoice = new InvoiceRepository(new CIQueryBuilder); |
|
35 | + $this->user_id = get_user_id(); |
|
36 | + } |
|
37 | + public function setUserID($user_id = null) { |
|
38 | + $this->user_id = isset($user_id) ? $user_id : get_user_id(); |
|
39 | + return $this; |
|
40 | + } |
|
41 | + public function getUserID() |
|
42 | + { |
|
43 | + return $this->user_id; |
|
44 | + } |
|
45 | + public static function getUrl($request_url) { |
|
46 | + $ch = curl_init(); |
|
47 | + curl_setopt($ch, CURLOPT_URL, $request_url); |
|
48 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
|
49 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
50 | + $response = curl_exec($ch); |
|
51 | + curl_close($ch); |
|
52 | 52 | |
53 | - return $response; |
|
54 | - } |
|
55 | - public static function isValidLicense() { |
|
56 | - $request_url = 'https://www.mmanager.fr/process.php?r=cl&rf='.base_url().'&pc='.get_option('purchase_code'); |
|
57 | - return self::getUrl($request_url); |
|
58 | - } |
|
59 | - public static function expire() { |
|
60 | - $validity = self::isValidLicense(); |
|
61 | - if ($validity == 1) { |
|
62 | - return '<span style="color:green">'. strtoupper(__('label_never')).'</span>'; |
|
63 | - } else { |
|
64 | - return '<span style="color:red">'.strtoupper(__('message_contact_reseller_support')).'</span>'; |
|
65 | - } |
|
66 | - } |
|
67 | - public static function LicenseDetails() { |
|
68 | - return '<p><span><strong>'. __('label_license_details'). '</strong></span><ul><li>'.__('label_domain'). rtrim(base_url(), '/').'</li><li>Status: '. is_valid_license(self::isValidLicense()).'</li><li>Expires: '. self::expire().'</li></ul></em></p>'; |
|
69 | - } |
|
70 | - public static function render($module, $view_file, $data = null, $return = false) { |
|
71 | - return __render($module, $view_file, $data, $return); |
|
72 | - } |
|
73 | - public static function write_log($log_msg, $folder, $extension) |
|
74 | - { |
|
75 | - if (!file_exists($folder)) |
|
76 | - { |
|
77 | - // create directory. |
|
78 | - mkdir($folder, 0777, true); |
|
79 | - } |
|
80 | - $filePath = $folder.'/log-' . date('Y-m-d') . '.'.$extension; |
|
53 | + return $response; |
|
54 | + } |
|
55 | + public static function isValidLicense() { |
|
56 | + $request_url = 'https://www.mmanager.fr/process.php?r=cl&rf='.base_url().'&pc='.get_option('purchase_code'); |
|
57 | + return self::getUrl($request_url); |
|
58 | + } |
|
59 | + public static function expire() { |
|
60 | + $validity = self::isValidLicense(); |
|
61 | + if ($validity == 1) { |
|
62 | + return '<span style="color:green">'. strtoupper(__('label_never')).'</span>'; |
|
63 | + } else { |
|
64 | + return '<span style="color:red">'.strtoupper(__('message_contact_reseller_support')).'</span>'; |
|
65 | + } |
|
66 | + } |
|
67 | + public static function LicenseDetails() { |
|
68 | + return '<p><span><strong>'. __('label_license_details'). '</strong></span><ul><li>'.__('label_domain'). rtrim(base_url(), '/').'</li><li>Status: '. is_valid_license(self::isValidLicense()).'</li><li>Expires: '. self::expire().'</li></ul></em></p>'; |
|
69 | + } |
|
70 | + public static function render($module, $view_file, $data = null, $return = false) { |
|
71 | + return __render($module, $view_file, $data, $return); |
|
72 | + } |
|
73 | + public static function write_log($log_msg, $folder, $extension) |
|
74 | + { |
|
75 | + if (!file_exists($folder)) |
|
76 | + { |
|
77 | + // create directory. |
|
78 | + mkdir($folder, 0777, true); |
|
79 | + } |
|
80 | + $filePath = $folder.'/log-' . date('Y-m-d') . '.'.$extension; |
|
81 | 81 | |
82 | - $loggerFactory = new FileLoggerFactory($filePath); |
|
83 | - $logger = $loggerFactory->createLogger(); |
|
82 | + $loggerFactory = new FileLoggerFactory($filePath); |
|
83 | + $logger = $loggerFactory->createLogger(); |
|
84 | 84 | |
85 | - $logger->log($log_msg); |
|
86 | - } |
|
85 | + $logger->log($log_msg); |
|
86 | + } |
|
87 | 87 | } |