本文整理汇总了PHP中Webmozart\Expression\Expr::same方法的典型用法代码示例。如果您正苦于以下问题:PHP Expr::same方法的具体用法?PHP Expr::same怎么用?PHP Expr::same使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Webmozart\Expression\Expr
的用法示例。
在下文中一共展示了Expr::same方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleList
/**
* Handles the "bind --list" command.
*
* @param Args $args The console arguments.
* @param IO $io The I/O.
*
* @return int The status code.
*/
public function handleList(Args $args, IO $io)
{
$packageNames = ArgsUtil::getPackageNames($args, $this->packages);
$bindingStates = $this->getBindingStates($args);
$printBindingState = count($bindingStates) > 1;
$printPackageName = count($packageNames) > 1;
$printHeaders = $printBindingState || $printPackageName;
$indentation = $printBindingState && $printPackageName ? 8 : ($printBindingState || $printPackageName ? 4 : 0);
foreach ($bindingStates as $bindingState) {
$bindingStatePrinted = !$printBindingState;
foreach ($packageNames as $packageName) {
$expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName)))->andMethod('getState', Expr::same($bindingState));
$descriptors = $this->discoveryManager->findBindingDescriptors($expr);
if (empty($descriptors)) {
continue;
}
if (!$bindingStatePrinted) {
$this->printBindingStateHeader($io, $bindingState);
$bindingStatePrinted = true;
}
if ($printPackageName) {
$prefix = $printBindingState ? ' ' : '';
$io->writeLine("{$prefix}Package: {$packageName}");
$io->writeLine('');
}
$this->printBindingTable($io, $descriptors, $indentation, BindingState::ENABLED === $bindingState);
if ($printHeaders) {
$io->writeLine('');
}
}
}
return 0;
}
示例2: leaveExpression
/**
* {@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;
}
示例3: leaveExpression
/**
* {@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;
}
示例4: testRemoveBindingsWithTypeAndParameterWorksOnLoadedDiscovery
public function testRemoveBindingsWithTypeAndParameterWorksOnLoadedDiscovery()
{
$binding1 = new StringBinding('string1', Foo::clazz, array('param2' => 'bar'));
$binding2 = new StringBinding('string2', Foo::clazz);
$binding3 = new StringBinding('string3', Foo::clazz, array('param1' => 'bar'));
$discovery = $this->createDiscovery();
$discovery->addBindingType(new BindingType(Foo::clazz, self::STRING_BINDING, array(new BindingParameter('param1', BindingParameter::OPTIONAL, 'foo'), new BindingParameter('param2'))));
$discovery->addBinding($binding1);
$discovery->addBinding($binding2);
$discovery->addBinding($binding3);
$discovery = $this->loadDiscoveryFromStorage($discovery);
// Bindings need to be initialized for this to work
$discovery->removeBindings(Foo::clazz, Expr::method('getParameterValue', 'param1', Expr::same('foo')));
$this->assertEquals(array($binding3), $discovery->findBindings(Foo::clazz));
$this->assertEquals(array($binding3), $discovery->getBindings());
}
示例5: handleList
/**
* Handles the "puli type --list" command.
*
* @param Args $args The console arguments.
* @param IO $io The I/O.
*
* @return int The status code.
*/
public function handleList(Args $args, IO $io)
{
$packageNames = ArgsUtil::getPackageNames($args, $this->packages);
$states = $this->getBindingTypeStates($args);
$printStates = count($states) > 1;
$printPackageName = count($packageNames) > 1;
$printHeaders = $printStates || $printPackageName;
$printTypeAdvice = true;
$printBindAdvice = false;
$indentation = $printStates && $printPackageName ? 8 : ($printStates || $printPackageName ? 4 : 0);
foreach ($states as $state) {
$statePrinted = !$printStates;
foreach ($packageNames as $packageName) {
$expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName)))->andMethod('getState', Expr::same($state));
$bindingTypes = $this->discoveryManager->findTypeDescriptors($expr);
if (!$bindingTypes) {
continue;
}
$printTypeAdvice = false;
if (!$statePrinted) {
$this->printBindingTypeState($io, $state);
$statePrinted = true;
// Only print the advice if at least one type was printed
$printBindAdvice = true;
}
if ($printPackageName) {
$prefix = $printStates ? ' ' : '';
$io->writeLine("{$prefix}Package: {$packageName}");
$io->writeLine('');
}
$styleTag = BindingTypeState::ENABLED === $state ? null : 'bad';
$this->printTypeTable($io, $bindingTypes, $styleTag, $indentation);
if ($printHeaders) {
$io->writeLine('');
}
}
}
if ($printTypeAdvice) {
$io->writeLine('No types defined. Use "puli type --define <name>" to define a type.');
}
if ($printBindAdvice) {
$io->writeLine('Use "puli bind <resource> <type>" to bind a resource to a type.');
}
return 0;
}
示例6: handleList
/**
* Handles the "bind --list" command.
*
* @param Args $args The console arguments
* @param IO $io The I/O
*
* @return int The status code
*/
public function handleList(Args $args, IO $io)
{
$moduleNames = ArgsUtil::getModuleNames($args, $this->modules);
$bindingStates = $this->getBindingStates($args);
$printBindingState = count($bindingStates) > 1;
$printModuleName = count($moduleNames) > 1;
$printHeaders = $printBindingState || $printModuleName;
$printAdvice = true;
$indentation = $printBindingState && $printModuleName ? 8 : ($printBindingState || $printModuleName ? 4 : 0);
foreach ($bindingStates as $bindingState) {
$bindingStatePrinted = !$printBindingState;
foreach ($moduleNames as $moduleName) {
$expr = Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName)))->andMethod('getState', Expr::same($bindingState));
$descriptors = $this->discoveryManager->findBindingDescriptors($expr);
if (empty($descriptors)) {
continue;
}
$printAdvice = false;
if (!$bindingStatePrinted) {
$this->printBindingStateHeader($io, $bindingState);
$bindingStatePrinted = true;
}
if ($printModuleName) {
$prefix = $printBindingState ? ' ' : '';
$io->writeLine(sprintf('%sModule: %s', $prefix, $moduleName));
$io->writeLine('');
}
$this->printBindingTable($io, $descriptors, $indentation, BindingState::ENABLED === $bindingState);
if ($printHeaders) {
$io->writeLine('');
}
}
}
if ($printAdvice) {
$io->writeLine('No bindings found. Use "puli bind <artifact> <type>" to bind an artifact to a type.');
}
return 0;
}
示例7: testAppendDefaultQuerySuffixForEndsWith
public function testAppendDefaultQuerySuffixForEndsWith()
{
$expr1 = Expr::endsWith('.css', AssetMapping::GLOB);
$expr2 = Expr::same(BindingState::ENABLED, BindingDescriptor::STATE)->andSame(DiscoveryUrlGenerator::BINDING_TYPE, BindingDescriptor::TYPE_NAME)->andEndsWith('{,/**/*}', BindingDescriptor::QUERY)->andEndsWith('.css{,/**/*}', BindingDescriptor::QUERY);
$this->assertEquals($expr2, $this->builder->buildExpression($expr1));
}
示例8: webPath
private function webPath($path)
{
return $this->defaultExpr()->andKey(BindingDescriptor::PARAMETER_VALUES, Expr::key(DiscoveryUrlGenerator::PATH_PARAMETER, Expr::same($path)));
}
示例9: testMatch
public function testMatch()
{
$descriptor = new InstallerDescriptor('symlink', self::SYMLINK_CLASS, 'The description');
$this->assertFalse($descriptor->match(Expr::same('copy', InstallerDescriptor::NAME)));
$this->assertTrue($descriptor->match(Expr::same('symlink', InstallerDescriptor::NAME)));
$this->assertFalse($descriptor->match(Expr::same('FooBar', InstallerDescriptor::CLASS_NAME)));
$this->assertTrue($descriptor->match(Expr::same(self::SYMLINK_CLASS, InstallerDescriptor::CLASS_NAME)));
$this->assertFalse($descriptor->match(Expr::same('Foo description', InstallerDescriptor::DESCRIPTION)));
$this->assertTrue($descriptor->match(Expr::same('The description', InstallerDescriptor::DESCRIPTION)));
}
示例10: testInstallWithServer
public function testInstallWithServer()
{
$mapping1 = new AssetMapping('/app/public', 'localhost', '/');
$mapping2 = new AssetMapping('/acme/blog/public/{css,js}', 'localhost', '/blog');
$symlinkInstaller = $this->getMock('Puli\\Manager\\Api\\Installer\\ResourceInstaller');
$symlinkInstallerDescriptor = new InstallerDescriptor('symlink', get_class($symlinkInstaller));
$localServer = new Server('localhost', 'symlink', 'public_html');
$resource1 = new GenericResource('/app/public');
$resource2 = new GenericResource('/acme/blog/public/css');
$resource3 = new GenericResource('/acme/blog/public/js');
$params1 = new InstallationParams($symlinkInstaller, $symlinkInstallerDescriptor, new ArrayResourceCollection(array($resource1)), $mapping1, $localServer, __DIR__);
$params2 = new InstallationParams($symlinkInstaller, $symlinkInstallerDescriptor, new ArrayResourceCollection(array($resource2, $resource3)), $mapping2, $localServer, __DIR__);
$this->assetManager->expects($this->once())->method('findAssetMappings')->with(Expr::same('localhost', AssetMapping::SERVER_NAME))->willReturn(array($mapping1, $mapping2));
$this->installationManager->expects($this->at(0))->method('prepareInstallation')->with($mapping1)->willReturn($params1);
$this->installationManager->expects($this->at(1))->method('prepareInstallation')->with($mapping2)->willReturn($params2);
$this->installationManager->expects($this->at(2))->method('installResource')->with($resource1, $params1);
$this->installationManager->expects($this->at(3))->method('installResource')->with($resource2, $params2);
$this->installationManager->expects($this->at(4))->method('installResource')->with($resource3, $params2);
$args = self::$installCommand->parseArgs(new StringArgs('localhost'));
$expected = <<<EOF
Installing /app/public into public_html via symlink...
Installing /acme/blog/public/css into public_html/blog/css via symlink...
Installing /acme/blog/public/js into public_html/blog/js via symlink...
EOF;
$this->assertSame(0, $this->handler->handleInstall($args, $this->io));
$this->assertSame($expected, $this->io->fetchOutput());
$this->assertEmpty($this->io->fetchErrors());
}
示例11: testHasRootInstallerDescriptors
public function testHasRootInstallerDescriptors()
{
$this->populateRootManager();
$this->assertTrue($this->manager->hasRootInstallerDescriptors());
$this->assertTrue($this->manager->hasRootInstallerDescriptors(Expr::same('symlink', InstallerDescriptor::NAME)));
$this->assertFalse($this->manager->hasRootInstallerDescriptors(Expr::same('rsync', InstallerDescriptor::NAME)));
$this->assertFalse($this->manager->hasRootInstallerDescriptors(Expr::same('foobar', InstallerDescriptor::NAME)));
}
示例12: testHasConfigKeysWithFallback
public function testHasConfigKeysWithFallback()
{
$this->assertFalse($this->manager->hasConfigKeys(null, true));
$this->baseConfig->set(Config::PULI_DIR, 'fallback');
$this->assertTrue($this->manager->hasConfigKeys(null, true));
$this->assertFalse($this->manager->hasConfigKeys(Expr::same(Config::FACTORY_IN_CLASS), true));
$this->configFile->getConfig()->set(Config::FACTORY_IN_CLASS, 'MyFactory');
$this->assertTrue($this->manager->hasConfigKeys(null, true));
$this->assertTrue($this->manager->hasConfigKeys(Expr::same(Config::FACTORY_IN_CLASS), true));
$this->configFile->getConfig()->set(Config::PULI_DIR, 'my-puli-dir');
$this->assertTrue($this->manager->hasConfigKeys(null, true));
$this->assertTrue($this->manager->hasConfigKeys(Expr::same(Config::FACTORY_IN_CLASS), true));
}
示例13: hasRootPathMappings
/**
* {@inheritdoc}
*/
public function hasRootPathMappings(Expression $expr = null)
{
$expr2 = Expr::same($this->rootPackage->getName(), PathMapping::CONTAINING_PACKAGE);
if ($expr) {
$expr2 = $expr2->andX($expr);
}
return $this->hasPathMappings($expr2);
}
示例14: hasAssetMapping
/**
* {@inheritdoc}
*/
public function hasAssetMapping(Uuid $uuid)
{
$expr = Expr::method('getUuid', Expr::method('toString', Expr::same($uuid->toString())))->andX($this->exprBuilder->buildExpression());
return $this->discoveryManager->hasBindingDescriptors($expr);
}
示例15: handleClean
/**
* Handles the "package --clean" command.
*
* @param Args $args The console arguments.
* @param IO $io The I/O.
*
* @return int The status code.
*/
public function handleClean(Args $args, IO $io)
{
$expr = Expr::same(PackageState::NOT_FOUND, Package::STATE);
foreach ($this->packageManager->findPackages($expr) as $package) {
$io->writeLine('Removing ' . $package->getName());
$this->packageManager->removePackage($package->getName());
}
return 0;
}