Completed
Push — master ( 57b531...5d4578 )
by Filipe
02:14
created

AbstractEvent::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/orm package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Orm\Event;
11
12
use \League\Event\AbstractEvent as LeagueAbstractEvent;
13
use Slick\Orm\EntityInterface;
14
15
/**
16
 * Abstract ORM Event
17
 *
18
 * @package Slick\Orm\Event
19
 * @author  Filipe Silva <[email protected]>
20
 */
21
abstract class AbstractEvent extends LeagueAbstractEvent implements EventInterface
22
{
23
24
    /**
25
     * @var string
26
     */
27
    protected $entityName;
28
29
    /**
30
     * @var EntityInterface
31
     */
32
    protected $entity;
33
34
    /**
35
     * @var string
36
     */
37
    protected $action = 'none';
38
39
    /**
40
     * @var mixed
41
     */
42
    protected $params;
43
44
    /**
45
     * All ORM events are from entities
46
     *
47
     * @param EntityInterface $entity
48
     * @param mixed $params additional parameters
49
     */
50 4
    public function __construct(EntityInterface $entity, $params = null)
51
    {
52 4
        $this->setEntity($entity);
53 4
        $this->params = $params;
54 4
    }
55
56
    /**
57
     * Sets the name of the class that triggers the event
58
     *
59
     * @param string $className
60
     * @return self|EventInterface|$this
61
     */
62
    public function setEntityName($className)
63
    {
64
        $this->entityName = $className;
65
        return $this;
66
    }
67
68
    /**
69
     * Gets the entity class name that triggers the event
70
     *
71
     * @return string
72
     */
73
    public function getEntityName()
74
    {
75
        if (null == $this->entityName) {
76
            $this->setEntityName(get_class($this->getEntity()));
77
        }
78
        return $this;
79
    }
80
81
    /**
82
     * Set event's action
83
     *
84
     * @param string $action
85
     * @return self|EventInterface|$this
86
     */
87 4
    public function setAction($action)
88
    {
89 4
        $this->action = $action;
90 4
        return $this;
91
    }
92
93
    /**
94
     * Sets the entity object that triggers the event
95
     *
96
     * @param EntityInterface $entity
97
     * @return self|EventInterface|$this
98
     */
99 4
    public function setEntity(EntityInterface $entity)
100
    {
101 4
        $this->entity = $entity;
102 4
        return $this;
103
    }
104
105
    /**
106
     * Gets the entity object that triggers the event
107
     *
108
     * @return EntityInterface
109
     */
110
    public function getEntity()
111
    {
112
        return $this->entity;
113
    }
114
115
    /**
116
     * Get the event name.
117
     *
118
     * @return string
119
     */
120 4
    public function getName()
121
    {
122 4
        return $this->action;
123
    }
124
}