PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.16.0
GiveWP – Donation Plugin and Fundraising Platform v2.16.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
71 lines 1.4 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\LogType;
6 use Give\Log\ValueObjects\LogCategory;
7
8 /**
9 * Class LogFactory
10 * @package Give\Log
11 *
12 * @since 2.10.0
13 */
14 class LogFactory {
15 /**
16 * Make LogModel instance
17 *
18 * @param string $type
19 * @param string $message
20 * @param string $category
21 * @param string $source
22 * @param array $context
23 * @param int|null $logId
24 * @param string|null $date
25 *
26 * @return LogModel
27 */
28 public static function make( $type, $message, $category, $source, $context = [], $logId = null, $date = null ) {
29 return new LogModel( $type, $message, $category, $source, $context, $logId, $date );
30 }
31
32 /**
33 * Make LogModel instance from array of data
34 *
35 * @param array $data
36 *
37 * @return LogModel
38 */
39 public static function makeFromArray( $data ) {
40 // Get default
41 $data = array_merge( static::getDefaults(), $data );
42
43 return new LogModel(
44 $data['type'],
45 $data['message'],
46 $data['category'],
47 $data['source'],
48 $data['context'],
49 $data['id'],
50 $data['date']
51 );
52 }
53
54 /**
55 * Get log default fields array
56 *
57 * @return array
58 */
59 public static function getDefaults() {
60 return [
61 'type' => LogType::getDefault(),
62 'message' => esc_html__( 'Something went wrong', 'give' ),
63 'category' => LogCategory::getDefault(),
64 'source' => esc_html__( 'Give Core', 'give' ),
65 'context' => [],
66 'id' => null,
67 'date' => date( 'Y-m-d H:i:s' ),
68 ];
69 }
70 }
71