/var/www/(Del)hsihk.com/wp-content/plugins/woocommerce/includes/gateways/mijireh/includes/Model.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php

if ( ! defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly
}

class 
Mijireh_Model {

  protected 
$_data = array();
  protected 
$_errors = array();

  
/**
   * Set the value of one of the keys in the private $_data array.
   *
   * @param string $key The key in the $_data array
   * @param string $value The value to assign to the key
   * @return boolean
   */
  
public function __set($key$value) {
    
$success false;
    if(
array_key_exists($key$this->_data)) {
      
$this->_data[$key] = $value;
      
$success true;
    }
    return 
$success;
  }

  
/**
   * Get the value for the key from the private $_data array.
   *
   * Return false if the requested key does not exist
   *
   * @param string $key The key from the $_data array
   * @return mixed
   */
  
public function __get($key) {
    
$value false;
    if(
array_key_exists($key$this->_data)) {
      
$value $this->_data[$key];
    }

    
/*
    elseif(method_exists($this, $key)) {
      $value = call_user_func_array(array($this, $key), func_get_args());
    }
    */

    
return $value;
  }

  
/**
   * Return true if the given $key in the private $_data array is set
   *
   * @param string $key
   * @return boolean
   */
  
public function __isset($key) {
    return isset(
$this->_data[$key]);
  }

  
/**
   * Set the value of the $_data array to null for the given key.
   *
   * @param string $key
   * @return void
   */
  
public function __unset($key) {
    if(
array_key_exists($key$this->_data)) {
      
$this->_data[$key] = null;
    }
  }

  
/**
   * Return the private $_data array
   *
   * @return mixed
   */
  
public function get_data() {
    return 
$this->_data;
  }

  
/**
   * Return true if the given $key exists in the private $_data array
   *
   * @param string $key
   * @return boolean
   */
  
public function field_exists($key) {
    return 
array_key_exists($key$this->_data);
  }

  public function 
copy_from(array $data) {
    foreach(
$data as $key => $value) {
      if(
array_key_exists($key$this->_data)) {
        
$this->_data[$key] = $value;
      }
    }
  }

  public function 
clear() {
    foreach(
$this->_data as $key => $value) {
      if(
$key == 'id') {
        
$this->_data[$key] = null;
      }
      else {
        
$this->_data[$key] = '';
      }
    }
  }

  public function 
add_error($error_message) {
    if(!empty(
$error_message)) {
      
$this->_errors[] = $error_message;
    }
  }

  public function 
clear_errors() {
    
$this->_errors = array();
  }

  public function 
get_errors() {
    return 
$this->_errors;
  }

  public function 
get_error_lines($glue="\n") {
    
$error_lines '';
    if(
count($this->_errors)) {
      
$error_lines implode($glue$this->_errors);
    }
    return 
$error_lines;
  }

  public function 
is_valid() {
    return 
count($this->_errors) == 0;
  }

}