diff --git a/.travis.yml b/.travis.yml index 1294fdf0..27b527c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" @@ -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 @@ -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; diff --git a/Catalogue/CatalogueFetcher.php b/Catalogue/CatalogueFetcher.php index 4b666307..3ef2e093 100644 --- a/Catalogue/CatalogueFetcher.php +++ b/Catalogue/CatalogueFetcher.php @@ -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; @@ -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; + } } diff --git a/composer.json b/composer.json index 1e1fda6c..01877823 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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": {