|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Drest package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Lee Davis |
|
9
|
|
|
* @copyright Copyright (c) Lee Davis <@leedavis81> |
|
10
|
|
|
* @link https://github.com/leedavis81/drest/blob/master/LICENSE |
|
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT X License (MIT) |
|
12
|
|
|
*/ |
|
13
|
|
|
namespace Drest\Tools\Console\Command; |
|
14
|
|
|
|
|
15
|
|
|
use Symfony\Component\Console\Command\Command; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Symfony\Component\Console; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Check Drest Production Setting |
|
22
|
|
|
*/ |
|
23
|
|
View Code Duplication |
class CheckProductionSettings extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @see Console\Command\Command |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function configure() |
|
29
|
|
|
{ |
|
30
|
|
|
$this |
|
31
|
|
|
->setName('config:production-ready') |
|
32
|
|
|
->setDescription('Checks the settings used are suitable for a production environment.') |
|
33
|
|
|
->setHelp( |
|
34
|
|
|
<<<EOT |
|
35
|
|
|
|
|
36
|
|
|
Checks the settings used are suitable for a production environment. |
|
37
|
|
|
Notifications are given for using debug mode, or using a bad cache implementation. |
|
38
|
|
|
|
|
39
|
|
|
Example usage: |
|
40
|
|
|
php drest-server.php config:production-ready |
|
41
|
|
|
EOT |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @see Console\Command\Command |
|
47
|
|
|
* |
|
48
|
|
|
* @param InputInterface $input |
|
49
|
|
|
* @param OutputInterface $output |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
53
|
|
|
{ |
|
54
|
|
|
/* @var $drm \Drest\Manager */ |
|
55
|
|
|
$drm = $this->getHelper('drm')->getDrestManager(); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
try { |
|
58
|
|
|
$drm->getConfiguration()->ensureProductionSettings(); |
|
59
|
|
|
$output->write('Production settings OK' . PHP_EOL); |
|
60
|
|
|
} catch (\Exception $e) { |
|
61
|
|
|
$output->write(PHP_EOL . $e->getMessage() . PHP_EOL); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
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: