GetWrapperInternal() static private method

Search the lists of registered StreamWrappers to find the appropriate wrapper for a given scheme. When the scheme is empty, the FileStreamWrapper is returned.
static private GetWrapperInternal ( Context ctx, string scheme ) : StreamWrapper
ctx Pchp.Core.Context Current runtime context.
scheme string The scheme portion of an URL.
return StreamWrapper
Ejemplo n.º 1
0
        /// <summary>
        /// Registers a user-wrapper specified by the name of a defining user-class.
        /// </summary>
        /// <param name="ctx">Runtime context.</param>
        /// <param name="protocol">The schema to be associated with the given wrapper.</param>
        /// <param name="classname">Name of the user class implementing the wrapper functions.</param>
        /// <param name="flags">Should be set to STREAM_IS_URL if protocol is a URL protocol. Default is 0, local stream.</param>
        /// <returns>False in case of failure (ex. schema already occupied).</returns>
        public static bool stream_wrapper_register(Context ctx, string protocol, string classname, StreamWrapperRegisterFlags flags = StreamWrapperRegisterFlags.Default)
        {
            // check if the scheme is already registered:
            if (string.IsNullOrEmpty(protocol) || StreamWrapper.GetWrapperInternal(ctx, protocol) == null)
            {
                // TODO: Warning?
                return(false);
            }

            var wrapperClass = ctx.GetDeclaredTypeOrThrow(classname, true);

            if (wrapperClass == null)
            {
                return(false);
            }

            // EX: [stream_wrapper_register]: create the user wrapper
            var wrapper = new UserStreamWrapper(ctx, protocol, wrapperClass, flags == StreamWrapperRegisterFlags.IsUrl);

            return(StreamWrapper.RegisterUserWrapper(ctx, protocol, wrapper));
        }