-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCommandBase.php
More file actions
109 lines (97 loc) · 2.6 KB
/
CommandBase.php
File metadata and controls
109 lines (97 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Created by JetBrains PhpStorm.
* User: alex
* Date: 30/08/2013
* Time: 23:24
* To change this template use File | Settings | File Templates.
*/
namespace DrupalPatchUtils\Command;
use DrupalPatchUtils\Config;
use DrupalPatchUtils\DoBrowser;
use DrupalPatchUtils\Issue;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
class CommandBase extends Command {
/**
* @var \DrupalPatchUtils\Config
*/
protected $config;
/**
* @param OutputInterface $output
* @param $messages string|array
*/
protected function verbose (OutputInterface $output, $messages) {
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln($messages);
}
}
/**
* @param $uri
* @return Issue|bool
*/
protected function getIssue($uri) {
try {
return new Issue($uri);
} catch (\Exception $e) {
return FALSE;
}
}
/**
* @param OutputInterface $output
* @param string $question
* @param string $default
*
* @return string
*/
protected function ask (OutputInterface $output, $question, $default = '', $hidden_response = FALSE) {
// Need to choose patch.
$dialog = $this->getDialog();
if ($hidden_response) {
$response = $dialog->askHiddenResponse($output, $question, $default);
}
else {
$response = $dialog->ask($output, $question, $default);
}
return $response;
}
/**
* @return \DrupalPatchUtils\Config
*/
protected function getConfig() {
if (!is_object($this->config)) {
$this->config = new Config();
$this->config->load();
}
return $this->config;
}
/**
* @return \Symfony\Component\Console\Helper\DialogHelper
*/
protected function getDialog() {
$app = $this->getApplication();
return $app->getHelperSet()->get('dialog');
}
/**
* @param OutputInterface $output
* @param $question
* @param bool $default
* @return bool
*/
protected function askConfirmation (OutputInterface $output, $question, $default = FALSE) {
return $this->getDialog()->askConfirmation($output, $question, $default);
}
/**
* Ensure that the user is logged in.
*
* @param \DrupalPatchUtils\DoBrowser $browser
* The d.o. browser
* @param \Symfony\Component\Console\Output\OutputInterface $output
* The output.
*/
protected function ensureUserIsLoggedIn(DoBrowser $browser, OutputInterface $output) {
if (!$browser->loggedIn()) {
$browser->login($this->getConfig()->getDrupalUser(), $this->ask($output, "Enter your Drupal.org password: ", '', TRUE));
}
}
}