withFlag() публичный Метод

Creates a new instance of the bag with the given flag. If a flag with the same identifier already exists, the existing value will be replaced.
public withFlag ( Nelmio\Alice\Definition\FlagInterface $flag ) : self
$flag Nelmio\Alice\Definition\FlagInterface
Результат self
Пример #1
0
 public function testAddingAFlagCreatesANewModifiedInstance()
 {
     $flag = new MutableFlag('flag0', new \stdClass());
     $bag1 = new FlagBag('user0');
     $bag2 = $bag1->withFlag($flag);
     $this->assertInstanceOf(FlagBag::class, $bag1);
     $this->assertNotSame($bag1, $bag2);
     $this->assertCount(0, $bag1);
     $this->assertCount(1, $bag2);
     // Mutate injected value
     $flag->setStringValue('flag1');
     $flag->getObject()->injected = true;
     // Mutate return value
     foreach ($bag1 as $flag) {
         /** @var MutableFlag $flag */
         $flag->setStringValue('flag2');
         $flag->getObject()->foo = 'bar';
     }
     $this->assertEquals((new FlagBag('user0'))->withFlag(new MutableFlag('flag0', new \stdClass())), $bag2);
 }