public function testRole() { $role = new Role(); $this->assertEmpty($role->getId()); $this->assertEmpty($role->getRole()); $role->setRole('foo'); $this->assertStringStartsWith('ROLE_FOO', $role->getRole()); $this->assertEquals(Role::PREFIX_ROLE, $role->getPrefix()); }
/** * @param Role $role * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData(Role $role, $field, $data) { switch ($field) { case 'role': $role->setRole($data); break; case 'label': $role->setLabel($data); break; } }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $roleTest1 = new Role(); $roleTest1->setLabel('Role 1'); $roleTest1->setRole('ROLE_TEST_1'); $manager->persist($roleTest1); $this->setReference('ROLE_TEST_1', $roleTest1); $roleTest2 = new Role(); $roleTest2->setLabel('Role 2'); $roleTest2->setRole('ROLE_TEST_2'); $manager->persist($roleTest2); $this->setReference('ROLE_TEST_2', $roleTest2); $manager->flush(); }
/** * Save role * * @param Role $role * @return bool */ public function process(Role $role) { if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { $this->form->submit($this->request); if ($this->form->isValid()) { $appendUsers = $this->form->get('appendUsers')->getData(); $removeUsers = $this->form->get('removeUsers')->getData(); $role->setRole(strtoupper(trim(preg_replace('/[^\\w\\-]/i', '_', $role->getLabel())))); $this->onSuccess($role, $appendUsers, $removeUsers); $this->processPrivileges($role); return true; } } else { $this->setRolePrivileges($role); } return false; }
/** * {@inheritDoc} */ public function setRole($role) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setRole', array($role)); return parent::setRole($role); }