Scalr\Api\Service\User\V1beta0\Controller\FarmRoles::getFarmRole PHP Méthode

getFarmRole() public méthode

Gets specified Farm Role taking into account both scope and authentication token
public getFarmRole ( string $farmRoleId, integer $farmId = null, boolean $modify = false ) : FarmRole
$farmRoleId string Numeric identifier of the Farm role
$farmId integer optional Identifier of the Farm containing Farm role
$modify boolean optional Flag checking write permissions
Résultat Scalr\Model\Entity\FarmRole Returns the Script Entity on success
    public function getFarmRole($farmRoleId, $farmId = null, $modify = false)
    {
        /* @var $role FarmRole */
        $role = FarmRole::findPk($farmRoleId);
        if (!$role) {
            throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Farm Role either does not exist or is not owned by your environment.");
        }
        if (isset($farmId)) {
            if ($role->farmId != $farmId) {
                throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid identifier of the farm");
            }
        } else {
            $farmId = $role->farmId;
        }
        $this->getFarm($farmId, $modify);
        if (!$this->hasPermissions($role, $modify)) {
            //Checks entity level write access permissions
            throw new ApiErrorException(403, ErrorMessage::ERR_PERMISSION_VIOLATION, "Insufficient permissions");
        }
        return $role;
    }

Usage Example

Exemple #1
0
 /**
  * Gets farm role from database using User's Environment
  *
  * @param   int     $farmRoleId          The identifier of the Farm Role
  * @param   bool    $modify     optional Flag checking write permissions
  *
  * @return  FarmRole|null
  *
  * @throws  ApiErrorException
  */
 public function getFarmRole($farmRoleId, $modify = false)
 {
     if (empty($this->farmRoleController)) {
         $this->farmRoleController = $this->getContainer()->api->controller(static::$farmRoleControllerClass);
     }
     return $this->farmRoleController->getFarmRole($farmRoleId, null, $modify);
 }
All Usage Examples Of Scalr\Api\Service\User\V1beta0\Controller\FarmRoles::getFarmRole