FOS\UserBundle\Model\GroupManagerInterface::findGroupByName PHP Method

findGroupByName() public method

Finds a group by name
public findGroupByName ( string $name ) : FOS\UserBundle\Model\GroupInterface
$name string
return FOS\UserBundle\Model\GroupInterface
    function findGroupByName($name);

Usage Example

 /**
  * Returns a specific principal, specified by it's path.
  * The returned structure should be the exact same as from
  * getPrincipalsByPrefix.
  *
  * @param string $path
  * @param bool   $getObject
  *
  * @return array|GroupInterface|UserInterface|void
  *
  * @throws Exception
  */
 public function getPrincipalByPath($path, $getObject = false)
 {
     $name = str_replace('principals/', '', $path);
     // get username from path-string, if string contains additional slashes (e.g. admin/calendar-proxy-read)
     if (!(strpos($name, '/') === false)) {
         $name = substr($name, 0, strpos($name, '/'));
     }
     $user = $this->user_manager->findUserByUsername($name);
     if ($user === null) {
         if (!$this->group_manager) {
             return;
         }
         // search in group-manager
         $group = $this->group_manager->findGroupByName($name);
         if ($group === null) {
             return;
         }
         if ($getObject === true) {
             return $group;
         }
         return $this->getPrincipalArray($group, true);
     }
     if ($getObject === true) {
         return $user;
     }
     return $this->getPrincipalArray($user, true);
 }