Inheritance: extends collections\AbstractCollectionArray, implements collections\MapInterface, implements ArrayAccess, use trait Collections\Traits\StrictKeyedIterableTrait, use trait Collections\Traits\GuardTrait
コード例 #1
0
 /**
  * Busca por uma estratégia a partir do nome definido para a mesma.
  * @param $name
  * @return mixed
  * @throws StrategyNotFoundException
  */
 public function getStrategy($name)
 {
     if (!$this->dictionary->containsKey($name)) {
         throw new StrategyNotFoundException();
     }
     return $this->dictionary->get($name);
 }
コード例 #2
0
 /**
  * @param array $data
  * @return MapInterface
  */
 public function deserialize(array $data)
 {
     $data = new Dictionary($data);
     $collection = new Dictionary();
     $serializer = new ToggleSerializer(new OperatorConditionSerializer(new OperatorSerializer()));
     foreach ($data as $name => $serializedToggle) {
         $toggle = $serializer->deserialize($serializedToggle);
         $collection->set($serializedToggle->get('name'), $toggle);
     }
     return $collection;
 }
コード例 #3
0
 public function testConcat()
 {
     $this->coll->add(1)->add(2)->add(4);
     $coll2 = new ArrayList([3]);
     $this->coll->concat($coll2);
     $this->assertEquals([1, 2, 4, 3], $this->coll->toArray());
     $coll3 = new Dictionary(['key1' => 'value1', 'key2' => 'wrongValue']);
     $coll4 = new Dictionary(['key2' => 'value2']);
     $coll3->concat($coll4);
     $this->assertEquals(['key1' => 'value1', 'key2' => 'value2'], $coll3->toArray());
 }
コード例 #4
0
ファイル: Consumer.php プロジェクト: hellofresh/reagieren
 /**
  * {@inheritdoc}
  */
 public function consume($topic, callable $callback, $configs = [])
 {
     if (!$configs instanceof MapInterface) {
         $configs = new Dictionary($configs);
     }
     if (!$this->configured || $configs->get('force_config')) {
         $configs = $this->setConfig($topic, $configs);
     }
     while (true) {
         $this->fetch($topic, $callback);
     }
 }
コード例 #5
0
ファイル: Producer.php プロジェクト: hellofresh/reagieren
 /**
  * {@inheritdoc}
  */
 public function produce($payload, $configs = [])
 {
     $configs = new Dictionary($configs);
     $this->producers->each(function (ProducerInterface $producer) use($payload, $configs) {
         /** @var MapInterface $brokerConfigs */
         $brokerConfigs = $configs->get($producer->getName());
         try {
             $topic = $brokerConfigs->get('topic');
         } catch (\OutOfBoundsException $e) {
             throw new \InvalidArgumentException('You should configure the topic/exchange that you want to produce to');
         }
         $producer->produce($topic, $payload, $brokerConfigs);
     });
 }
コード例 #6
0
ファイル: Producer.php プロジェクト: hellofresh/reagieren
 /**
  * {@inheritdoc}
  */
 public function produce($topic, $payload, $configs = [])
 {
     if (!$configs instanceof MapInterface) {
         $configs = new Dictionary($configs);
     }
     if (!$this->configured || $configs->get('force_config')) {
         $configs = $this->setConfig($topic, $configs);
     }
     $partition = $this->choosePartition($topic, isset($configs['partition_strategy']) ? $configs['partition_strategy'] : self::PARTITION_STRATEGY_RANDOM);
     if (is_string($payload)) {
         $payload = [$payload];
     }
     foreach ($payload as $message) {
         $this->connection->setMessages($topic, $partition, $message);
     }
     return $this->connection->send();
 }
コード例 #7
0
ファイル: Dictionary.php プロジェクト: vladimino/collections
 /**
  * {@inheritdoc}
  */
 public function addAll($items)
 {
     if (!is_array($items) && !$items instanceof Traversable) {
         throw new \InvalidArgumentException('The items must be an array or Traversable');
     }
     foreach ($items as $key => $value) {
         if (is_array($value)) {
             $value = Dictionary::fromArray($value);
         }
         $this->add($key, $value);
     }
 }
コード例 #8
0
 /**
  * {@inheritDoc}
  * @return $this
  */
 public function indexBy($callback)
 {
     $callback = $this->propertyExtractor($callback);
     $group = new Dictionary();
     foreach ($this as $value) {
         $key = $callback($value);
         $group->set($key, $value);
     }
     return $group;
 }
コード例 #9
0
ファイル: Request.php プロジェクト: italolelis/datatables
 /**
  * Hydrate the current object from a $_GET, $_POST, or $_REQUEST array
  * @return $this
  */
 public static function createFromGlobals()
 {
     $request = new static();
     $data = new Dictionary($_GET);
     $data->addAll($_POST);
     return $request->createFromCollection($data);
 }
コード例 #10
0
 public function testToArray()
 {
     $data = ['key1' => 'value1', 'key2' => 'value2', 'key3' => ['key3.1' => 'value3.1']];
     $this->coll->addAll($data);
     $this->assertEquals($data, $this->coll->toArray());
 }
コード例 #11
0
ファイル: Wunderlist.php プロジェクト: italolelis/wunderlist
 /**
  * Unregister a service
  * @param string $name The service name
  * @return $this
  */
 public function unregisterService($name)
 {
     $this->services->remove($name);
     return $this;
 }
コード例 #12
0
ファイル: RxTest.php プロジェクト: robmachado/collections
 /**
  * Tests indexBy with a deep property
  *
  * @return void
  */
 public function testIndexByDeep()
 {
     $items = [['id' => 1, 'name' => 'foo', 'thing' => ['parent_id' => 10]], ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]], ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]]];
     $collection = new Dictionary($items);
     $grouped = $collection->indexBy('thing.parent_id');
     $expected = [10 => ['id' => 3, 'name' => 'baz', 'thing' => ['parent_id' => 10]], 11 => ['id' => 2, 'name' => 'bar', 'thing' => ['parent_id' => 11]]];
     $this->assertEquals($expected, $grouped->toArray());
 }