Пример #1
0
 /**
  * Gets a feature toggle
  * @param $name - The name of the feature
  * @return FeatureInterface
  */
 public function get($name)
 {
     if (!$this->has($name)) {
         throw new FeatureNotFoundException(sprintf('The feature %s was not found', $name));
     }
     return $this->features->get($name);
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function addListener($eventName, callable $callable)
 {
     if (!$this->listeners->containsKey($eventName)) {
         $this->listeners->add(new Pair($eventName, new Vector()));
     }
     $this->listeners->get($eventName)->add($callable);
 }
 /**
  * @param MapInterface $condition
  *
  * @return OperatorCondition
  */
 public function deserialize(MapInterface $condition)
 {
     $name = $condition->get('name');
     if ($name !== 'operator-condition') {
         throw new \RuntimeException(sprintf('Unable to deserialize operator with name "%s".', $name));
     }
     $operator = $this->operatorSerializer->deserialize($condition->get('operator'));
     return new OperatorCondition($condition->get('key'), $operator);
 }
Пример #4
0
 public function countEventsFor(StreamName $streamName, AggregateIdInterface $aggregateId)
 {
     $name = (string) $streamName;
     /** @var MapInterface $events */
     $events = $this->events->get($name);
     /** @var MapInterface $stream */
     $stream = $events->get((string) $aggregateId);
     return $stream->count();
 }
Пример #5
0
 /**
  * @test
  */
 public function is_should_concatenate_vectors()
 {
     if ($this->coll instanceof MapInterface) {
         $this->coll->add(new Pair(0, 1))->add(new Pair(1, 2))->add(new Pair(3, 4));
     } else {
         $this->coll->add(1)->add(2)->add(4);
     }
     $coll2 = new Vector([3]);
     $concatenated = $this->coll->concat($coll2);
     $this->assertEquals([1, 2, 4, 3], $concatenated->toArray());
 }
Пример #6
0
 /**
  * Configure the producer
  *
  * @param              $topic
  * @param VectorInterface $channels
  * @param MapInterface $configs
  */
 protected function configureChannels($topic, VectorInterface $channels, MapInterface $configs)
 {
     $channels->each(function (AMQPChannel $channel) use($topic, $configs) {
         $channel->queue_declare($topic, $configs->get('passive'), $configs->get('durable'), $configs->get('exclusive'), $configs->get('auto_delete'), $configs->get('nowait'), $configs->get('arguments'), $configs->get('ticket'));
     });
     $this->configured = true;
 }
 /**
  * @param MapInterface $data
  *
  * @return FeatureInterface
  */
 public function deserialize(MapInterface $data)
 {
     /** @var MapInterface $conditions */
     $conditions = $data->get('conditions');
     if (!$conditions instanceof MapInterface) {
         throw new \RuntimeException('Key "conditions" should be an MapInterface.');
     }
     $toggle = new Feature($data->get('name'), $this->deserializeConditions($conditions), $data->containsKey('strategy') ? $this->deserializeStrategy($data->get('strategy')) : ToggleStrategy::AFFIRMATIVE);
     if ($data->containsKey('status')) {
         $this->deserializeStatus($toggle, $data->get('status'));
     }
     return $toggle;
 }
Пример #8
0
 public function has(AggregateIdInterface $id, $version)
 {
     return $this->snapshots->containsKey((string) $id);
 }
 /**
  * @param MapInterface $operator
  *
  * @return OperatorInterface
  */
 public function deserialize(MapInterface $operator)
 {
     switch ($operator->get('name')) {
         case 'equals-to':
             return new EqualsTo($operator->get('value'));
         case 'greater-than':
             return new GreaterThan($operator->get('value'));
         case 'greater-than-equal':
             return new GreaterThanEqual($operator->get('value'));
         case 'in-set':
             return new InSet($operator->get('values'));
         case 'less-than':
             return new LessThan($operator->get('value'));
         case 'less-than-equal':
             return new LessThanEqual($operator->get('value'));
         case 'percentage':
             return new Percentage($operator->get('percentage'), $operator->get('shift'));
         case 'matches-regex':
             return new MatchesRegex($operator->get('value'));
         default:
             throw new \RuntimeException(sprintf('Unknown operator with name "%s".', $operator->get('name')));
     }
 }
 private function configureSnapshotStrategy(MapInterface $config)
 {
     $adapterName = $config->get('name');
     $arguments = $config->get('arguments') ? $config->get('arguments') : [];
     return new $adapterName(...$arguments);
 }
Пример #11
0
 public function serializeCollection(VisitorInterface $visitor, MapInterface $collection, array $type, Context $context)
 {
     // We change the base type, and pass through possible parameters.
     $type['name'] = 'array';
     return $visitor->visitArray($collection->toArray(), $type, $context);
 }