Base class for PHP Resources - both built-in and extension-resources. Resources rely on GC Finalization - override FreeManaged for cleanup. When printing a resource variable in PHP, "Resource id #x" prints out.
Inheritance: IDisposable, IPhpConvertible
Exemple #1
0
        public static PhpStream GetValid(PhpResource handle, FileAccess desiredAccess)
        {
            PhpStream result = GetValid(handle);

            if (result != null)
            {
                if ((desiredAccess & FileAccess.Write) != 0 && !result.CanWrite)
                {
                    PhpException.Throw(PhpError.Warning, ErrResources.stream_write_off);
                    return null;
                }

                if ((desiredAccess & FileAccess.Read) != 0 && !result.CanRead)
                {
                    PhpException.Throw(PhpError.Warning, ErrResources.stream_read_off);
                    return null;
                }
            }

            return result;
        }
Exemple #2
0
 /// <summary>
 /// Check that the resource handle contains a valid
 /// PhpStream resource and cast the handle to PhpStream.
 /// </summary>
 /// <param name="handle">A PhpResource passed to the PHP function.</param>
 /// <returns>The handle cast to PhpStream.</returns>
 public static PhpStream GetValid(PhpResource handle)
 {
     var result = handle as PhpStream;
     if (result != null && result.IsValid)
     {
         return result;
     }
     else
     {
         PhpException.Throw(PhpError.Warning, ErrResources.invalid_stream_resource);
         return null;
     }
 }
Exemple #3
0
        /// <summary>
        /// Checks the context for validity, throws a warning it is not.
        /// </summary>
        /// <param name="resource">Resource which should contain a StreamContext.</param>
        /// <param name="allowNull"><c>True</c> to allow <c>NULL</c> context, that will be without any warning converted to Default <see cref="StreamContext"/>.</param>
        /// <returns>The given resource cast to <see cref="StreamContext"/> or <c>null</c> if invalid and <c>allowNull</c> is <c>false</c>.</returns>
        /// <exception cref="PhpException">In case the context is invalid.</exception>
        public static StreamContext GetValid(PhpResource resource, bool allowNull)
        {
            // implicit default from NULL
            if (allowNull && resource == null)
                return StreamContext.Default;

            // try to cast to StreamContext
            var result = resource as StreamContext;
            if (result != null /* TODO: Why is default context disposed? && result.IsValid*/)
                return result;

            //PhpException.Throw(PhpError.Warning, CoreResources.GetString("invalid_context_resource"));
            //return null;
            throw new NotImplementedException();
        }
Exemple #4
0
        /// <summary>
		/// Checks the context for validity, throws a warning it is not.
		/// </summary>
		/// <param name="resource">Resource which should contain a StreamContext.</param>
		/// <returns>The given resource cast to <see cref="StreamContext"/> or <c>null</c> if invalid.</returns>
		/// <exception cref="PhpException">In case the context is invalid.</exception>
		public static StreamContext GetValid(PhpResource resource) => GetValid(resource, false);
Exemple #5
0
 public static string get_resource_type(PhpResource resource) => resource?.TypeName;
Exemple #6
0
 new public static SocketStream GetValid(PhpResource handle)
 {
     SocketStream result = handle as SocketStream;
     if (result == null)
         PhpException.Throw(PhpError.Warning, ErrResources.invalid_socket_stream_resource);
     return result;
 }