示例#1
0
文件: User.php 项目: hpdev225/myguard
 public function removeRole($role)
 {
     $role = $this->roles->filter(function (Role $r) use($role) {
         if ($role instanceof Role) {
             return $r->getRole() === $role->getRole();
         } else {
             return $r->getRole() === strtoupper($role);
         }
     })->first();
     if ($role) {
         $this->roles->removeElement($role);
     }
     return $this;
 }
示例#2
0
 public function test_filter_map()
 {
     $arc = new ArrayCollection(array('aap', 'aap', 'noot', 'mies'));
     $filtered = $arc->filter(function ($i) {
         return $i != 'aap';
     });
     $this->assertInstanceOf('\\SAML2\\Utilities\\ArrayCollection', $filtered);
     $this->assertEquals($filtered->get(0), null);
     $this->assertEquals($filtered->get(1), null);
     $this->assertEquals($filtered->get(2), 'noot');
     $this->assertEquals($filtered->get(3), 'mies');
     $mapped = $arc->map(function ($i) {
         return ucfirst($i);
     });
     $this->assertInstanceOf('\\SAML2\\Utilities\\ArrayCollection', $mapped);
     $this->assertEquals($mapped->get(0), 'Aap');
     $this->assertEquals($mapped->get(1), 'Aap');
     $this->assertEquals($mapped->get(2), 'Noot');
     $this->assertEquals($mapped->get(3), 'Mies');
     // ensure original is not changed
     $this->assertEquals($arc->get(0), 'aap');
     $this->assertEquals($arc->get(1), 'aap');
     $this->assertEquals($arc->get(2), 'noot');
     $this->assertEquals($arc->get(3), 'mies');
 }
示例#3
0
 /** {@inheritDoc} */
 public function filter(Closure $p)
 {
     $this->initialize();
     return $this->collection->filter($p);
 }