|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Laravel Meetups. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Nuno Maduro <[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 LaravelMeetups; |
|
13
|
|
|
|
|
14
|
|
|
use LaravelMeetups\Contracts\Config as ConfigContract; |
|
15
|
|
|
use Symfony\Component\Console\Command\Command as BaseCommand; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Question\Question; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class Command. |
|
23
|
|
|
*/ |
|
24
|
|
|
class Command extends BaseCommand |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Configure the command options. |
|
28
|
|
|
*a. |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function configure() |
|
33
|
|
|
{ |
|
34
|
|
|
date_default_timezone_set('UTC'); |
|
35
|
|
|
|
|
36
|
|
|
$this->setName('laravel-meetups') |
|
37
|
|
|
->setDescription('Create a new Laravel meetup application') |
|
38
|
|
|
->addArgument('max_radius', InputArgument::OPTIONAL, 'What should be the max radius?'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Execute the command. |
|
43
|
|
|
* |
|
44
|
|
|
* @param InputInterface $input |
|
45
|
|
|
* @param OutputInterface $output |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
50
|
|
|
{ |
|
51
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection( |
|
|
|
|
|
|
52
|
|
|
' Laravel Meetups ', |
|
53
|
|
|
'Searching nearby meetups...' |
|
54
|
|
|
)); |
|
55
|
|
|
|
|
56
|
|
|
$interaction = new Interactions\Catalog(($config = new Config()), $input, $output); |
|
57
|
|
|
|
|
58
|
|
|
$key = null; |
|
59
|
|
|
while (!$interaction->isEmpty() && $key !== 'exit') { |
|
60
|
|
|
$interaction->displayTable()->displayDetail($key); |
|
61
|
|
|
$output->writeln('<comment>Follow the author on twitter:<comment> <info>@enunomaduro</info> <info>✔</info>'); |
|
62
|
|
|
$key = $this->getHelper('question')->ask($input, $output, new Question('Select a meetup:')); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$interaction->isEmpty() and $this->noMeetupsNearYou($config, $output); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Displays the no meetups near you message. |
|
70
|
|
|
* |
|
71
|
|
|
* @param \LaravelMeetups\Contracts\Config $config |
|
72
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
73
|
|
|
* |
|
74
|
|
|
* @return $this |
|
75
|
|
|
*/ |
|
76
|
|
|
private function noMeetupsNearYou(ConfigContract $config, OutputInterface $output) |
|
77
|
|
|
{ |
|
78
|
|
|
$radiusUsed = $config->getMaxRadius(); |
|
79
|
|
|
|
|
80
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection( |
|
|
|
|
|
|
81
|
|
|
" There is no nearby meetups within $radiusUsed miles ", |
|
82
|
|
|
'<comment>Try to use another max radius. Example LaravelMeetups 1000</comment>' |
|
83
|
|
|
)); |
|
84
|
|
|
|
|
85
|
|
|
return $this; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
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 implementation 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 interface: