key() public static method

Check that the value of an array key matches an expression.
public static key ( string | integer $key, Webmozart\Expression\Expression $expr ) : Key
$key string | integer The array key.
$expr Webmozart\Expression\Expression The evaluated expression.
return Webmozart\Expression\Selector\Key The created expression.
 public function testBuildExpressionWithCustomCriteria()
 {
     $expr1 = Expr::startsWith('abcd', AssetMapping::UUID)->orSame('local', AssetMapping::SERVER_NAME)->orX(Expr::same('/path', AssetMapping::GLOB)->andSame('css', AssetMapping::SERVER_PATH));
     $expr2 = Expr::same(BindingState::ENABLED, BindingDescriptor::STATE)->andSame(DiscoveryUrlGenerator::BINDING_TYPE, BindingDescriptor::TYPE_NAME)->andEndsWith('{,/**/*}', BindingDescriptor::QUERY)->andX(Expr::startsWith('abcd', BindingDescriptor::UUID)->orKey(BindingDescriptor::PARAMETER_VALUES, Expr::key(DiscoveryUrlGenerator::SERVER_PARAMETER, Expr::same('local')))->orX(Expr::same('/path{,/**/*}', BindingDescriptor::QUERY)->andKey(BindingDescriptor::PARAMETER_VALUES, Expr::key(DiscoveryUrlGenerator::PATH_PARAMETER, Expr::same('css')))));
     $this->assertEquals($expr2, $this->builder->buildExpression($expr1));
 }
Exemplo n.º 2
0
 public function orKey($keyName, Expression $expr)
 {
     return $this->orX(Expr::key($keyName, $expr));
 }
 /**
  * {@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;
 }
 private function webPath($path)
 {
     return $this->defaultExpr()->andKey(BindingDescriptor::PARAMETER_VALUES, Expr::key(DiscoveryUrlGenerator::PATH_PARAMETER, Expr::same($path)));
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 protected function transform(Expression $expression)
 {
     $constraint = $expression->getConstraint();
     return Expr::key($expression->getSelector(), new $constraint($expression->getValue()));
 }
Exemplo n.º 6
0
 public function testRemovePackages()
 {
     $this->initDefaultManager();
     $packageDir = $this->packageDir1;
     $this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->with($this->rootPackageFile)->will($this->returnCallback(function (RootPackageFile $rootPackageFile) use($packageDir) {
         PHPUnit_Framework_Assert::assertFalse($rootPackageFile->hasInstallInfo('vendor/package1'));
         PHPUnit_Framework_Assert::assertFalse($rootPackageFile->hasInstallInfo('vendor/package2'));
         PHPUnit_Framework_Assert::assertTrue($rootPackageFile->hasInstallInfo('vendor/package3'));
     }));
     $this->rootPackageFile->addInstallInfo($this->installInfo3);
     $this->assertTrue($this->rootPackageFile->hasInstallInfo('vendor/package1'));
     $this->assertTrue($this->rootPackageFile->hasInstallInfo('vendor/package2'));
     $this->assertTrue($this->rootPackageFile->hasInstallInfo('vendor/package3'));
     $this->assertTrue($this->manager->hasPackage('vendor/root'));
     $this->assertTrue($this->manager->hasPackage('vendor/package1'));
     $this->assertTrue($this->manager->hasPackage('vendor/package2'));
     $this->assertTrue($this->manager->hasPackage('vendor/package3'));
     $this->manager->removePackages(Expr::key(Package::NAME, Expr::endsWith('1')->orEndsWith('2')));
     $this->assertFalse($this->rootPackageFile->hasInstallInfo('vendor/package1'));
     $this->assertFalse($this->rootPackageFile->hasInstallInfo('vendor/package2'));
     $this->assertTrue($this->rootPackageFile->hasInstallInfo('vendor/package3'));
     $this->assertTrue($this->manager->hasPackage('vendor/root'));
     $this->assertFalse($this->manager->hasPackage('vendor/package1'));
     $this->assertFalse($this->manager->hasPackage('vendor/package2'));
     $this->assertTrue($this->manager->hasPackage('vendor/package3'));
 }
Exemplo n.º 7
0
 public function testMatch()
 {
     $server = new Server('localhost', 'symlink', 'web', '/%s', array('param1' => 'value1', 'param2' => 'value2'));
     $this->assertFalse($server->match(Expr::same('foobar', Server::NAME)));
     $this->assertTrue($server->match(Expr::same('localhost', Server::NAME)));
     $this->assertFalse($server->match(Expr::same('foobar', Server::INSTALLER_NAME)));
     $this->assertTrue($server->match(Expr::same('symlink', Server::INSTALLER_NAME)));
     $this->assertFalse($server->match(Expr::same('foobar', Server::DOCUMENT_ROOT)));
     $this->assertTrue($server->match(Expr::same('web', Server::DOCUMENT_ROOT)));
     $this->assertFalse($server->match(Expr::same('foobar', Server::URL_FORMAT)));
     $this->assertTrue($server->match(Expr::same('/%s', Server::URL_FORMAT)));
     $this->assertFalse($server->match(Expr::key(Server::PARAMETER_VALUES, Expr::keyExists('foobar'))));
     $this->assertTrue($server->match(Expr::key(Server::PARAMETER_VALUES, Expr::keyExists('param1'))));
 }
 public function testMatch()
 {
     $type = new BindingTypeDescriptor('vendor/type', null, array(new BindingParameterDescriptor('param')));
     $type->load($this->package);
     $uuid = Uuid::fromString('abcdb814-9dad-11d1-80b4-00c04fd430c8');
     $this->package->getInstallInfo()->addEnabledBindingUuid($uuid);
     $binding = new BindingDescriptor('/path', 'vendor/type', array('param' => 'value'), 'glob', $uuid);
     $binding->load($this->package, $type);
     $this->assertFalse($binding->match(Expr::same('foobar', BindingDescriptor::CONTAINING_PACKAGE)));
     $this->assertTrue($binding->match(Expr::same($this->package->getName(), BindingDescriptor::CONTAINING_PACKAGE)));
     $this->assertFalse($binding->match(Expr::same(BindingState::DISABLED, BindingDescriptor::STATE)));
     $this->assertTrue($binding->match(Expr::same(BindingState::ENABLED, BindingDescriptor::STATE)));
     $this->assertFalse($binding->match(Expr::startsWith('abce', BindingDescriptor::UUID)));
     $this->assertTrue($binding->match(Expr::startsWith('abcd', BindingDescriptor::UUID)));
     $this->assertFalse($binding->match(Expr::same('/path/nested', BindingDescriptor::QUERY)));
     $this->assertTrue($binding->match(Expr::same('/path', BindingDescriptor::QUERY)));
     $this->assertFalse($binding->match(Expr::same('xpath', BindingDescriptor::LANGUAGE)));
     $this->assertTrue($binding->match(Expr::same('glob', BindingDescriptor::LANGUAGE)));
     $this->assertFalse($binding->match(Expr::same('vendor/other', BindingDescriptor::TYPE_NAME)));
     $this->assertTrue($binding->match(Expr::same('vendor/type', BindingDescriptor::TYPE_NAME)));
     $this->assertFalse($binding->match(Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key('param', Expr::same('foobar')))));
     $this->assertTrue($binding->match(Expr::key(BindingDescriptor::PARAMETER_VALUES, Expr::key('param', Expr::same('value')))));
 }
Exemplo n.º 9
0
 public function testMatch()
 {
     $target = new InstallTarget('local', 'symlink', 'web', '/%s', array('param1' => 'value1', 'param2' => 'value2'));
     $this->assertFalse($target->match(Expr::same('foobar', InstallTarget::NAME)));
     $this->assertTrue($target->match(Expr::same('local', InstallTarget::NAME)));
     $this->assertFalse($target->match(Expr::same('foobar', InstallTarget::INSTALLER_NAME)));
     $this->assertTrue($target->match(Expr::same('symlink', InstallTarget::INSTALLER_NAME)));
     $this->assertFalse($target->match(Expr::same('foobar', InstallTarget::LOCATION)));
     $this->assertTrue($target->match(Expr::same('web', InstallTarget::LOCATION)));
     $this->assertFalse($target->match(Expr::same('foobar', InstallTarget::URL_FORMAT)));
     $this->assertTrue($target->match(Expr::same('/%s', InstallTarget::URL_FORMAT)));
     $this->assertFalse($target->match(Expr::key(InstallTarget::PARAMETER_VALUES, Expr::keyExists('foobar'))));
     $this->assertTrue($target->match(Expr::key(InstallTarget::PARAMETER_VALUES, Expr::keyExists('param1'))));
 }
Exemplo n.º 10
0
 public function andKey($keyName, Expression $expr)
 {
     return $this->andX(Expr::key($keyName, $expr));
 }
Exemplo n.º 11
0
 private function webPath($path)
 {
     return $this->defaultExpr()->andKey(BindingDescriptor::PARAMETER_VALUES, Expr::key(AssetPlugin::PATH_PARAMETER, Expr::same($path)));
 }