PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.2
Independent Analytics – WordPress Analytics Plugin v2.15.2
2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Console / DbCommand.php
independent-analytics / vendor / illuminate / database / Console Last commit date
Factories 2 weeks ago Migrations 2 weeks ago Seeds 2 weeks ago DatabaseInspectionCommand.php 2 weeks ago DbCommand.php 2 weeks ago DumpCommand.php 2 weeks ago MonitorCommand.php 2 weeks ago PruneCommand.php 2 weeks ago ShowCommand.php 2 weeks ago TableCommand.php 2 weeks ago WipeCommand.php 2 weeks ago
DbCommand.php
173 lines
1 <?php
2
3 namespace IAWPSCOPED\Illuminate\Database\Console;
4
5 use IAWPSCOPED\Illuminate\Console\Command;
6 use IAWPSCOPED\Illuminate\Support\ConfigurationUrlParser;
7 use IAWPSCOPED\Symfony\Component\Process\Process;
8 use UnexpectedValueException;
9 /** @internal */
10 class DbCommand extends Command
11 {
12 /**
13 * The name and signature of the console command.
14 *
15 * @var string
16 */
17 protected $signature = 'db {connection? : The database connection that should be used}
18 {--read : Connect to the read connection}
19 {--write : Connect to the write connection}';
20 /**
21 * The console command description.
22 *
23 * @var string
24 */
25 protected $description = 'Start a new database CLI session';
26 /**
27 * Execute the console command.
28 *
29 * @return int
30 */
31 public function handle()
32 {
33 $connection = $this->getConnection();
34 if (!isset($connection['host']) && $connection['driver'] !== 'sqlite') {
35 $this->components->error('No host specified for this database connection.');
36 $this->line(' Use the <options=bold>[--read]</> and <options=bold>[--write]</> options to specify a read or write connection.');
37 $this->newLine();
38 return Command::FAILURE;
39 }
40 (new Process(\array_merge([$this->getCommand($connection)], $this->commandArguments($connection)), null, $this->commandEnvironment($connection)))->setTimeout(null)->setTty(\true)->mustRun(function ($type, $buffer) {
41 $this->output->write($buffer);
42 });
43 return 0;
44 }
45 /**
46 * Get the database connection configuration.
47 *
48 * @return array
49 *
50 * @throws \UnexpectedValueException
51 */
52 public function getConnection()
53 {
54 $connection = $this->laravel['config']['database.connections.' . (($db = $this->argument('connection')) ?? $this->laravel['config']['database.default'])];
55 if (empty($connection)) {
56 throw new UnexpectedValueException("Invalid database connection [{$db}].");
57 }
58 if (!empty($connection['url'])) {
59 $connection = (new ConfigurationUrlParser())->parseConfiguration($connection);
60 }
61 if ($this->option('read')) {
62 if (\is_array($connection['read']['host'])) {
63 $connection['read']['host'] = $connection['read']['host'][0];
64 }
65 $connection = \array_merge($connection, $connection['read']);
66 } elseif ($this->option('write')) {
67 if (\is_array($connection['write']['host'])) {
68 $connection['write']['host'] = $connection['write']['host'][0];
69 }
70 $connection = \array_merge($connection, $connection['write']);
71 }
72 return $connection;
73 }
74 /**
75 * Get the arguments for the database client command.
76 *
77 * @param array $connection
78 * @return array
79 */
80 public function commandArguments(array $connection)
81 {
82 $driver = \ucfirst($connection['driver']);
83 return $this->{"get{$driver}Arguments"}($connection);
84 }
85 /**
86 * Get the environment variables for the database client command.
87 *
88 * @param array $connection
89 * @return array|null
90 */
91 public function commandEnvironment(array $connection)
92 {
93 $driver = \ucfirst($connection['driver']);
94 if (\method_exists($this, "get{$driver}Environment")) {
95 return $this->{"get{$driver}Environment"}($connection);
96 }
97 return null;
98 }
99 /**
100 * Get the database client command to run.
101 *
102 * @param array $connection
103 * @return string
104 */
105 public function getCommand(array $connection)
106 {
107 return ['mysql' => 'mysql', 'pgsql' => 'psql', 'sqlite' => 'sqlite3', 'sqlsrv' => 'sqlcmd'][$connection['driver']];
108 }
109 /**
110 * Get the arguments for the MySQL CLI.
111 *
112 * @param array $connection
113 * @return array
114 */
115 protected function getMysqlArguments(array $connection)
116 {
117 return \array_merge(['--host=' . $connection['host'], '--port=' . $connection['port'], '--user=' . $connection['username']], $this->getOptionalArguments(['password' => '--password=' . $connection['password'], 'unix_socket' => '--socket=' . ($connection['unix_socket'] ?? ''), 'charset' => '--default-character-set=' . ($connection['charset'] ?? '')], $connection), [$connection['database']]);
118 }
119 /**
120 * Get the arguments for the Postgres CLI.
121 *
122 * @param array $connection
123 * @return array
124 */
125 protected function getPgsqlArguments(array $connection)
126 {
127 return [$connection['database']];
128 }
129 /**
130 * Get the arguments for the SQLite CLI.
131 *
132 * @param array $connection
133 * @return array
134 */
135 protected function getSqliteArguments(array $connection)
136 {
137 return [$connection['database']];
138 }
139 /**
140 * Get the arguments for the SQL Server CLI.
141 *
142 * @param array $connection
143 * @return array
144 */
145 protected function getSqlsrvArguments(array $connection)
146 {
147 return \array_merge(...$this->getOptionalArguments(['database' => ['-d', $connection['database']], 'username' => ['-U', $connection['username']], 'password' => ['-P', $connection['password']], 'host' => ['-S', 'tcp:' . $connection['host'] . ($connection['port'] ? ',' . $connection['port'] : '')]], $connection));
148 }
149 /**
150 * Get the environment variables for the Postgres CLI.
151 *
152 * @param array $connection
153 * @return array|null
154 */
155 protected function getPgsqlEnvironment(array $connection)
156 {
157 return \array_merge(...$this->getOptionalArguments(['username' => ['PGUSER' => $connection['username']], 'host' => ['PGHOST' => $connection['host']], 'port' => ['PGPORT' => $connection['port']], 'password' => ['PGPASSWORD' => $connection['password']]], $connection));
158 }
159 /**
160 * Get the optional arguments based on the connection configuration.
161 *
162 * @param array $args
163 * @param array $connection
164 * @return array
165 */
166 protected function getOptionalArguments(array $args, array $connection)
167 {
168 return \array_values(\array_filter($args, function ($key) use($connection) {
169 return !empty($connection[$key]);
170 }, \ARRAY_FILTER_USE_KEY));
171 }
172 }
173