Webiny\Component\Rest\Response\RequestBag::getClassData PHP Method

getClassData() public method

Get the class data array.
public getClassData ( ) : array
return array
    public function getClassData()
    {
        return $this->classData;
    }

Usage Example

Example #1
0
 /**
  * Checks if current user has access to the current rest request.
  *
  * @param RequestBag $requestBag
  *
  * @return bool
  * @throws \Webiny\Component\Rest\RestException
  */
 public static function hasAccess(RequestBag $requestBag)
 {
     // first we check if method requires a special access level
     if (!$requestBag->getApiConfig()->get('Security', false)) {
         return true;
         // no special access level required
     }
     // get the required role
     if (isset($requestBag->getMethodData()['role'])) {
         $role = $requestBag->getMethodData()['role'];
     } else {
         $role = $requestBag->getApiConfig()->get('Security.Role', 'ROLE_ANONYMOUS');
     }
     // check if user has the access level required
     if ($requestBag->getClassData()['accessInterface']) {
         return $requestBag->getClassInstance()->hasAccess($role);
     } else {
         // get firewall name
         $firewallName = $requestBag->getApiConfig()->get('Security.Firewall', false);
         if (!$firewallName) {
             throw new RestException('When using Rest access rule, you must specify a Firewall in your configuration.
             Alternatively you can implement the AccessInterface and do the check on your own.');
         }
         return self::security()->firewall($firewallName)->getUser()->hasRole($role);
     }
 }
All Usage Examples Of Webiny\Component\Rest\Response\RequestBag::getClassData