1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPAlgorithms\Dijkstra; |
4
|
|
|
|
5
|
|
|
use PHPAlgorithms\Dijkstra\Exceptions\PointException; |
6
|
|
|
use PHPAlgorithms\GraphTools\AbstractPoint; |
7
|
|
|
use PHPAlgorithms\GraphTools\Traits\MagicGet; |
8
|
|
|
|
9
|
|
|
class Point extends AbstractPoint |
10
|
|
|
{ |
11
|
|
|
use MagicGet; |
12
|
|
|
|
13
|
|
|
private $label = ''; |
14
|
|
|
private $relations = array(); |
15
|
|
|
|
16
|
|
|
public function __construct($label = null) |
17
|
|
|
{ |
18
|
|
|
if (!is_null($label)) { |
19
|
|
|
$this->setLabel($label); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function __isset($name) |
24
|
|
|
{ |
25
|
|
|
return isset($this->{$name}); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function addDoubleRelation() |
29
|
|
|
{ |
30
|
|
|
switch (func_num_args()) { |
31
|
|
|
case 1: |
32
|
|
|
$arg = func_get_arg(0); |
33
|
|
|
|
34
|
|
|
$this->addRelation($arg); |
35
|
|
|
if ($arg->from === $this) { |
36
|
|
|
$arg->to |
37
|
|
|
->addRelation($arg); |
38
|
|
|
} else { |
39
|
|
|
$arg->from |
40
|
|
|
->addRelation($arg); |
41
|
|
|
} |
42
|
|
|
break; |
43
|
|
|
case 2: |
44
|
|
|
$this->addRelation(func_get_arg(0), func_get_arg(1)); |
45
|
|
|
func_get_arg(0)->addRelation($this, func_get_arg(1)); |
46
|
|
|
break; |
47
|
|
|
default: |
48
|
|
|
throw new PointException('Wrong arguments sent to addRelation() method'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function addRelation() |
55
|
|
|
{ |
56
|
|
|
switch (func_num_args()) { |
57
|
|
|
case 1: |
58
|
|
|
$this->addRelationObject(func_get_arg(0)); |
59
|
|
|
break; |
60
|
|
|
case 2: |
61
|
|
|
$this->addRelationPointDistance(func_get_arg(0), func_get_arg(1)); |
62
|
|
|
break; |
63
|
|
|
default: |
64
|
|
|
throw new PointException('Wrong arguments sent to addRelation() method'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function addRelationObject(Relation $relation) |
71
|
|
|
{ |
72
|
|
|
if (($this !== $relation->from) && ($this !== $relation->to)) { |
|
|
|
|
73
|
|
|
throw new PointException('Sent relation is not match to this point'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->relations[] = $relation; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function addRelationPointDistance(Point $point, $distance) |
80
|
|
|
{ |
81
|
|
|
$this->addRelationObject(new Relation($this, $point, $distance)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setLabel($label) |
85
|
|
|
{ |
86
|
|
|
if (!is_string($label)) { |
87
|
|
|
throw new PointException('Label is not a string'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->label = $label; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.