-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dumper config initialization
- Loading branch information
Showing
26 changed files
with
384 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\GdprDump\Config\Compiler\Processor; | ||
|
||
use Smile\GdprDump\Config\ConfigInterface; | ||
|
||
class DumpOutputProcessor implements ProcessorInterface | ||
{ | ||
/** | ||
* Process date placeholders in dump output (e.g. "dump-{Y-m-d-H.i.s}.sql"). | ||
*/ | ||
public function process(ConfigInterface $config): void | ||
{ | ||
$dumpSettings = $config->get('dump', []); | ||
|
||
if (array_key_exists('output', $dumpSettings)) { | ||
$dumpSettings['output'] = preg_replace_callback( | ||
'/{([^}]+)}/', | ||
fn (array $matches) => date($matches[1]), | ||
$dumpSettings['output'] | ||
); | ||
|
||
$config->set('dump', $dumpSettings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\GdprDump\Dumper\Config\Definition; | ||
|
||
class FakerSettings | ||
{ | ||
public function __construct(private string $locale) | ||
{ | ||
} | ||
|
||
/** | ||
* Get the faker locale. | ||
*/ | ||
public function getLocale(): string | ||
{ | ||
return $this->locale; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Dumper/Config/Definition/FilterPropagationSettings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\GdprDump\Dumper\Config\Definition; | ||
|
||
class FilterPropagationSettings | ||
{ | ||
public function __construct(private bool $enabled, private array $ignoredForeignKeys) | ||
{ | ||
} | ||
|
||
/** | ||
* Checker whether filter propagation is enabled. | ||
*/ | ||
public function isEnabled(): bool | ||
{ | ||
return $this->enabled; | ||
} | ||
|
||
/** | ||
* Get foreign keys to ignore when propagating filters to table dependencies. | ||
*/ | ||
public function getIgnoredForeignKeys(): array | ||
{ | ||
return $this->ignoredForeignKeys; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Smile\GdprDump\Dumper\Config\Definition; | ||
|
||
use ArrayIterator; | ||
use IteratorAggregate; | ||
use Traversable; | ||
use UnexpectedValueException; | ||
|
||
/** | ||
* @implements IteratorAggregate<TableConfig> | ||
*/ | ||
class TableConfigCollection implements IteratorAggregate | ||
{ | ||
/** | ||
* @var TableConfig[] | ||
*/ | ||
private array $items = []; | ||
|
||
/**+ | ||
* Add an item. | ||
*/ | ||
public function add(TableConfig $tableConfig): void | ||
{ | ||
$this->items[$tableConfig->getName()] = $tableConfig; | ||
} | ||
|
||
/** | ||
* Get an item. | ||
* | ||
* @throws UnexpectedValueException | ||
*/ | ||
public function get(string $name): TableConfig | ||
{ | ||
return $this->has($name) | ||
? $this->items[$name] | ||
: throw new UnexpectedValueException(sprintf('The table "%s" is not defined.', $name)); | ||
} | ||
|
||
/** | ||
* Check whether an item exists. | ||
*/ | ||
public function has(string $name): bool | ||
{ | ||
return array_key_exists($name, $this->items); | ||
} | ||
|
||
/** | ||
* Get all items. | ||
* | ||
* @return TableConfig[] | ||
*/ | ||
public function all(): array | ||
{ | ||
return $this->items; | ||
} | ||
|
||
/** | ||
* @return ArrayIterator<string, TableConfig> | ||
*/ | ||
public function getIterator(): Traversable | ||
{ | ||
return new ArrayIterator($this->items); | ||
} | ||
} |
Oops, something went wrong.