コード例 #1
0
 /**
  * Tests getting a key and creating a new namespace for it.
  */
 public function testGetKeyCreateNamespace()
 {
     /* Setup method calls. */
     $method = $this->getMethodUsingReflection($this->baseProvider, 'getKey');
     $this->baseProvider->expects($this->once())->method('doGet')->with('my_ns')->will($this->returnValue(new CacheResponse(false, false, false, 'Some error')));
     $this->baseProvider->expects($this->once())->method('doSet')->with('my_ns', $this->matchesRegularExpression('/^[1-9][0-9]*$/'), 30)->will($this->returnValue(true));
     /* Call method. */
     $options = array(ProviderServiceInterface::CMD_OPT_NAMESPACE => 'my_ns', ProviderServiceInterface::CMD_OPT_NAMESPACE_EXPIRATION => 30);
     $this->assertRegExp('/^prefix:my_ns:[1-9][0-9]*:my_key$/', $method->invoke($this->baseProvider, 'my_key', $options));
 }
コード例 #2
0
 /**
  * Constructor.
  *
  * @param ClientInterface $client  Predis client instance.
  * @param array           $options Provider options.
  */
 public function __construct(ClientInterface $client, array $options = array())
 {
     parent::__construct();
     $this->client = $client;
     /* Set the provider options. */
     $this->setOptions($options);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function configureProviderOptions(OptionsResolver $optionsResolver)
 {
     /* Parent options still apply. */
     parent::configureProviderOptions($optionsResolver);
     /* Define default values. */
     $optionsResolver->setDefault(ProviderServiceInterface::PROVIDER_OPT_GC_PROBABILITY, 1);
     $optionsResolver->setDefault(ProviderServiceInterface::PROVIDER_OPT_GC_DIVISOR, 100);
     /* Add allowed types. */
     $optionsResolver->setAllowedTypes(ProviderServiceInterface::PROVIDER_OPT_GC_PROBABILITY, 'int');
     $optionsResolver->setAllowedTypes(ProviderServiceInterface::PROVIDER_OPT_GC_DIVISOR, 'int');
     /* Set allowed values. */
     $optionsResolver->setAllowedValues(ProviderServiceInterface::PROVIDER_OPT_GC_PROBABILITY, function ($value) {
         return 0 <= $value;
     });
     $optionsResolver->setAllowedValues(ProviderServiceInterface::PROVIDER_OPT_GC_DIVISOR, function ($value) {
         return 1 <= $value;
     });
 }