1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the webmozart/booking package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Puli\Discovery\Binding; |
13
|
|
|
|
14
|
|
|
use Puli\Discovery\Api\Binding\Binding; |
15
|
|
|
use Puli\Discovery\Api\Type\MissingParameterException; |
16
|
|
|
use Puli\Discovery\Api\Type\NoSuchParameterException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Binds a class name to a binding type. |
20
|
|
|
* |
21
|
|
|
* @since 1.0 |
22
|
|
|
* |
23
|
|
|
* @author Bernhard Schussek <[email protected]> |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
class ClassBinding extends AbstractBinding |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $className; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Creates a new class binding. |
34
|
|
|
* |
35
|
|
|
* @param string $className The fully-qualified name of the bound |
36
|
|
|
* class. |
37
|
|
|
* @param string $typeName The name of the type to bind against. |
38
|
|
|
* @param array $parameterValues The values of the parameters defined |
39
|
|
|
* for the type. |
40
|
|
|
* |
41
|
|
|
* @throws NoSuchParameterException If an invalid parameter was passed. |
42
|
|
|
* @throws MissingParameterException If a required parameter was not passed. |
43
|
|
|
*/ |
44
|
32 |
|
public function __construct($className, $typeName, array $parameterValues = array()) |
45
|
|
|
{ |
46
|
32 |
|
parent::__construct($typeName, $parameterValues); |
47
|
|
|
|
48
|
31 |
|
$this->className = $className; |
49
|
31 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns the name of the bound class. |
53
|
|
|
* |
54
|
|
|
* @return string The fully-qualified class name. |
55
|
|
|
*/ |
56
|
1 |
|
public function getClassName() |
57
|
|
|
{ |
58
|
1 |
|
return $this->className; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function equals(Binding $other) |
65
|
|
|
{ |
66
|
|
|
if (!parent::equals($other)) { |
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/* @var ClassBinding $other */ |
71
|
|
|
return $this->className === $other->className; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
14 |
|
protected function preSerialize(array &$data) |
78
|
|
|
{ |
79
|
14 |
|
parent::preSerialize($data); |
80
|
|
|
|
81
|
14 |
|
$data[] = $this->className; |
82
|
14 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
8 |
|
protected function postUnserialize(array &$data) |
88
|
|
|
{ |
89
|
8 |
|
$this->className = array_pop($data); |
90
|
|
|
|
91
|
8 |
|
parent::postUnserialize($data); |
92
|
8 |
|
} |
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.