9 use InvalidArgumentException;
24 private $scopeResolverPool;
31 $this->scopeResolverPool = $scopeResolverPool;
37 public function isValid($scope, $scopeCode =
null)
45 'The "%1" scope can\'t include a scope code. Try again without entering a scope code.',
54 $this->validateScopeCode($scopeCode);
57 $scopeResolver = $this->scopeResolverPool->get($scope);
58 $scopeResolver->getScope($scopeCode)->getId();
59 }
catch (InvalidArgumentException $e) {
61 new Phrase(
'The "%1" value doesn\'t exist. Enter another value and try again.', [$scope])
65 new Phrase(
'The "%1" value doesn\'t exist. Enter another value and try again.', [$scopeCode])
80 private function validateScopeCode($scopeCode)
82 if (empty($scopeCode)) {
86 if (!preg_match(
'/^[a-z]+[a-z0-9_]*$/', $scopeCode)) {
88 'The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores (_). ' 89 .
'Also, the first character must be a letter.'
__construct(ScopeResolverPool $scopeResolverPool)
isValid($scope, $scopeCode=null)