|
1
|
|
|
<?php |
|
2
|
|
|
namespace nstdio\svg\traits; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use nstdio\svg\util\transform\TransformInterface; |
|
6
|
|
|
|
|
7
|
|
|
trait TransformTrait |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var TransformInterface |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $transformImpl; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @inheritdoc |
|
16
|
|
|
*/ |
|
17
|
|
|
public function result() |
|
18
|
|
|
{ |
|
19
|
|
|
return $this->transformImpl->result(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritdoc |
|
24
|
|
|
*/ |
|
25
|
|
|
public function setArgumentDelimiter($delim) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->transformImpl->setArgumentDelimiter($delim); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritdoc |
|
32
|
|
|
* @param int $angle |
|
33
|
|
|
*/ |
|
34
|
4 |
|
public function rotate($angle, $cx = null, $cy = null) |
|
35
|
|
|
{ |
|
36
|
4 |
|
$this->setTransformAttribute($this->transformImpl->rotate($angle, $cx, $cy)); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
4 |
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @inheritdoc |
|
43
|
|
|
*/ |
|
44
|
|
|
public function translate($x, $y = null) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->setTransformAttribute($this->transformImpl->translate($x, $y)); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritdoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function scale($x, $y = null) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->setTransformAttribute($this->transformImpl->scale($x, $y)); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritdoc |
|
63
|
|
|
*/ |
|
64
|
|
|
public function skewX($x) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->setTransformAttribute($this->transformImpl->skewX($x)); |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @inheritdoc |
|
73
|
|
|
*/ |
|
74
|
|
|
public function skewY($y) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->setTransformAttribute($this->transformImpl->skewY($y)); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @inheritdoc |
|
83
|
|
|
*/ |
|
84
|
|
|
public function matrix(array $matrix) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->setTransformAttribute($this->transformImpl->matrix($matrix)); |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @inheritdoc |
|
93
|
|
|
*/ |
|
94
|
|
|
public function compact() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->setTransformAttribute($this->transformImpl->compact()); |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @inheritdoc |
|
103
|
|
|
*/ |
|
104
|
|
|
public function toMatrix() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->setTransformAttribute($this->transformImpl->toMatrix()); |
|
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @inheritdoc |
|
113
|
|
|
* @return $this |
|
114
|
|
|
*/ |
|
115
|
|
|
public function clearTransformation() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->transformImpl->clearTransformation(); |
|
118
|
|
|
$this->setTransformAttribute(''); |
|
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
return $this; |
|
121
|
|
|
} |
|
122
|
|
|
} |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.