Skip to content

Better respect blacklist and whitelist #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ env:
matrix:
fast_finish: true
include:
# Run test with code coverage
- php: 7.2
env: COVERAGE=true TEST_COMMAND="composer test-ci"

# Test with lowest dependencies
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak" SYMFONY_PHPUNIT_VERSION="5.7"
Expand All @@ -30,8 +34,6 @@ matrix:
env: SYMFONY_PHPUNIT_VERSION="5.7"
- php: 7.0
- php: 7.1
- php: 7.2
env: COVERAGE=true TEST_COMMAND="composer test-ci"

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

before_install:
- INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- if [[ $COVERAGE == true ]]; then echo max_execution_time = 600 >> $INI_FILE; fi
- if [[ $COVERAGE == true ]]; then echo "max_execution_time = 600" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
Expand Down
31 changes: 31 additions & 0 deletions Catalogue/CatalogueFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Translation\Bundle\Catalogue;

use Nyholm\NSA;
use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader as SymfonyTranslationLoader;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
Expand Down Expand Up @@ -67,9 +68,39 @@ public function getCatalogues(Configuration $config, array $locales = [])
$this->reader->read($path, $currentCatalogue);
}
}

foreach ($currentCatalogue->getDomains() as $domain) {
if (!$this->isValidDomain($config, $domain)) {
$messages = $currentCatalogue->all();
unset($messages[$domain]);
NSA::setProperty($currentCatalogue, 'messages', $messages);
}
}

$catalogues[] = $currentCatalogue;
}

return $catalogues;
}

/**
* @param string $domain
*
* @return bool
*/
private function isValidDomain(Configuration $config, $domain)
{
$blacklist = $config->getBlacklistDomains();
$whitelist = $config->getWhitelistDomains();

if (!empty($blacklist) && in_array($domain, $blacklist)) {
return false;
}

if (!empty($whitelist) && !in_array($domain, $whitelist)) {
return false;
}

return true;
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

"php-translation/common": "^0.3",
"php-translation/symfony-storage": "^0.5.0",
"php-translation/extractor": "^1.3"
"php-translation/extractor": "^1.3",
"nyholm/nsa": "^1.1"
},
"require-dev": {
"symfony/phpunit-bridge": "^3.4 || ^4.0",
Expand All @@ -37,7 +38,6 @@
"matthiasnoback/symfony-dependency-injection-test": "^1.2 || ^2.3",
"matthiasnoback/symfony-config-test": "^2.2 || ^3.1",
"guzzlehttp/psr7": "^1.4",
"nyholm/nsa": "^1.1",
"nyholm/symfony-bundle-test": "^1.2.3"
},
"suggest": {
Expand Down