Skip to content

Commit

Permalink
Added schema filtering class
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Jan 6, 2023
1 parent 6457acf commit dec1299
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Utils/SchemaAssetsFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php declare(strict_types=1);

/**
* @copyright Martin Procházka (c) 2023
* @license MIT License
*/

namespace JuniWalk\ORM\Utils;

use Doctrine\DBAL\Schema\AbstractAsset;
use Nette\Utils\Strings;

final class SchemaAssetsFilter
{
private array $assets;

public function __construct(
string ...$assets
) {
$this->assets = $assets;
}


public function __invoke(string|AbstractAsset $assetName): bool
{
if (empty($this->assets)) {
return true;
}

if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}

if (in_array($assetName, $this->assets)) {
return false;
}

return !Strings::match($assetName, '/'.implode('|', $this->assets).'/i');
}
}

0 comments on commit dec1299

Please sign in to comment.