-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.php
40 lines (32 loc) · 962 Bytes
/
shape.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class Shape {
private static $circle;
private static $clover;
private static $diamond;
private static $square;
private static $star;
private static $x;
private static $representations = ['circle' => 'o', 'clover' => '+', 'diamond' => 'v', 'square' => '#', 'star' => '*', 'x' => 'x'];
public static function shapes() {
return [self::circle(), self::clover(), self::diamond(), self::square(), self::star(), self::x()];
}
public static function __callStatic($f, array $args) {
if (!self::$$f) {
self::$$f = new Shape($f, self::$representations[$f]);
}
return self::$$f;
}
private function __construct($name, $representation) {
$this->name = $name;
$this->representation = $representation;
}
public function name() {
return $this->name;
}
public function representation() {
return $this->representation;
}
public function __toString() {
return $this->representation();
}
}