public static function ensureNullOrArrayOfType($name, array &$array = null, $type)
    {
        if (is_null($array))
        {
            return;
        }

        foreach ($array as $element)
        {
            if (!($element instanceof $type))
            {
                throw new \InvalidArgumentException("'$name' must be null or an array of $type.");
            }
        }
    }