@@ -43,23 +43,23 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function load(string $id): ?TokenInterface |
| 45 | 45 | { |
| 46 | - try { |
|
| 46 | + try{ |
|
| 47 | 47 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
| 48 | - if ($tokenData === null) { |
|
| 48 | + if ($tokenData === null){ |
|
| 49 | 49 | return null; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $token = Token::unpack($tokenData); |
| 53 | - } catch (Throwable $e) { |
|
| 53 | + }catch (Throwable $e){ |
|
| 54 | 54 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if (!hash_equals($token->getID(), $id)) { |
|
| 57 | + if (!hash_equals($token->getID(), $id)){ |
|
| 58 | 58 | return null; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $expiresAt = $token->getExpiresAt(); |
| 62 | - if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) { |
|
| 62 | + if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()){ |
|
| 63 | 63 | $this->delete($token); |
| 64 | 64 | return null; |
| 65 | 65 | } |
@@ -72,12 +72,12 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function create(array $payload, DateTimeInterface $expiresAt = null): TokenInterface |
| 74 | 74 | { |
| 75 | - try { |
|
| 75 | + try{ |
|
| 76 | 76 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
| 77 | 77 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
| 78 | 78 | |
| 79 | 79 | return $token; |
| 80 | - } catch (Throwable $e) { |
|
| 80 | + }catch (Throwable $e){ |
|
| 81 | 81 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -43,23 +43,29 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function load(string $id): ?TokenInterface |
| 45 | 45 | { |
| 46 | - try { |
|
| 46 | + try |
|
| 47 | + { |
|
| 47 | 48 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
| 48 | - if ($tokenData === null) { |
|
| 49 | + if ($tokenData === null) |
|
| 50 | + { |
|
| 49 | 51 | return null; |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | $token = Token::unpack($tokenData); |
| 53 | - } catch (Throwable $e) { |
|
| 55 | + } |
|
| 56 | + catch (Throwable $e) |
|
| 57 | + { |
|
| 54 | 58 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
| 55 | 59 | } |
| 56 | 60 | |
| 57 | - if (!hash_equals($token->getID(), $id)) { |
|
| 61 | + if (!hash_equals($token->getID(), $id)) |
|
| 62 | + { |
|
| 58 | 63 | return null; |
| 59 | 64 | } |
| 60 | 65 | |
| 61 | 66 | $expiresAt = $token->getExpiresAt(); |
| 62 | - if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) { |
|
| 67 | + if ($expiresAt !== null && $expiresAt < new DateTimeImmutable()) |
|
| 68 | + { |
|
| 63 | 69 | $this->delete($token); |
| 64 | 70 | return null; |
| 65 | 71 | } |
@@ -72,12 +78,15 @@ discard block |
||
| 72 | 78 | */ |
| 73 | 79 | public function create(array $payload, DateTimeInterface $expiresAt = null): TokenInterface |
| 74 | 80 | { |
| 75 | - try { |
|
| 81 | + try |
|
| 82 | + { |
|
| 76 | 83 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
| 77 | 84 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
| 78 | 85 | |
| 79 | 86 | return $token; |
| 80 | - } catch (Throwable $e) { |
|
| 87 | + } |
|
| 88 | + catch (Throwable $e) |
|
| 89 | + { |
|
| 81 | 90 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
| 82 | 91 | } |
| 83 | 92 | } |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | public static function unpack(array $data): Token |
| 88 | 88 | { |
| 89 | 89 | $expiresAt = null; |
| 90 | - if ($data['expiresAt'] !== null) { |
|
| 90 | + if ($data['expiresAt'] !== null){ |
|
| 91 | 91 | $expiresAt = (new DateTimeImmutable())->setTimestamp($data['expiresAt']); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -87,7 +87,8 @@ |
||
| 87 | 87 | public static function unpack(array $data): Token |
| 88 | 88 | { |
| 89 | 89 | $expiresAt = null; |
| 90 | - if ($data['expiresAt'] !== null) { |
|
| 90 | + if ($data['expiresAt'] !== null) |
|
| 91 | + { |
|
| 91 | 92 | $expiresAt = (new DateTimeImmutable())->setTimestamp($data['expiresAt']); |
| 92 | 93 | } |
| 93 | 94 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | ['locale', InputArgument::REQUIRED, 'Locale to be dumped'], |
| 29 | 29 | ['path', InputArgument::REQUIRED, 'Export path'] |
| 30 | 30 | ]; |
| 31 | - protected const OPTIONS = [ |
|
| 31 | + protected const OPTIONS = [ |
|
| 32 | 32 | ['dumper', 'd', InputOption::VALUE_OPTIONAL, 'Dumper name', 'php'], |
| 33 | 33 | ['fallback', 'f', InputOption::VALUE_NONE, 'Merge messages from fallback catalogue'], |
| 34 | 34 | ]; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function perform(TranslatorConfig $config, CatalogueManager $manager): void |
| 41 | 41 | { |
| 42 | - if (!$config->hasDumper($this->option('dumper'))) { |
|
| 42 | + if (!$config->hasDumper($this->option('dumper'))){ |
|
| 43 | 43 | $this->writeln("<fg=red>Undefined dumper '{$this->option('dumper')}'.</fg=red>"); |
| 44 | 44 | |
| 45 | 45 | return; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $manager->get($this->argument('locale')) |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - if ($this->isVerbose() && !empty($mc->getDomains())) { |
|
| 54 | + if ($this->isVerbose() && !empty($mc->getDomains())){ |
|
| 55 | 55 | $this->sprintf( |
| 56 | 56 | "<info>Exporting domain(s):</info> %s\n", |
| 57 | 57 | join(',', $mc->getDomains()) |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | ] |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - $this->writeln('Export successfully completed using <info>' . get_class($dumper) . '</info>'); |
|
| 73 | - $this->writeln('Output: <comment>' . realpath($this->argument('path')) . '</comment>'); |
|
| 72 | + $this->writeln('Export successfully completed using <info>'.get_class($dumper).'</info>'); |
|
| 73 | + $this->writeln('Output: <comment>'.realpath($this->argument('path')).'</comment>'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | $catalogue->getData() |
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | - if ($this->option('fallback')) { |
|
| 93 | - foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) { |
|
| 94 | - foreach ($messages as $id => $message) { |
|
| 95 | - if (!$messageCatalogue->defines($id, $domain)) { |
|
| 92 | + if ($this->option('fallback')){ |
|
| 93 | + foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages){ |
|
| 94 | + foreach ($messages as $id => $message){ |
|
| 95 | + if (!$messageCatalogue->defines($id, $domain)){ |
|
| 96 | 96 | $messageCatalogue->set($id, $message, $domain); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -39,7 +39,8 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function perform(TranslatorConfig $config, CatalogueManager $manager): void |
| 41 | 41 | { |
| 42 | - if (!$config->hasDumper($this->option('dumper'))) { |
|
| 42 | + if (!$config->hasDumper($this->option('dumper'))) |
|
| 43 | + { |
|
| 43 | 44 | $this->writeln("<fg=red>Undefined dumper '{$this->option('dumper')}'.</fg=red>"); |
| 44 | 45 | |
| 45 | 46 | return; |
@@ -51,7 +52,8 @@ discard block |
||
| 51 | 52 | $manager->get($this->argument('locale')) |
| 52 | 53 | ); |
| 53 | 54 | |
| 54 | - if ($this->isVerbose() && !empty($mc->getDomains())) { |
|
| 55 | + if ($this->isVerbose() && !empty($mc->getDomains())) |
|
| 56 | + { |
|
| 55 | 57 | $this->sprintf( |
| 56 | 58 | "<info>Exporting domain(s):</info> %s\n", |
| 57 | 59 | join(',', $mc->getDomains()) |
@@ -86,10 +88,14 @@ discard block |
||
| 86 | 88 | $catalogue->getData() |
| 87 | 89 | ); |
| 88 | 90 | |
| 89 | - if ($this->option('fallback')) { |
|
| 90 | - foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) { |
|
| 91 | - foreach ($messages as $id => $message) { |
|
| 92 | - if (!$messageCatalogue->defines($id, $domain)) { |
|
| 91 | + if ($this->option('fallback')) |
|
| 92 | + { |
|
| 93 | + foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) |
|
| 94 | + { |
|
| 95 | + foreach ($messages as $id => $message) |
|
| 96 | + { |
|
| 97 | + if (!$messageCatalogue->defines($id, $domain)) |
|
| 98 | + { |
|
| 93 | 99 | $messageCatalogue->set($id, $message, $domain); |
| 94 | 100 | } |
| 95 | 101 | } |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function perform(DatabaseConfig $config, DatabaseManager $dbal): void |
| 36 | 36 | { |
| 37 | - if ($this->argument('db')) { |
|
| 37 | + if ($this->argument('db')){ |
|
| 38 | 38 | $databases = [$this->argument('db')]; |
| 39 | - } else { |
|
| 39 | + }else{ |
|
| 40 | 40 | $databases = array_keys($config->getDatabases()); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if (empty($databases)) { |
|
| 43 | + if (empty($databases)){ |
|
| 44 | 44 | $this->writeln('<fg=red>No databases found.</fg=red>'); |
| 45 | 45 | |
| 46 | 46 | return; |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | ] |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - foreach ($databases as $database) { |
|
| 61 | + foreach ($databases as $database){ |
|
| 62 | 62 | $database = $dbal->database($database); |
| 63 | 63 | |
| 64 | 64 | /** @var Driver $driver */ |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | $database->getPrefix() ?: '<comment>---</comment>' |
| 72 | 72 | ]; |
| 73 | 73 | |
| 74 | - try { |
|
| 74 | + try{ |
|
| 75 | 75 | $driver->connect(); |
| 76 | - } catch (\Exception $exception) { |
|
| 76 | + }catch (\Exception $exception){ |
|
| 77 | 77 | $this->renderException($grid, $header, $exception); |
| 78 | 78 | |
| 79 | - if ($database->getName() != end($databases)) { |
|
| 79 | + if ($database->getName() != end($databases)){ |
|
| 80 | 80 | $grid->addRow(new TableSeparator()); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | $header[] = '<info>connected</info>'; |
| 87 | 87 | $this->renderTables($grid, $header, $database); |
| 88 | - if ($database->getName() != end($databases)) { |
|
| 88 | + if ($database->getName() != end($databases)){ |
|
| 89 | 89 | $grid->addRow(new TableSeparator()); |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | private function renderTables(Table $grid, array $header, Database $database): void |
| 121 | 121 | { |
| 122 | - foreach ($database->getTables() as $table) { |
|
| 122 | + foreach ($database->getTables() as $table){ |
|
| 123 | 123 | $grid->addRow( |
| 124 | 124 | array_merge( |
| 125 | 125 | $header, |
@@ -34,13 +34,17 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function perform(DatabaseConfig $config, DatabaseManager $dbal): void |
| 36 | 36 | { |
| 37 | - if ($this->argument('db')) { |
|
| 37 | + if ($this->argument('db')) |
|
| 38 | + { |
|
| 38 | 39 | $databases = [$this->argument('db')]; |
| 39 | - } else { |
|
| 40 | + } |
|
| 41 | + else |
|
| 42 | + { |
|
| 40 | 43 | $databases = array_keys($config->getDatabases()); |
| 41 | 44 | } |
| 42 | 45 | |
| 43 | - if (empty($databases)) { |
|
| 46 | + if (empty($databases)) |
|
| 47 | + { |
|
| 44 | 48 | $this->writeln('<fg=red>No databases found.</fg=red>'); |
| 45 | 49 | |
| 46 | 50 | return; |
@@ -58,7 +62,8 @@ discard block |
||
| 58 | 62 | ] |
| 59 | 63 | ); |
| 60 | 64 | |
| 61 | - foreach ($databases as $database) { |
|
| 65 | + foreach ($databases as $database) |
|
| 66 | + { |
|
| 62 | 67 | $database = $dbal->database($database); |
| 63 | 68 | |
| 64 | 69 | /** @var Driver $driver */ |
@@ -71,12 +76,16 @@ discard block |
||
| 71 | 76 | $database->getPrefix() ?: '<comment>---</comment>' |
| 72 | 77 | ]; |
| 73 | 78 | |
| 74 | - try { |
|
| 79 | + try |
|
| 80 | + { |
|
| 75 | 81 | $driver->connect(); |
| 76 | - } catch (\Exception $exception) { |
|
| 82 | + } |
|
| 83 | + catch (\Exception $exception) |
|
| 84 | + { |
|
| 77 | 85 | $this->renderException($grid, $header, $exception); |
| 78 | 86 | |
| 79 | - if ($database->getName() != end($databases)) { |
|
| 87 | + if ($database->getName() != end($databases)) |
|
| 88 | + { |
|
| 80 | 89 | $grid->addRow(new TableSeparator()); |
| 81 | 90 | } |
| 82 | 91 | |
@@ -85,7 +94,8 @@ discard block |
||
| 85 | 94 | |
| 86 | 95 | $header[] = '<info>connected</info>'; |
| 87 | 96 | $this->renderTables($grid, $header, $database); |
| 88 | - if ($database->getName() != end($databases)) { |
|
| 97 | + if ($database->getName() != end($databases)) |
|
| 98 | + { |
|
| 89 | 99 | $grid->addRow(new TableSeparator()); |
| 90 | 100 | } |
| 91 | 101 | } |
@@ -119,7 +129,8 @@ discard block |
||
| 119 | 129 | */ |
| 120 | 130 | private function renderTables(Table $grid, array $header, Database $database): void |
| 121 | 131 | { |
| 122 | - foreach ($database->getTables() as $table) { |
|
| 132 | + foreach ($database->getTables() as $table) |
|
| 133 | + { |
|
| 123 | 134 | $grid->addRow( |
| 124 | 135 | array_merge( |
| 125 | 136 | $header, |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $database = $dbal->database($this->option('database')); |
| 45 | 45 | $schema = $database->table($this->argument('table'))->getSchema(); |
| 46 | 46 | |
| 47 | - if (!$schema->exists()) { |
|
| 47 | + if (!$schema->exists()){ |
|
| 48 | 48 | throw new DBALException( |
| 49 | 49 | "Table {$database->getName()}.{$this->argument('table')} does not exists." |
| 50 | 50 | ); |
@@ -58,11 +58,11 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | $this->describeColumns($schema); |
| 60 | 60 | |
| 61 | - if (!empty($indexes = $schema->getIndexes())) { |
|
| 61 | + if (!empty($indexes = $schema->getIndexes())){ |
|
| 62 | 62 | $this->describeIndexes($database, $indexes); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if (!empty($foreignKeys = $schema->getForeignKeys())) { |
|
| 65 | + if (!empty($foreignKeys = $schema->getForeignKeys())){ |
|
| 66 | 66 | $this->describeForeignKeys($database, $foreignKeys); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | ] |
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | - foreach ($schema->getColumns() as $column) { |
|
| 87 | + foreach ($schema->getColumns() as $column){ |
|
| 88 | 88 | $name = $column->getName(); |
| 89 | 89 | |
| 90 | - if (in_array($column->getName(), $schema->getPrimaryKeys(), true)) { |
|
| 90 | + if (in_array($column->getName(), $schema->getPrimaryKeys(), true)){ |
|
| 91 | 91 | $name = "<fg=magenta>{$name}</fg=magenta>"; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | $indexesTable = $this->table(['Name:', 'Type:', 'Columns:']); |
| 123 | - foreach ($indexes as $index) { |
|
| 123 | + foreach ($indexes as $index){ |
|
| 124 | 124 | $indexesTable->addRow( |
| 125 | 125 | [ |
| 126 | 126 | $index->getName(), |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | ] |
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | - foreach ($foreignKeys as $reference) { |
|
| 158 | + foreach ($foreignKeys as $reference){ |
|
| 159 | 159 | $foreignTable->addRow( |
| 160 | 160 | [ |
| 161 | 161 | $reference->getName(), |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | { |
| 181 | 181 | $defaultValue = $column->getDefaultValue(); |
| 182 | 182 | |
| 183 | - if ($defaultValue instanceof FragmentInterface) { |
|
| 183 | + if ($defaultValue instanceof FragmentInterface){ |
|
| 184 | 184 | $value = $driver->getQueryCompiler()->compile(new QueryParameters(), '', $defaultValue); |
| 185 | 185 | |
| 186 | 186 | return "<info>{$value}</info>"; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ($defaultValue instanceof \DateTimeInterface) { |
|
| 189 | + if ($defaultValue instanceof \DateTimeInterface){ |
|
| 190 | 190 | $defaultValue = $defaultValue->format('c'); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $abstractType = $column->getAbstractType(); |
| 205 | 205 | |
| 206 | - if ($column->getSize()) { |
|
| 206 | + if ($column->getSize()){ |
|
| 207 | 207 | $type .= " ({$column->getSize()})"; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if ($abstractType === 'decimal') { |
|
| 210 | + if ($abstractType === 'decimal'){ |
|
| 211 | 211 | $type .= " ({$column->getPrecision()}, {$column->getScale()})"; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $abstractType = $column->getAbstractType(); |
| 224 | 224 | |
| 225 | - if (in_array($abstractType, ['primary', 'bigPrimary'])) { |
|
| 225 | + if (in_array($abstractType, ['primary', 'bigPrimary'])){ |
|
| 226 | 226 | $abstractType = "<fg=magenta>{$abstractType}</fg=magenta>"; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -44,7 +44,8 @@ discard block |
||
| 44 | 44 | $database = $dbal->database($this->option('database')); |
| 45 | 45 | $schema = $database->table($this->argument('table'))->getSchema(); |
| 46 | 46 | |
| 47 | - if (!$schema->exists()) { |
|
| 47 | + if (!$schema->exists()) |
|
| 48 | + { |
|
| 48 | 49 | throw new DBALException( |
| 49 | 50 | "Table {$database->getName()}.{$this->argument('table')} does not exists." |
| 50 | 51 | ); |
@@ -58,11 +59,13 @@ discard block |
||
| 58 | 59 | |
| 59 | 60 | $this->describeColumns($schema); |
| 60 | 61 | |
| 61 | - if (!empty($indexes = $schema->getIndexes())) { |
|
| 62 | + if (!empty($indexes = $schema->getIndexes())) |
|
| 63 | + { |
|
| 62 | 64 | $this->describeIndexes($database, $indexes); |
| 63 | 65 | } |
| 64 | 66 | |
| 65 | - if (!empty($foreignKeys = $schema->getForeignKeys())) { |
|
| 67 | + if (!empty($foreignKeys = $schema->getForeignKeys())) |
|
| 68 | + { |
|
| 66 | 69 | $this->describeForeignKeys($database, $foreignKeys); |
| 67 | 70 | } |
| 68 | 71 | |
@@ -84,10 +87,12 @@ discard block |
||
| 84 | 87 | ] |
| 85 | 88 | ); |
| 86 | 89 | |
| 87 | - foreach ($schema->getColumns() as $column) { |
|
| 90 | + foreach ($schema->getColumns() as $column) |
|
| 91 | + { |
|
| 88 | 92 | $name = $column->getName(); |
| 89 | 93 | |
| 90 | - if (in_array($column->getName(), $schema->getPrimaryKeys(), true)) { |
|
| 94 | + if (in_array($column->getName(), $schema->getPrimaryKeys(), true)) |
|
| 95 | + { |
|
| 91 | 96 | $name = "<fg=magenta>{$name}</fg=magenta>"; |
| 92 | 97 | } |
| 93 | 98 | |
@@ -120,7 +125,8 @@ discard block |
||
| 120 | 125 | ); |
| 121 | 126 | |
| 122 | 127 | $indexesTable = $this->table(['Name:', 'Type:', 'Columns:']); |
| 123 | - foreach ($indexes as $index) { |
|
| 128 | + foreach ($indexes as $index) |
|
| 129 | + { |
|
| 124 | 130 | $indexesTable->addRow( |
| 125 | 131 | [ |
| 126 | 132 | $index->getName(), |
@@ -155,7 +161,8 @@ discard block |
||
| 155 | 161 | ] |
| 156 | 162 | ); |
| 157 | 163 | |
| 158 | - foreach ($foreignKeys as $reference) { |
|
| 164 | + foreach ($foreignKeys as $reference) |
|
| 165 | + { |
|
| 159 | 166 | $foreignTable->addRow( |
| 160 | 167 | [ |
| 161 | 168 | $reference->getName(), |
@@ -180,13 +187,15 @@ discard block |
||
| 180 | 187 | { |
| 181 | 188 | $defaultValue = $column->getDefaultValue(); |
| 182 | 189 | |
| 183 | - if ($defaultValue instanceof FragmentInterface) { |
|
| 190 | + if ($defaultValue instanceof FragmentInterface) |
|
| 191 | + { |
|
| 184 | 192 | $value = $driver->getQueryCompiler()->compile(new QueryParameters(), '', $defaultValue); |
| 185 | 193 | |
| 186 | 194 | return "<info>{$value}</info>"; |
| 187 | 195 | } |
| 188 | 196 | |
| 189 | - if ($defaultValue instanceof \DateTimeInterface) { |
|
| 197 | + if ($defaultValue instanceof \DateTimeInterface) |
|
| 198 | + { |
|
| 190 | 199 | $defaultValue = $defaultValue->format('c'); |
| 191 | 200 | } |
| 192 | 201 | |
@@ -203,11 +212,13 @@ discard block |
||
| 203 | 212 | |
| 204 | 213 | $abstractType = $column->getAbstractType(); |
| 205 | 214 | |
| 206 | - if ($column->getSize()) { |
|
| 215 | + if ($column->getSize()) |
|
| 216 | + { |
|
| 207 | 217 | $type .= " ({$column->getSize()})"; |
| 208 | 218 | } |
| 209 | 219 | |
| 210 | - if ($abstractType === 'decimal') { |
|
| 220 | + if ($abstractType === 'decimal') |
|
| 221 | + { |
|
| 211 | 222 | $type .= " ({$column->getPrecision()}, {$column->getScale()})"; |
| 212 | 223 | } |
| 213 | 224 | |
@@ -222,7 +233,8 @@ discard block |
||
| 222 | 233 | { |
| 223 | 234 | $abstractType = $column->getAbstractType(); |
| 224 | 235 | |
| 225 | - if (in_array($abstractType, ['primary', 'bigPrimary'])) { |
|
| 236 | + if (in_array($abstractType, ['primary', 'bigPrimary'])) |
|
| 237 | + { |
|
| 226 | 238 | $abstractType = "<fg=magenta>{$abstractType}</fg=magenta>"; |
| 227 | 239 | } |
| 228 | 240 | |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | |
| 44 | 44 | if (!$schema->exists()) { |
| 45 | 45 | throw new DBALException( |
| 46 | - "Table {$database->getName()}.{$this->argument('table')} does not exists." |
|
| 46 | + "table {$database->getName()}.{$this->argument('table')} does not exists." |
|
| 47 | 47 | ); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | $this->output->writeln('<info>Detecting schema changes:</info>'); |
| 43 | 43 | |
| 44 | 44 | $this->changes = []; |
| 45 | - foreach ($registry->getIterator() as $e) { |
|
| 46 | - if ($registry->hasTable($e)) { |
|
| 45 | + foreach ($registry->getIterator() as $e){ |
|
| 46 | + if ($registry->hasTable($e)){ |
|
| 47 | 47 | $table = $registry->getTableSchema($e); |
| 48 | 48 | |
| 49 | - if ($table->getComparator()->hasChanges()) { |
|
| 49 | + if ($table->getComparator()->hasChanges()){ |
|
| 50 | 50 | $this->changes[] = [ |
| 51 | 51 | 'database' => $registry->getDatabase($e), |
| 52 | 52 | 'table' => $registry->getTable($e), |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ($this->changes === []) { |
|
| 59 | + if ($this->changes === []){ |
|
| 60 | 60 | $this->output->writeln('<fg=yellow>no database changes has been detected</fg=yellow>'); |
| 61 | 61 | |
| 62 | 62 | return $registry; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - foreach ($this->changes as $change) { |
|
| 65 | + foreach ($this->changes as $change){ |
|
| 66 | 66 | $this->output->write(sprintf('• <fg=cyan>%s.%s</fg=cyan>', $change['database'], $change['table'])); |
| 67 | 67 | $this->describeChanges($change['schema']); |
| 68 | 68 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | protected function describeChanges(AbstractTable $table): void |
| 85 | 85 | { |
| 86 | - if (!$this->output->isVerbose()) { |
|
| 86 | + if (!$this->output->isVerbose()){ |
|
| 87 | 87 | $this->output->writeln( |
| 88 | 88 | sprintf( |
| 89 | 89 | ': <fg=green>%s</fg=green> change(s) detected', |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | $this->output->write("\n"); |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - if (!$table->exists()) { |
|
| 99 | + if (!$table->exists()){ |
|
| 100 | 100 | $this->output->writeln(' - create table'); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
|
| 103 | + if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED){ |
|
| 104 | 104 | $this->output->writeln(' - drop table'); |
| 105 | 105 | return; |
| 106 | 106 | } |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | protected function describeColumns(Comparator $cmp): void |
| 119 | 119 | { |
| 120 | - foreach ($cmp->addedColumns() as $column) { |
|
| 120 | + foreach ($cmp->addedColumns() as $column){ |
|
| 121 | 121 | $this->output->writeln(" - add column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - foreach ($cmp->droppedColumns() as $column) { |
|
| 124 | + foreach ($cmp->droppedColumns() as $column){ |
|
| 125 | 125 | $this->output->writeln(" - drop column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - foreach ($cmp->alteredColumns() as $column) { |
|
| 128 | + foreach ($cmp->alteredColumns() as $column){ |
|
| 129 | 129 | $column = $column[0]; |
| 130 | 130 | $this->output->writeln(" - alter column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 131 | 131 | } |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function describeIndexes(Comparator $cmp): void |
| 138 | 138 | { |
| 139 | - foreach ($cmp->addedIndexes() as $index) { |
|
| 139 | + foreach ($cmp->addedIndexes() as $index){ |
|
| 140 | 140 | $index = join(', ', $index->getColumns()); |
| 141 | 141 | $this->output->writeln(" - add index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - foreach ($cmp->droppedIndexes() as $index) { |
|
| 144 | + foreach ($cmp->droppedIndexes() as $index){ |
|
| 145 | 145 | $index = join(', ', $index->getColumns()); |
| 146 | 146 | $this->output->writeln(" - drop index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - foreach ($cmp->alteredIndexes() as $index) { |
|
| 149 | + foreach ($cmp->alteredIndexes() as $index){ |
|
| 150 | 150 | $index = $index[0]; |
| 151 | 151 | $index = join(', ', $index->getColumns()); |
| 152 | 152 | $this->output->writeln(" - alter index on <fg=yellow>[{$index}]</fg=yellow>"); |
@@ -158,17 +158,17 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | protected function describeFKs(Comparator $cmp): void |
| 160 | 160 | { |
| 161 | - foreach ($cmp->addedForeignKeys() as $fk) { |
|
| 161 | + foreach ($cmp->addedForeignKeys() as $fk){ |
|
| 162 | 162 | $fkColumns = join(', ', $fk->getColumns()); |
| 163 | 163 | $this->output->writeln(" - add foreign key on <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - foreach ($cmp->droppedForeignKeys() as $fk) { |
|
| 166 | + foreach ($cmp->droppedForeignKeys() as $fk){ |
|
| 167 | 167 | $fkColumns = join(', ', $fk->getColumns()); |
| 168 | 168 | $this->output->writeln(" - drop foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - foreach ($cmp->alteredForeignKeys() as $fk) { |
|
| 171 | + foreach ($cmp->alteredForeignKeys() as $fk){ |
|
| 172 | 172 | $fk = $fk[0]; |
| 173 | 173 | $fkColumns = join(', ', $fk->getColumns()); |
| 174 | 174 | $this->output->writeln(" - alter foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
@@ -42,11 +42,14 @@ discard block |
||
| 42 | 42 | $this->output->writeln('<info>Detecting schema changes:</info>'); |
| 43 | 43 | |
| 44 | 44 | $this->changes = []; |
| 45 | - foreach ($registry->getIterator() as $e) { |
|
| 46 | - if ($registry->hasTable($e)) { |
|
| 45 | + foreach ($registry->getIterator() as $e) |
|
| 46 | + { |
|
| 47 | + if ($registry->hasTable($e)) |
|
| 48 | + { |
|
| 47 | 49 | $table = $registry->getTableSchema($e); |
| 48 | 50 | |
| 49 | - if ($table->getComparator()->hasChanges()) { |
|
| 51 | + if ($table->getComparator()->hasChanges()) |
|
| 52 | + { |
|
| 50 | 53 | $this->changes[] = [ |
| 51 | 54 | 'database' => $registry->getDatabase($e), |
| 52 | 55 | 'table' => $registry->getTable($e), |
@@ -56,13 +59,15 @@ discard block |
||
| 56 | 59 | } |
| 57 | 60 | } |
| 58 | 61 | |
| 59 | - if ($this->changes === []) { |
|
| 62 | + if ($this->changes === []) |
|
| 63 | + { |
|
| 60 | 64 | $this->output->writeln('<fg=yellow>no database changes has been detected</fg=yellow>'); |
| 61 | 65 | |
| 62 | 66 | return $registry; |
| 63 | 67 | } |
| 64 | 68 | |
| 65 | - foreach ($this->changes as $change) { |
|
| 69 | + foreach ($this->changes as $change) |
|
| 70 | + { |
|
| 66 | 71 | $this->output->write(sprintf('• <fg=cyan>%s.%s</fg=cyan>', $change['database'], $change['table'])); |
| 67 | 72 | $this->describeChanges($change['schema']); |
| 68 | 73 | } |
@@ -83,7 +88,8 @@ discard block |
||
| 83 | 88 | */ |
| 84 | 89 | protected function describeChanges(AbstractTable $table): void |
| 85 | 90 | { |
| 86 | - if (!$this->output->isVerbose()) { |
|
| 91 | + if (!$this->output->isVerbose()) |
|
| 92 | + { |
|
| 87 | 93 | $this->output->writeln( |
| 88 | 94 | sprintf( |
| 89 | 95 | ': <fg=green>%s</fg=green> change(s) detected', |
@@ -96,11 +102,13 @@ discard block |
||
| 96 | 102 | $this->output->write("\n"); |
| 97 | 103 | |
| 98 | 104 | |
| 99 | - if (!$table->exists()) { |
|
| 105 | + if (!$table->exists()) |
|
| 106 | + { |
|
| 100 | 107 | $this->output->writeln(' - create table'); |
| 101 | 108 | } |
| 102 | 109 | |
| 103 | - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
|
| 110 | + if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) |
|
| 111 | + { |
|
| 104 | 112 | $this->output->writeln(' - drop table'); |
| 105 | 113 | return; |
| 106 | 114 | } |
@@ -117,15 +125,18 @@ discard block |
||
| 117 | 125 | */ |
| 118 | 126 | protected function describeColumns(Comparator $cmp): void |
| 119 | 127 | { |
| 120 | - foreach ($cmp->addedColumns() as $column) { |
|
| 128 | + foreach ($cmp->addedColumns() as $column) |
|
| 129 | + { |
|
| 121 | 130 | $this->output->writeln(" - add column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 122 | 131 | } |
| 123 | 132 | |
| 124 | - foreach ($cmp->droppedColumns() as $column) { |
|
| 133 | + foreach ($cmp->droppedColumns() as $column) |
|
| 134 | + { |
|
| 125 | 135 | $this->output->writeln(" - drop column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 126 | 136 | } |
| 127 | 137 | |
| 128 | - foreach ($cmp->alteredColumns() as $column) { |
|
| 138 | + foreach ($cmp->alteredColumns() as $column) |
|
| 139 | + { |
|
| 129 | 140 | $column = $column[0]; |
| 130 | 141 | $this->output->writeln(" - alter column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 131 | 142 | } |
@@ -136,17 +147,20 @@ discard block |
||
| 136 | 147 | */ |
| 137 | 148 | protected function describeIndexes(Comparator $cmp): void |
| 138 | 149 | { |
| 139 | - foreach ($cmp->addedIndexes() as $index) { |
|
| 150 | + foreach ($cmp->addedIndexes() as $index) |
|
| 151 | + { |
|
| 140 | 152 | $index = join(', ', $index->getColumns()); |
| 141 | 153 | $this->output->writeln(" - add index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 142 | 154 | } |
| 143 | 155 | |
| 144 | - foreach ($cmp->droppedIndexes() as $index) { |
|
| 156 | + foreach ($cmp->droppedIndexes() as $index) |
|
| 157 | + { |
|
| 145 | 158 | $index = join(', ', $index->getColumns()); |
| 146 | 159 | $this->output->writeln(" - drop index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 147 | 160 | } |
| 148 | 161 | |
| 149 | - foreach ($cmp->alteredIndexes() as $index) { |
|
| 162 | + foreach ($cmp->alteredIndexes() as $index) |
|
| 163 | + { |
|
| 150 | 164 | $index = $index[0]; |
| 151 | 165 | $index = join(', ', $index->getColumns()); |
| 152 | 166 | $this->output->writeln(" - alter index on <fg=yellow>[{$index}]</fg=yellow>"); |
@@ -158,17 +172,20 @@ discard block |
||
| 158 | 172 | */ |
| 159 | 173 | protected function describeFKs(Comparator $cmp): void |
| 160 | 174 | { |
| 161 | - foreach ($cmp->addedForeignKeys() as $fk) { |
|
| 175 | + foreach ($cmp->addedForeignKeys() as $fk) |
|
| 176 | + { |
|
| 162 | 177 | $fkColumns = join(', ', $fk->getColumns()); |
| 163 | 178 | $this->output->writeln(" - add foreign key on <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 164 | 179 | } |
| 165 | 180 | |
| 166 | - foreach ($cmp->droppedForeignKeys() as $fk) { |
|
| 181 | + foreach ($cmp->droppedForeignKeys() as $fk) |
|
| 182 | + { |
|
| 167 | 183 | $fkColumns = join(', ', $fk->getColumns()); |
| 168 | 184 | $this->output->writeln(" - drop foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 169 | 185 | } |
| 170 | 186 | |
| 171 | - foreach ($cmp->alteredForeignKeys() as $fk) { |
|
| 187 | + foreach ($cmp->alteredForeignKeys() as $fk) |
|
| 188 | + { |
|
| 172 | 189 | $fk = $fk[0]; |
| 173 | 190 | $fkColumns = join(', ', $fk->getColumns()); |
| 174 | 191 | $this->output->writeln(" - alter foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | |
| 44 | 44 | $memory->saveData('cycle', $schema); |
| 45 | 45 | |
| 46 | - if ($show->hasChanges()) { |
|
| 46 | + if ($show->hasChanges()){ |
|
| 47 | 47 | $this->writeln("\n<info>ORM Schema has been synchronized</info>"); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -43,7 +43,8 @@ |
||
| 43 | 43 | |
| 44 | 44 | $memory->saveData('cycle', $schema); |
| 45 | 45 | |
| 46 | - if ($show->hasChanges()) { |
|
| 46 | + if ($show->hasChanges()) |
|
| 47 | + { |
|
| 47 | 48 | $this->writeln("\n<info>ORM Schema has been synchronized</info>"); |
| 48 | 49 | } |
| 49 | 50 | } |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | Migrator $migrator, |
| 57 | 57 | Console $console |
| 58 | 58 | ): void { |
| 59 | - if (!$this->verifyConfigured()) { |
|
| 59 | + if (!$this->verifyConfigured()){ |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - foreach ($migrator->getMigrations() as $migration) { |
|
| 64 | - if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED) { |
|
| 63 | + foreach ($migrator->getMigrations() as $migration){ |
|
| 64 | + if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED){ |
|
| 65 | 65 | $this->writeln('<fg=red>Outstanding migrations found, run `migrate` first.</fg=red>'); |
| 66 | 66 | return; |
| 67 | 67 | } |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | $memory->saveData('cycle', $schema); |
| 78 | 78 | |
| 79 | - if ($show->hasChanges()) { |
|
| 79 | + if ($show->hasChanges()){ |
|
| 80 | 80 | (new Compiler())->compile($registry, [$migrations]); |
| 81 | 81 | |
| 82 | - if ($this->option('run')) { |
|
| 82 | + if ($this->option('run')){ |
|
| 83 | 83 | $console->run('migrate', [], $this->output); |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -56,12 +56,15 @@ discard block |
||
| 56 | 56 | Migrator $migrator, |
| 57 | 57 | Console $console |
| 58 | 58 | ): void { |
| 59 | - if (!$this->verifyConfigured()) { |
|
| 59 | + if (!$this->verifyConfigured()) |
|
| 60 | + { |
|
| 60 | 61 | return; |
| 61 | 62 | } |
| 62 | 63 | |
| 63 | - foreach ($migrator->getMigrations() as $migration) { |
|
| 64 | - if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED) { |
|
| 64 | + foreach ($migrator->getMigrations() as $migration) |
|
| 65 | + { |
|
| 66 | + if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED) |
|
| 67 | + { |
|
| 65 | 68 | $this->writeln('<fg=red>Outstanding migrations found, run `migrate` first.</fg=red>'); |
| 66 | 69 | return; |
| 67 | 70 | } |
@@ -76,10 +79,12 @@ discard block |
||
| 76 | 79 | |
| 77 | 80 | $memory->saveData('cycle', $schema); |
| 78 | 81 | |
| 79 | - if ($show->hasChanges()) { |
|
| 82 | + if ($show->hasChanges()) |
|
| 83 | + { |
|
| 80 | 84 | (new Compiler())->compile($registry, [$migrations]); |
| 81 | 85 | |
| 82 | - if ($this->option('run')) { |
|
| 86 | + if ($this->option('run')) |
|
| 87 | + { |
|
| 83 | 88 | $console->run('migrate', [], $this->output); |
| 84 | 89 | } |
| 85 | 90 | } |
@@ -28,18 +28,18 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function perform(FilesInterface $files): void |
| 30 | 30 | { |
| 31 | - if (!$this->verifyConfigured()) { |
|
| 31 | + if (!$this->verifyConfigured()){ |
|
| 32 | 32 | return; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if (empty($this->migrator->getMigrations())) { |
|
| 35 | + if (empty($this->migrator->getMigrations())){ |
|
| 36 | 36 | $this->writeln('<comment>No migrations were found.</comment>'); |
| 37 | 37 | |
| 38 | 38 | return; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $table = $this->table(['Migration', 'Created at', 'Executed at']); |
| 42 | - foreach ($this->migrator->getMigrations() as $migration) { |
|
| 42 | + foreach ($this->migrator->getMigrations() as $migration){ |
|
| 43 | 43 | $state = $migration->getState(); |
| 44 | 44 | |
| 45 | 45 | $table->addRow( |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $state->getTimeCreated()->format('Y-m-d H:i:s'), |
| 49 | 49 | $state->getStatus() == State::STATUS_PENDING |
| 50 | 50 | ? self::PENDING |
| 51 | - : '<info>' . $state->getTimeExecuted()->format('Y-m-d H:i:s') . '</info>' |
|
| 51 | + : '<info>'.$state->getTimeExecuted()->format('Y-m-d H:i:s').'</info>' |
|
| 52 | 52 | ] |
| 53 | 53 | ); |
| 54 | 54 | } |
@@ -28,18 +28,21 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | public function perform(FilesInterface $files): void |
| 30 | 30 | { |
| 31 | - if (!$this->verifyConfigured()) { |
|
| 31 | + if (!$this->verifyConfigured()) |
|
| 32 | + { |
|
| 32 | 33 | return; |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | - if (empty($this->migrator->getMigrations())) { |
|
| 36 | + if (empty($this->migrator->getMigrations())) |
|
| 37 | + { |
|
| 36 | 38 | $this->writeln('<comment>No migrations were found.</comment>'); |
| 37 | 39 | |
| 38 | 40 | return; |
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | $table = $this->table(['Migration', 'Created at', 'Executed at']); |
| 42 | - foreach ($this->migrator->getMigrations() as $migration) { |
|
| 44 | + foreach ($this->migrator->getMigrations() as $migration) |
|
| 45 | + { |
|
| 43 | 46 | $state = $migration->getState(); |
| 44 | 47 | |
| 45 | 48 | $table->addRow( |