Completed
Push — trunk ( e8681e...314ee9 )
by SuperNova.WS
13:57
created

EntityDb::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 08.01.2018 14:46
4
 */
5
6
namespace Core;
7
8
9
use \DBAL\ActiveRecord;
10
use Traits\TContainer;
11
12
/**
13
 * Class EntityDb
14
 *
15
 * Represents in-game entity which have representation in DB (aka one or more connected ActiveRecords)
16
 *
17
 * @package Core
18
 */
19
class EntityDb extends Entity implements \IContainer {
20
  use TContainer;
21
22
  /**
23
   * @var string $_activeClass
24
   */
25
  protected $_activeClass = ''; // \\DBAL\\ActiveRecord
26
27
  /**
28
   * @var ActiveRecord $_container
29
   */
30
  protected $_container;
31
32
  /**
33
   * @return ActiveRecord
34
   */
35
  public function _getContainer() {
36
    return $this->_container;
37
  }
38
39
  /**
40
   * EntityDb constructor.
41
   *
42
   * @param int $id
43
   */
44
  public function __construct($id = 0) {
45
    $this->dbLoadRecord($id);
46
  }
47
48
  /**
49
   * @param int|float $id
50
   *
51
   * @return ActiveRecord
52
   */
53
  public function dbLoadRecord($id) {
54
    $className = $this->_activeClass;
55
    $this->_container = $className::findById($id);
56
57
    return $this->_container;
58
  }
59
60
}
61