public static function createFromObject($permission)
    {
        // Make sure the id is typecast to an integer.
        $id = ! is_null($permission->resource_id) ? (int) $permission->resource_id : null;

        if ($permission->type === Privilege::TYPE) {
            return new Privilege(
                $permission->action,
                new SimpleResource($permission->resource_type, $id)
            );
        } elseif ($permission->type === Restriction::TYPE) {
            return new Restriction(
                $permission->action,
                new SimpleResource($permission->resource_type, $id)
            );
        } else {
            throw new InvalidPermissionType("The permission type you provided \"{$permission->type}\" is incorrect.");
        }
    }