Skip to content

Commit 92d74ea

Browse files
authored
Better respect blacklist and whitelist (#220)
* Better respect blacklist and whitelist * travis fix * Move around builds
1 parent b1a77c6 commit 92d74ea

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ env:
1717
matrix:
1818
fast_finish: true
1919
include:
20+
# Run test with code coverage
21+
- php: 7.2
22+
env: COVERAGE=true TEST_COMMAND="composer test-ci"
23+
2024
# Test with lowest dependencies
2125
- php: 7.1
2226
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak" SYMFONY_PHPUNIT_VERSION="5.7"
@@ -30,8 +34,6 @@ matrix:
3034
env: SYMFONY_PHPUNIT_VERSION="5.7"
3135
- php: 7.0
3236
- php: 7.1
33-
- php: 7.2
34-
env: COVERAGE=true TEST_COMMAND="composer test-ci"
3537

3638
# Force some major versions of Symfony
3739
- php: 7.2
@@ -52,8 +54,7 @@ matrix:
5254
- env: STABILITY="dev"
5355

5456
before_install:
55-
- INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
56-
- if [[ $COVERAGE == true ]]; then echo max_execution_time = 600 >> $INI_FILE; fi
57+
- if [[ $COVERAGE == true ]]; then echo "max_execution_time = 600" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
5758
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
5859
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
5960
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;

Catalogue/CatalogueFetcher.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Translation\Bundle\Catalogue;
1313

14+
use Nyholm\NSA;
1415
use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader as SymfonyTranslationLoader;
1516
use Symfony\Component\Translation\MessageCatalogue;
1617
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
@@ -67,9 +68,39 @@ public function getCatalogues(Configuration $config, array $locales = [])
6768
$this->reader->read($path, $currentCatalogue);
6869
}
6970
}
71+
72+
foreach ($currentCatalogue->getDomains() as $domain) {
73+
if (!$this->isValidDomain($config, $domain)) {
74+
$messages = $currentCatalogue->all();
75+
unset($messages[$domain]);
76+
NSA::setProperty($currentCatalogue, 'messages', $messages);
77+
}
78+
}
79+
7080
$catalogues[] = $currentCatalogue;
7181
}
7282

7383
return $catalogues;
7484
}
85+
86+
/**
87+
* @param string $domain
88+
*
89+
* @return bool
90+
*/
91+
private function isValidDomain(Configuration $config, $domain)
92+
{
93+
$blacklist = $config->getBlacklistDomains();
94+
$whitelist = $config->getWhitelistDomains();
95+
96+
if (!empty($blacklist) && in_array($domain, $blacklist)) {
97+
return false;
98+
}
99+
100+
if (!empty($whitelist) && !in_array($domain, $whitelist)) {
101+
return false;
102+
}
103+
104+
return true;
105+
}
75106
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
"php-translation/common": "^0.3",
2222
"php-translation/symfony-storage": "^0.5.0",
23-
"php-translation/extractor": "^1.3"
23+
"php-translation/extractor": "^1.3",
24+
"nyholm/nsa": "^1.1"
2425
},
2526
"require-dev": {
2627
"symfony/phpunit-bridge": "^3.4 || ^4.0",
@@ -37,7 +38,6 @@
3738
"matthiasnoback/symfony-dependency-injection-test": "^1.2 || ^2.3",
3839
"matthiasnoback/symfony-config-test": "^2.2 || ^3.1",
3940
"guzzlehttp/psr7": "^1.4",
40-
"nyholm/nsa": "^1.1",
4141
"nyholm/symfony-bundle-test": "^1.2.3"
4242
},
4343
"suggest": {

0 commit comments

Comments
 (0)