1 | <?php |
||
12 | class Usher |
||
13 | { |
||
14 | const DEFAULT_MAX_TRIES = 100000; |
||
15 | |||
16 | /** @var int */ |
||
17 | protected $maxTries; |
||
18 | |||
19 | /** @var \SixtyNine\Cloud\SimpleMask */ |
||
20 | protected $mask; |
||
21 | |||
22 | /** @var \SixtyNine\Cloud\Placer\PlacerInterface */ |
||
23 | protected $placer; |
||
24 | |||
25 | /** @var \SixtyNine\Cloud\FontMetrics */ |
||
26 | protected $metrics; |
||
27 | |||
28 | /** |
||
29 | * @param int $imgWidth |
||
30 | * @param int $imgHeight |
||
31 | * @param PlacerInterface $placer |
||
32 | * @param FontMetrics $metrics |
||
33 | * @param int $maxTries |
||
34 | */ |
||
35 | 4 | public function __construct( |
|
49 | |||
50 | /** |
||
51 | * @param string $word |
||
52 | * @param string $font |
||
53 | * @param int $size |
||
54 | * @param int $angle |
||
55 | * @return bool|Box |
||
56 | */ |
||
57 | 4 | public function getPlace($word, $font, $size, $angle) |
|
58 | { |
||
59 | 4 | $bounds = new Box(0, 0, $this->imgWidth, $this->imgHeight); |
|
60 | 4 | $box = $this->metrics->calculateSize($word, $font, $size, $angle); |
|
61 | 4 | $place = $this->searchPlace($bounds, $box); |
|
62 | |||
63 | 4 | if ($place) { |
|
64 | 4 | $this->mask->add($place->getPosition(), $box); |
|
65 | 4 | return $place; |
|
66 | } |
||
67 | |||
68 | return false; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Search a free place for a new box. |
||
73 | * @param \SixtyNine\Cloud\Model\Box $bounds |
||
74 | * @param \SixtyNine\Cloud\Model\Box $box |
||
75 | * @return bool|Box |
||
76 | */ |
||
77 | 4 | protected function searchPlace(Box $bounds, Box $box) |
|
107 | } |
||
108 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: