1 | <?php |
||
20 | class MatchFormCreator extends ModelFormCreator |
||
21 | { |
||
22 | /** |
||
23 | * {@inheritdoc} |
||
24 | */ |
||
25 | 1 | protected function build($builder) |
|
26 | { |
||
27 | 1 | $durations = \Service::getParameter('bzion.league.duration'); |
|
28 | 1 | foreach ($durations as $duration => &$value) { |
|
29 | 1 | $durations[$duration] = $duration; |
|
30 | } |
||
31 | |||
32 | return $builder |
||
33 | 1 | ->add('first_team', new MatchTeamType(), array( |
|
34 | 1 | 'disableTeam' => $this->isEdit() && $this->editing->isOfficial() |
|
|
|||
35 | )) |
||
36 | 1 | ->add('second_team', new MatchTeamType(), array( |
|
37 | 1 | 'disableTeam' => $this->isEdit() && $this->editing->isOfficial() |
|
38 | )) |
||
39 | 1 | ->add('duration', 'choice', array( |
|
40 | 1 | 'choices' => $durations, |
|
41 | 1 | 'constraints' => new NotBlank(), |
|
42 | 'expanded' => true |
||
43 | )) |
||
44 | 1 | ->add('server_address', 'text', array( |
|
45 | 1 | 'required' => false, |
|
46 | 'attr' => array('placeholder' => 'brad.guleague.org:5100'), |
||
47 | )) |
||
48 | 1 | ->add('time', new DatetimeWithTimezoneType(), array( |
|
49 | 'constraints' => array( |
||
50 | 1 | new NotBlank(), |
|
51 | 1 | new LessThan(array( |
|
52 | 1 | 'value' => \TimeDate::now()->addMinutes(10), |
|
53 | 1 | 'message' => 'The timestamp of the match must not be in the future' |
|
54 | )) |
||
55 | ), |
||
56 | 1 | 'data' => ($this->isEdit()) |
|
57 | ? $this->editing->getTimestamp()->setTimezone(\Controller::getMe()->getTimezone()) |
||
58 | 1 | : \TimeDate::now(\Controller::getMe()->getTimezone()), |
|
59 | 1 | 'with_seconds' => $this->isEdit() |
|
60 | )) |
||
61 | 1 | ->add('map', new ModelType('Map'), array( |
|
62 | 1 | 'required' => false |
|
63 | )) |
||
64 | 1 | ->add('type', 'choice', array( |
|
65 | 'choices' => array( |
||
66 | 1 | \Match::OFFICIAL => 'Official', |
|
67 | 1 | \Match::FUN => 'Fun match', |
|
68 | 1 | \Match::SPECIAL => 'Special event match', |
|
69 | ), |
||
70 | 1 | 'disabled' => $this->editing && $this->editing->isOfficial(), |
|
71 | 1 | 'label' => 'Match Type' |
|
72 | )) |
||
73 | 1 | ->add('enter', 'submit'); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | * |
||
79 | * @param \Match $match |
||
80 | */ |
||
81 | public function fill($form, $match) |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | * |
||
104 | * @param \Match $match |
||
105 | */ |
||
106 | public function update($form, $match) |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | 1 | public function enter($form) |
|
178 | |||
179 | /** |
||
180 | * Get the player list of a team |
||
181 | * |
||
182 | * @param FormInterface $team A MatchTeamType form |
||
183 | * @return array |
||
184 | */ |
||
185 | 1 | private function getPlayerList(FormInterface $team) |
|
189 | |||
190 | /** |
||
191 | * Get a function which converts models to their IDs |
||
192 | * |
||
193 | * Useful to store the match players into the database |
||
194 | */ |
||
195 | private static function getModelToID() |
||
201 | } |
||
202 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: