Scalr\Api\Service\User\V1beta0\Controller\Farms::getFarm PHP Метод

getFarm() публичный Метод

Gets specified Farm taking into account both scope and authentication token
public getFarm ( string $farmId, boolean | string $modify = false ) : Farm
$farmId string Numeric identifier of the Farm
$modify boolean | string optional Permission identifier
Результат Scalr\Model\Entity\Farm Returns the Farm Entity on success
    public function getFarm($farmId, $modify = false)
    {
        /* @var $farm Farm */
        $farm = Farm::findPk($farmId);
        if (!$farm) {
            throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Farm either does not exist or is not owned by your environment.");
        }
        if (!$this->hasPermissions($farm, $modify)) {
            //Checks entity level write access permissions
            throw new ApiErrorException(403, ErrorMessage::ERR_PERMISSION_VIOLATION, "Insufficient permissions");
        }
        return $farm;
    }

Usage Example

Пример #1
0
 /**
  * Gets farm from database using User's Environment
  *
  * @param   int     $farmId          The identifier of the Role
  * @param   bool    $modify optional Modification flag
  * @return  Farm|null Returns specified Farm
  * @throws  ApiErrorException
  */
 public function getFarm($farmId, $modify = false)
 {
     if (empty($this->farmController)) {
         $this->farmController = $this->getContainer()->api->controller(static::$farmControllerClass);
     }
     return $this->farmController->getFarm($farmId, $modify ? Acl::PERM_FARMS_MANAGE : null);
 }
All Usage Examples Of Scalr\Api\Service\User\V1beta0\Controller\Farms::getFarm