Since: 1.0
Author: Bernhard Schussek (bschussek@gmail.com)
 /**
  * {@inheritdoc}
  */
 public function leaveExpression(Expression $expr)
 {
     if ($expr instanceof Key) {
         switch ($expr->getKey()) {
             case AssetMapping::UUID:
                 return Expr::key(BindingDescriptor::UUID, $expr->getExpression());
             case AssetMapping::GLOB:
                 $queryExpr = $expr->getExpression();
                 if ($queryExpr instanceof Same) {
                     $queryExpr = Expr::same($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof Equals) {
                     $queryExpr = Expr::equals($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof NotSame) {
                     $queryExpr = Expr::notSame($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof NotEquals) {
                     $queryExpr = Expr::notEquals($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof EndsWith) {
                     $queryExpr = Expr::endsWith($queryExpr->getAcceptedSuffix() . '{,/**/*}');
                 }
                 return Expr::key(BindingDescriptor::QUERY, $queryExpr);
             case AssetMapping::SERVER_NAME:
                 return Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key(DiscoveryUrlGenerator::SERVER_PARAMETER, $expr->getExpression()));
             case AssetMapping::SERVER_PATH:
                 return Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key(DiscoveryUrlGenerator::PATH_PARAMETER, $expr->getExpression()));
         }
     }
     return $expr;
 }
 /**
  * {@inheritdoc}
  */
 public function leaveExpression(Expression $expr)
 {
     if ($expr instanceof Method) {
         switch ($expr->getMethodName()) {
             case 'getUuid':
                 return Expr::method('getUuid', $expr->getExpression());
             case 'getGlob':
                 $queryExpr = $expr->getExpression();
                 if ($queryExpr instanceof Same) {
                     $queryExpr = Expr::same($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof Equals) {
                     $queryExpr = Expr::equals($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof NotSame) {
                     $queryExpr = Expr::notSame($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof NotEquals) {
                     $queryExpr = Expr::notEquals($queryExpr->getComparedValue() . '{,/**/*}');
                 } elseif ($queryExpr instanceof EndsWith) {
                     $queryExpr = Expr::endsWith($queryExpr->getAcceptedSuffix() . '{,/**/*}');
                 }
                 return Expr::method('getBinding', Expr::method('getQuery', $queryExpr));
             case 'getServerName':
                 return Expr::method('getParameterValue', DiscoveryUrlGenerator::SERVER_PARAMETER, $expr->getExpression());
             case 'getServerPath':
                 return Expr::method('getParameterValue', DiscoveryUrlGenerator::PATH_PARAMETER, $expr->getExpression());
         }
     }
     return $expr;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function equivalentTo(Expression $other)
 {
     if (1 === count($this->acceptedValues)) {
         // In is logically equivalent to Same if strict and only one value
         if ($this->strict && $other instanceof Same) {
             return reset($this->acceptedValues) === $other->getComparedValue();
         }
         // In is logically equivalent to Equals if not strict and only one value
         if (!$this->strict && $other instanceof Equals) {
             return reset($this->acceptedValues) == $other->getComparedValue();
         }
     }
     // Since this class is final, we can check with instanceof
     if (!$other instanceof $this) {
         return false;
     }
     if ($this->strict !== $other->strict) {
         return false;
     }
     if (!$this->strict) {
         return $this->acceptedValues == $other->acceptedValues;
     }
     $acceptedValuesLeft = $this->acceptedValues;
     $acceptedValuesRight = $other->acceptedValues;
     // Ignore order
     sort($acceptedValuesLeft);
     sort($acceptedValuesRight);
     return $acceptedValuesLeft === $acceptedValuesRight;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function equivalentTo(Expression $other)
 {
     if (get_class($this) !== get_class($other)) {
         return false;
     }
     /* @var Selector $other */
     return $this->expr->equivalentTo($other->expr);
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function equivalentTo(Expression $other)
 {
     if ($other instanceof In && $other->isStrict()) {
         return array($this->comparedValue) === $other->getAcceptedValues();
     }
     // Since this class is final, we can check with instanceof
     return $other instanceof $this && $this->comparedValue === $other->comparedValue;
 }
 /**
  * Returns whether the binding type matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link NAME}, {@link PARAMETERS},
  *                         {@link STATE} and {@link CONTAINING_PACKAGE}
  *                         in the expression.
  *
  * @return bool Returns `true` if the binding type matches the expression
  *              and `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::NAME => $this->name, self::STATE => $this->state, self::CONTAINING_PACKAGE => $this->containingPackage->getName()));
 }
 /**
  * {@inheritdoc}
  */
 public function findExtraKeys(Expression $expr)
 {
     $values = array();
     foreach ($this->rootPackageFile->getExtraKeys() as $key => $value) {
         if ($expr->evaluate($key)) {
             $values[$key] = $value;
         }
     }
     return $values;
 }
Beispiel #8
0
 /**
  * Returns whether the binding matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link UUID}, {@link QUERY}, {@link LANGUAGE},
  *                         {@link TYPE_NAME}, {@link STATE} and
  *                         {@link CONTAINING_PACKAGE} in the expression.
  *
  * @return bool Returns `true` if the binding matches the expression and
  *              `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::UUID => $this->uuid->toString(), self::QUERY => $this->query, self::LANGUAGE => $this->language, self::TYPE_NAME => $this->typeName, self::PARAMETER_VALUES => $this->parameterValues, self::STATE => $this->state, self::CONTAINING_PACKAGE => $this->containingPackage->getName()));
 }
 protected function hasBindingsWithTypeNameThatMatch($typeName, Expression $expr)
 {
     if (!$this->hasBindingsWithTypeName($typeName)) {
         return false;
     }
     $key = $this->keysByTypeName[$typeName];
     if (!isset($this->bindingsByKey[$key])) {
         $this->loadBindingsForKey($key);
     }
     foreach ($this->bindingsByKey[$key] as $binding) {
         if ($expr->evaluate($binding)) {
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function hasServers(Expression $expr = null)
 {
     $this->assertServersLoaded();
     if (!$expr) {
         return !$this->servers->isEmpty();
     }
     foreach ($this->servers as $server) {
         if ($expr->evaluate($server)) {
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function hasInstallerDescriptors(Expression $expr = null)
 {
     $this->assertInstallersLoaded();
     if (!$expr) {
         return count($this->installerDescriptors) > 0;
     }
     foreach ($this->installerDescriptors as $installer) {
         if ($expr->evaluate($installer)) {
             return true;
         }
     }
     return false;
 }
Beispiel #12
0
 /**
  * Returns whether the package matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link NAME}, {@link INSTALL_PATH} and
  *                         {@link STATE} in the expression.
  *
  * @return bool Returns `true` if the package matches the expression and
  *              `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::NAME => $this->name, self::INSTALL_PATH => $this->installPath, self::STATE => $this->state, self::INSTALLER => $this->installInfo ? $this->installInfo->getInstallerName() : null, self::ENVIRONMENT => $this->installInfo ? $this->installInfo->getEnvironment() : Environment::PROD));
 }
Beispiel #13
0
 /**
  * Filter a collection for entries matching the expression.
  *
  * @param array|ArrayAccess|Traversable $collection An array or an object
  *                                                  implementing Traversable
  *                                                  and ArrayAccess.
  * @param Expression                    $expr       The expression to
  *                                                  evaluate for each entry.
  *
  * @return array|ArrayAccess|Traversable The filtered collection.
  */
 public static function filter($collection, Expression $expr)
 {
     if (is_array($collection)) {
         return array_filter($collection, array($expr, 'evaluate'));
     }
     if (!($collection instanceof Traversable && $collection instanceof ArrayAccess)) {
         throw new InvalidArgumentException(sprintf('Expected an array or an instance of Traversable and ArrayAccess. Got: %s', is_object($collection) ? get_class($collection) : gettype($collection)));
     }
     $clone = clone $collection;
     foreach ($collection as $key => $value) {
         if (!$expr->evaluate($value)) {
             unset($clone[$key]);
         }
     }
     return $clone;
 }
 /**
  * @dataProvider getNonEquivalentCriteria
  */
 public function testNonEquivalence(Expression $left, Expression $right)
 {
     $this->assertFalse($left->equivalentTo($right));
     $this->assertFalse($right->equivalentTo($left));
 }
 /**
  * {@inheritdoc}
  */
 public function findConfigKeys(Expression $expr, $includeFallback = false, $includeUnset = false, $raw = true)
 {
     Assert::boolean($includeFallback, 'The argument $includeFallback must be a boolean.');
     Assert::boolean($includeUnset, 'The argument $includeUnset must be a boolean.');
     $values = array();
     foreach ($this->getConfigKeys($includeFallback, $includeUnset, $raw) as $key => $value) {
         if ($expr->evaluate($key)) {
             $values[$key] = $value;
         }
     }
     return $values;
 }
Beispiel #16
0
 /**
  * {@inheritdoc}
  */
 public function hasPathMappings(Expression $expr = null)
 {
     $this->assertMappingsLoaded();
     if (!$expr) {
         return !$this->mappings->isEmpty();
     }
     foreach ($this->mappings->toArray() as $mappingsByModule) {
         foreach ($mappingsByModule as $mapping) {
             if ($expr->evaluate($mapping)) {
                 return true;
             }
         }
     }
     return false;
 }
Beispiel #17
0
 /**
  * Returns whether the target matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link NAME}, {@link CLASS_NAME},
  *                         {@link LOCATION}, {@link URL_FORMAT} and
  *                         {@link PARAMETER_VALUES} in the expression.
  *
  * @return bool Returns `true` if the target matches the expression and
  *              `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::NAME => $this->name, self::INSTALLER_NAME => $this->installerName, self::LOCATION => $this->location, self::URL_FORMAT => $this->urlFormat, self::PARAMETER_VALUES => $this->parameterValues));
 }
Beispiel #18
0
 /**
  * Returns whether the path mapping matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link REPOSITORY_PATH}, {@link STATE} and
  *                         {@link CONTAINING_PACKAGE} in the expression.
  *
  * @return bool Returns `true` if the path mapping matches the expression
  *              and `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::REPOSITORY_PATH => $this->repositoryPath, self::STATE => $this->state, self::CONTAINING_PACKAGE => $this->containingPackage->getName()));
 }
Beispiel #19
0
 /**
  * Returns whether the installer matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link NAME}, {@link CLASS_NAME} and
  *                         {@link DESCRIPTION} in the expression.
  *
  * @return bool Returns `true` if the installer matches the expression and
  *              `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::NAME => $this->name, self::CLASS_NAME => $this->className, self::DESCRIPTION => $this->description));
 }
Beispiel #20
0
 /**
  * Returns whether the package matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link NAME}, {@link INSTALL_PATH} and
  *                         {@link STATE} in the expression.
  *
  * @return bool Returns `true` if the package matches the expression and
  *              `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::NAME => $this->name, self::INSTALL_PATH => $this->installPath, self::STATE => $this->state, self::INSTALLER => $this->installInfo ? $this->installInfo->getInstallerName() : null));
 }
Beispiel #21
0
 /**
  * Returns whether the server matches the given expression.
  *
  * @param Expression $expr The search criteria. You can use the fields
  *                         {@link NAME}, {@link INSTALLER_NAME},
  *                         {@link DOCUMENT_ROOT}, {@link URL_FORMAT} and
  *                         {@link PARAMETER_VALUES} in the expression.
  *
  * @return bool Returns `true` if the server matches the expression and
  *              `false` otherwise.
  */
 public function match(Expression $expr)
 {
     return $expr->evaluate(array(self::NAME => $this->name, self::INSTALLER_NAME => $this->installerName, self::DOCUMENT_ROOT => $this->documentRoot, self::URL_FORMAT => $this->urlFormat, self::PARAMETER_VALUES => $this->parameterValues));
 }
Beispiel #22
0
 /**
  * {@inheritdoc}
  */
 public function hasBindingDescriptors(Expression $expr = null)
 {
     $this->assertModulesLoaded();
     if (!$expr) {
         return !$this->bindingDescriptors->isEmpty();
     }
     foreach ($this->bindingDescriptors->toArray() as $bindingDescriptor) {
         if ($expr->evaluate($bindingDescriptor)) {
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function hasModules(Expression $expr = null)
 {
     $this->assertModulesLoaded();
     if (!$expr) {
         return !$this->modules->isEmpty();
     }
     foreach ($this->modules as $module) {
         if ($expr->evaluate($module)) {
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 protected function removeBindingsWithTypeNameThatMatch($typeName, Expression $expr)
 {
     if (!isset($this->bindingsByTypeName[$typeName])) {
         return;
     }
     foreach ($this->bindingsByTypeName[$typeName] as $uuidString => $binding) {
         if ($expr->evaluate($binding)) {
             unset($this->bindings[$uuidString]);
             unset($this->bindingsByTypeName[$typeName][$uuidString]);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function hasBindingsWithTypeNameThatMatch($typeName, Expression $expr)
 {
     if (!isset($this->bindingsByTypeName[$typeName])) {
         return false;
     }
     foreach ($this->bindingsByTypeName[$typeName] as $binding) {
         if ($expr->evaluate($binding)) {
             return true;
         }
     }
     return false;
 }