PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.5 2.15.4 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 years ago Migrations 2 years ago Seeds 2 years ago DbCommand.php 2 years ago DumpCommand.php 2 years ago PruneCommand.php 2 years ago WipeCommand.php 2 years ago
DbCommand.php
167 lines
1 <?php
2
3 namespace IAWP_SCOPED\Illuminate\Database\Console;
4
5 use IAWP_SCOPED\Illuminate\Console\Command;
6 use IAWP_SCOPED\Illuminate\Support\ConfigurationUrlParser;
7 use IAWP_SCOPED\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 (new Process(\array_merge([$this->getCommand($connection)], $this->commandArguments($connection)), null, $this->commandEnvironment($connection)))->setTimeout(null)->setTty(\true)->mustRun(function ($type, $buffer) {
35 $this->output->write($buffer);
36 });
37 return 0;
38 }
39 /**
40 * Get the database connection configuration.
41 *
42 * @return array
43 *
44 * @throws \UnexpectedValueException
45 */
46 public function getConnection()
47 {
48 $connection = $this->laravel['config']['database.connections.' . (($db = $this->argument('connection')) ?? $this->laravel['config']['database.default'])];
49 if (empty($connection)) {
50 throw new UnexpectedValueException("Invalid database connection [{$db}].");
51 }
52 if (!empty($connection['url'])) {
53 $connection = (new ConfigurationUrlParser())->parseConfiguration($connection);
54 }
55 if ($this->option('read')) {
56 if (\is_array($connection['read']['host'])) {
57 $connection['read']['host'] = $connection['read']['host'][0];
58 }
59 $connection = \array_merge($connection, $connection['read']);
60 } elseif ($this->option('write')) {
61 if (\is_array($connection['write']['host'])) {
62 $connection['write']['host'] = $connection['write']['host'][0];
63 }
64 $connection = \array_merge($connection, $connection['write']);
65 }
66 return $connection;
67 }
68 /**
69 * Get the arguments for the database client command.
70 *
71 * @param array $connection
72 * @return array
73 */
74 public function commandArguments(array $connection)
75 {
76 $driver = \ucfirst($connection['driver']);
77 return $this->{"get{$driver}Arguments"}($connection);
78 }
79 /**
80 * Get the environment variables for the database client command.
81 *
82 * @param array $connection
83 * @return array|null
84 */
85 public function commandEnvironment(array $connection)
86 {
87 $driver = \ucfirst($connection['driver']);
88 if (\method_exists($this, "get{$driver}Environment")) {
89 return $this->{"get{$driver}Environment"}($connection);
90 }
91 return null;
92 }
93 /**
94 * Get the database client command to run.
95 *
96 * @param array $connection
97 * @return string
98 */
99 public function getCommand(array $connection)
100 {
101 return ['mysql' => 'mysql', 'pgsql' => 'psql', 'sqlite' => 'sqlite3', 'sqlsrv' => 'sqlcmd'][$connection['driver']];
102 }
103 /**
104 * Get the arguments for the MySQL CLI.
105 *
106 * @param array $connection
107 * @return array
108 */
109 protected function getMysqlArguments(array $connection)
110 {
111 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']]);
112 }
113 /**
114 * Get the arguments for the Postgres CLI.
115 *
116 * @param array $connection
117 * @return array
118 */
119 protected function getPgsqlArguments(array $connection)
120 {
121 return [$connection['database']];
122 }
123 /**
124 * Get the arguments for the SQLite CLI.
125 *
126 * @param array $connection
127 * @return array
128 */
129 protected function getSqliteArguments(array $connection)
130 {
131 return [$connection['database']];
132 }
133 /**
134 * Get the arguments for the SQL Server CLI.
135 *
136 * @param array $connection
137 * @return array
138 */
139 protected function getSqlsrvArguments(array $connection)
140 {
141 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));
142 }
143 /**
144 * Get the environment variables for the Postgres CLI.
145 *
146 * @param array $connection
147 * @return array|null
148 */
149 protected function getPgsqlEnvironment(array $connection)
150 {
151 return \array_merge(...$this->getOptionalArguments(['username' => ['PGUSER' => $connection['username']], 'host' => ['PGHOST' => $connection['host']], 'port' => ['PGPORT' => $connection['port']], 'password' => ['PGPASSWORD' => $connection['password']]], $connection));
152 }
153 /**
154 * Get the optional arguments based on the connection configuration.
155 *
156 * @param array $args
157 * @param array $connection
158 * @return array
159 */
160 protected function getOptionalArguments(array $args, array $connection)
161 {
162 return \array_values(\array_filter($args, function ($key) use($connection) {
163 return !empty($connection[$key]);
164 }, \ARRAY_FILTER_USE_KEY));
165 }
166 }
167