static function validate ($type, $v)
  {
    if (is_null ($v) || $v === '')
      return true;

    switch ($type) {

      case type::binding:
        return is_string ($v);

      case type::any:
      case type::bool: // Any value can be typecast to boolean.
        return true;

      case type::data:
        return is_array ($v) || is_object ($v)
               || $v instanceof \Traversable
               || (is_string ($v) && strpos ($v, '{') !== false);

      case type::id:
        return !!preg_match ('#^[\w\-]+$#', $v);

      case type::content:
        return $v instanceof Metadata || is_string ($v); // Note: content props can be specified in attribute syntax.

      case type::metadata:
        return $v instanceof Metadata;

      case type::collection:
        return is_array ($v);

      case type::number:
        return is_numeric ($v);

      case type::string:
        return is_scalar ($v) || (is_object ($v) && method_exists ($v, '__toString'));
    }
    return false;
  }