protected function castDimension($value, $dimension)
    {
        // Check type
        if (!is_numeric($value)) {
            throw new InvalidArgumentException("{$dimension} must be a numeric value");
        }

        // Cast to integer
        $value = intval($value);

        // Check empty
        if (empty($value)) {
            throw new InvalidArgumentException("{$dimension} is required");
        }
        // Check flag
        if ($value < 1) {
            throw new InvalidArgumentException("{$dimension} must be positive");
        }
        return $value;
    }