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