/** * {@inheritdoc} */ public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array()) { $options = array_replace(self::$defaultOptions, $options); Assert::string($options['host'], 'The host must be a string. Got: %s'); Assert::integer($options['port'], 'The port must be an integer. Got: %s'); $escHost = var_export($options['host'], true); $escPort = var_export($options['port'], true); $targetMethod->getClass()->addImports(array(new Import('Redis'), new Import('Webmozart\\KeyValueStore\\PhpRedisStore'))); $targetMethod->addBody(<<<EOF \$client = new Redis(); \$client->connect({$escHost}, {$escPort}); \${$varName} = new PhpRedisStore(\$client); EOF ); }
/** * {@inheritdoc} */ public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array()) { $options = array_replace(self::$defaultOptions, $options); Assert::stringNotEmpty($options['host'], 'The "host" option must be a non-empty string. Got: %s'); Assert::integer($options['port'], 'The "port" option must be an integer. Got: %s'); $escHost = var_export($options['host'], true); $escPort = var_export($options['port'], true); $targetMethod->getClass()->addImports(array(new Import('Predis\\Client'), new Import('Webmozart\\KeyValueStore\\PredisStore'))); $targetMethod->addBody(<<<EOF \$client = new Client(array( 'host' => {$escHost}, 'port' => {$escPort}, )); \${$varName} = new PredisStore(\$client); EOF ); }
/** * {@inheritdoc} */ public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array()) { Assert::keyExists($options, 'bucket', 'The "bucket" option is missing.'); $options = array_replace(self::$defaultOptions, $options); Assert::string($options['bucket'], 'The bucket must be a string. Got: %s'); Assert::string($options['host'], 'The host must be a string. Got: %s'); Assert::integer($options['port'], 'The port must be an integer. Got: %s'); $escBucket = var_export($options['bucket'], true); $escHost = var_export($options['host'], true); $escPort = var_export($options['port'], true); $targetMethod->getClass()->addImports(array(new Import('Basho\\Riak\\Riak'), new Import('Webmozart\\KeyValueStore\\RiakStore'))); $targetMethod->addBody(<<<EOF \$client = new Riak({$escHost}, {$escPort}); \${$varName} = new RiakStore({$escBucket}, \$client); EOF ); }
/** * {@inheritdoc} */ public function addRootBindingType(BindingTypeDescriptor $typeDescriptor, $flags = 0) { Assert::integer($flags, 'The argument $flags must be a boolean.'); $this->assertPackagesLoaded(); $this->emitWarningForDuplicateTypes(); if (!($flags & self::OVERRIDE) && $this->typeDescriptors->contains($typeDescriptor->getName())) { throw DuplicateTypeException::forTypeName($typeDescriptor->getName()); } $tx = new Transaction(); try { $typeName = $typeDescriptor->getName(); $syncBindingOps = array(); foreach ($this->getUuidsByTypeName($typeName) as $uuid) { $syncBindingOp = $this->syncBindingUuid($uuid); $syncBindingOp->takeSnapshot(); $syncBindingOps[] = $syncBindingOp; } $syncOp = $this->syncTypeName($typeName); $syncOp->takeSnapshot(); $tx->execute($this->loadTypeDescriptor($typeDescriptor, $this->rootPackage)); $tx->execute($this->addTypeDescriptorToPackageFile($typeDescriptor)); $tx->execute($syncOp); foreach ($syncBindingOps as $syncBindingOp) { $tx->execute($syncBindingOp); } $this->saveRootPackageFile(); $tx->commit(); } catch (Exception $e) { $tx->rollback(); throw $e; } }
/** * {@inheritdoc} */ public function addRootPathMapping(PathMapping $mapping, $flags = 0) { Assert::integer($flags, 'The argument $flags must be a boolean.'); $this->assertMappingsLoaded(); if (!($flags & self::OVERRIDE) && $this->rootPackageFile->hasPathMapping($mapping->getRepositoryPath())) { throw DuplicatePathMappingException::forRepositoryPath($mapping->getRepositoryPath(), $this->rootPackage->getName()); } $tx = new Transaction(); try { $syncOp = $this->syncRepositoryPath($mapping->getRepositoryPath()); $syncOp->takeSnapshot(); $tx->execute($this->loadPathMapping($mapping, $this->rootPackage)); if (!($flags & self::IGNORE_FILE_NOT_FOUND)) { $this->assertNoLoadErrors($mapping); } $tx->execute($this->updateConflicts($mapping->listRepositoryPaths())); $tx->execute($this->overrideConflictingPackages($mapping)); $tx->execute($this->updateConflicts()); $tx->execute($this->addPathMappingToPackageFile($mapping)); $tx->execute($syncOp); $this->saveRootPackageFile(); $tx->commit(); } catch (Exception $e) { $tx->rollback(); throw $e; } }