Exemplo n.º 1
0
 /**
  * Applies all plugins to given $intention based on their priority.
  *
  * @param IntentionInterface $intention
  */
 public function apply(IntentionInterface $intention)
 {
     $plugins = $this->pluginsCollection->getPlugins();
     foreach ($plugins as $priorityPlugins) {
         foreach ($priorityPlugins as $plugin) {
             /** @var PluginInterface $plugin */
             $plugin->apply($intention);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Tests that plugins are sorted correctly then trying to get them via Collection::getPlugins().
  */
 public function testPluginPrioritySorting()
 {
     $collection = new Collection();
     $plugin = $this->createPluginMock();
     $collection->addPlugin($plugin, 0);
     $collection->addPlugin($plugin, 0);
     $collection->addPlugin($plugin, -2);
     $collection->addPlugin($plugin, -5);
     $collection->addPlugin($plugin, 5);
     $collection->addPlugin($plugin, 100);
     $collection->addPlugin($plugin, 100);
     $plugins = $collection->getPlugins();
     $this->assertEquals(array_keys($plugins), [-5, -2, 0, 5, 100]);
     $this->assertCount(1, $plugins[-5]);
     $this->assertCount(1, $plugins[-2]);
     $this->assertCount(2, $plugins[0]);
     $this->assertCount(1, $plugins[5]);
     $this->assertCount(2, $plugins[100]);
 }