PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.11.0
GiveWP – Donation Plugin and Fundraising Platform v4.11.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Log / LogFactory.php

LogFactory.php in GiveWP – Donation Plugin and Fundraising Platform 4.11.0, at src/Log/LogFactory.php

75 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Log;
4
5 use Give\Log\ValueObjects\LogCategory;
6 use Give\Log\ValueObjects\LogType;
7
8 /**
9 * Class LogFactory
10 * @package Give\Log
11 *
12 * @since 2.10.0
13 */
14 class LogFactory
15 {
16 /**
17 * Make LogModel instance
18 *
19 * @param string $type
20 * @param string $message
21 * @param string $category
22 * @param string $source
23 * @param array $context
24 * @param int|null $logId
25 * @param string|null $date
26 *
27 * @return LogModel
28 */
29 public static function make($type, $message, $category, $source, $context = [], $logId = null, $date = null)
30 {
31 return new LogModel($type, $message, $category, $source, $context, $logId, $date);
32 }
33
34 /**
35 * Make LogModel instance from array of data
36 *
37 * @param array $data
38 *
39 * @return LogModel
40 */
41 public static function makeFromArray($data)
42 {
43 // Get default
44 $data = array_merge(static::getDefaults(), $data);
45
46 return new LogModel(
47 $data['type'],
48 $data['message'],
49 $data['category'],
50 $data['source'],
51 $data['context'],
52 $data['id'],
53 $data['date']
54 );
55 }
56
57 /**
58 * Get log default fields array
59 *
60 * @return array
61 */
62 public static function getDefaults()
63 {
64 return [
65 'type' => LogType::getDefault(),
66 'message' => esc_html__('Something went wrong', 'give'),
67 'category' => LogCategory::getDefault(),
68 'source' => esc_html__('Give Core', 'give'),
69 'context' => [],
70 'id' => null,
71 'date' => date('Y-m-d H:i:s'),
72 ];
73 }
74 }
75