本文整理汇总了C#中Pchp.Core.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Pchp.Core命名空间,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SocketStream
public SocketStream(Context ctx, Socket socket, string openedPath, StreamContext context, bool isAsync = false)
: base(ctx, null, StreamAccessOptions.Read | StreamAccessOptions.Write, openedPath, context)
{
Debug.Assert(socket != null);
this.socket = socket;
this.IsWriteBuffered = false;
this.eof = false;
this.isAsync = isAsync;
this.IsReadBuffered = false;
}
示例2: interface_exists
/// <summary>
/// Tests whether a given interface is defined.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="ifaceName">The name of the interface.</param>
/// <param name="autoload">Whether to attempt to call <c>__autoload</c>.</param>
/// <returns><B>true</B> if the interface given by <paramref name="ifaceName"/> has been defined,
/// <B>false</B> otherwise.</returns>
public static bool interface_exists(Context ctx, string ifaceName, bool autoload = true)
{
var info = ctx.GetDeclaredType(ifaceName);
if (info == null && autoload)
{
throw new NotImplementedException("autoload");
}
//
return info != null && info.Type.GetTypeInfo().IsInterface;
}
示例3: class_exists
/// <summary>
/// Tests whether a given class is defined.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="className">The name of the class.</param>
/// <param name="autoload">Whether to attempt to call <c>__autoload</c>.</param>
/// <returns><B>true</B> if the class given by <paramref name="className"/> has been defined,
/// <B>false</B> otherwise.</returns>
public static bool class_exists(Context ctx, string className, bool autoload = true)
{
var info = ctx.GetDeclaredType(className);
if (info == null && autoload)
{
throw new NotImplementedException("autoload");
}
//
return info != null;
}
示例4: call_user_func
/// <summary>
/// Calls a function or a method defined by callback with given arguments.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="function">Target callback.</param>
/// <param name="args">The arguments.</param>
/// <returns>The return value.</returns>
public static PhpValue call_user_func(Context ctx, IPhpCallable function, params PhpValue[] args)
{
if (function == null)
{
//PhpException.ArgumentNull("function");
//return null;
throw new ArgumentNullException(); // NOTE: should not be reached, runtime converts NULL to InvalidCallback instance
}
Debug.Assert(args != null);
// invoke the callback:
return function.Invoke(ctx, args);
}
示例5: call_user_func_array
/// <summary>
/// Calls a function or a method defined by callback with arguments stored in an array.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="function">Target callback.</param>
/// <param name="args">Arguments. Can be null.</param>
/// <returns>The returned value.</returns>
public static PhpValue call_user_func_array(Context ctx, IPhpCallable function, PhpArray args)
{
PhpValue[] args_array;
if (args != null && args.Count != 0)
{
args_array = new PhpValue[args.Count];
args.CopyValuesTo(args_array, 0);
}
else
{
args_array = Core.Utilities.ArrayUtils.EmptyValues;
}
return call_user_func(ctx, function, args_array);
}
示例6: FromValue
public static TextElement FromValue(Context ctx, PhpValue value)
{
switch (value.TypeCode)
{
case PhpTypeCode.Object:
if (value.Object is byte[])
{
return new TextElement((byte[])value.Object);
}
goto default;
case PhpTypeCode.WritableString:
return new TextElement(value.WritableString, ctx.StringEncoding);
default:
return new TextElement(value.ToStringOrThrow(ctx));
}
}
示例7: get_defined_constants
/// <summary>
/// Retrieves defined constants.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="categorize">Returns a multi-dimensional array with categories in the keys of the first dimension and constants and their values in the second dimension. </param>
/// <returns>Retrives the names and values of all the constants currently defined.</returns>
public static PhpArray get_defined_constants(Context ctx, bool categorize = false)
{
var result = new PhpArray();
if (categorize)
{
throw new NotImplementedException();
}
else
{
foreach (var c in ctx.GetConstants())
{
result.Add(c.Key, c.Value);
}
}
//
return result;
}
示例8: ProcessStatus
int ProcessStatus(Context ctx, ref PhpValue status)
{
switch (status.TypeCode)
{
case PhpTypeCode.Alias:
return ProcessStatus(ctx, ref status.Alias.Value);
case PhpTypeCode.Long:
case PhpTypeCode.Int32:
return (int)status.ToLong();
default:
if (ctx != null)
{
ctx.Echo(status);
}
return 0;
}
}
示例9: ob_start
/// <summary>
/// Increases the level of buffering, enables output buffering if disabled and assignes the filtering callback
/// to the new level of buffering.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="filter">The filtering callback. Ignores invalid callbacks.</param>
/// <param name="chunkSize">Not supported.</param>
/// <param name="erase">Not supported.</param>
/// <returns>Whether the filter is valid callback.</returns>
public static bool ob_start(Context ctx, Delegate filter = null, int chunkSize = 0, bool erase = true)
{
if (chunkSize != 0)
//PhpException.ArgumentValueNotSupported("chunkSize", "!= 0");
throw new NotSupportedException("chunkSize != 0");
if (!erase)
//PhpException.ArgumentValueNotSupported("erase", erase);
throw new NotSupportedException("erase == false");
ctx.BufferedOutput.IncreaseLevel();
bool result = true;
// skips filter setting if filter is not specified or valid:
if (filter != null) // && (result = filter.Bind())) // TODO: PhpCallback.Bind -> Delegate, done by caller
ctx.BufferedOutput.SetFilter(filter);
ctx.IsOutputBuffered = true;
return result;
}
示例10: CheckIncludePath
/// <summary>
/// Check if the path lays inside of the directory tree specified
/// by the <c>open_basedir</c> configuration option and return the resulting <paramref name="absolutePath"/>.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="relativePath">The filename to search for.</param>
/// <param name="absolutePath">The combined absolute path (either in the working directory
/// or in an include path wherever it has been found first).</param>
/// <returns><c>true</c> if the file was found in an include path.</returns>
private static bool CheckIncludePath(Context ctx, string relativePath, ref string absolutePath)
{
// Note: If the absolutePath exists, it overtakse the include_path search.
if (Path.IsPathRooted(relativePath)) return false;
if (File.Exists(absolutePath)) return false;
var paths = ctx.IncludePaths;
if (paths == null || paths.Length == 0) return false;
foreach (string s in paths)
{
if (string.IsNullOrEmpty(s)) continue;
string abs = Path.GetFullPath(Path.Combine(s, relativePath));
if (File.Exists(abs))
{
absolutePath = abs;
return true;
}
}
return false;
}
示例11: Open
/// <summary>
/// Openes a PhpStream using the appropriate StreamWrapper.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="path">URI or filename of the resource to be opened.</param>
/// <param name="mode">A file-access mode as passed to the PHP function.</param>
/// <param name="options">A combination of <see cref="StreamOpenOptions"/>.</param>
/// <param name="context">A valid StreamContext. Must not be <c>null</c>.</param>
/// <returns></returns>
public static PhpStream Open(Context ctx, string path, string mode, StreamOpenOptions options, StreamContext context)
{
if (context == null)
throw new ArgumentNullException("context");
Debug.Assert(ctx != null);
StreamWrapper wrapper;
if (!PhpStream.ResolvePath(ctx, ref path, out wrapper, CheckAccessMode.FileMayExist, (CheckAccessOptions)options))
return null;
return wrapper.Open(ctx, ref path, mode, options, context);
}
示例12: OutputChunks
static void OutputChunks(Context ctx, object[] chunks, int count)
{
for (int i = 0; i < count; i++)
{
OutputChunk(ctx, chunks[i]);
}
}
示例13: Output
internal void Output(Context ctx)
{
var chunks = _chunks;
if (chunks != null)
{
if (chunks.GetType() == typeof(object[]))
{
OutputChunks(ctx, (object[])chunks, _chunksCount);
}
else
{
OutputChunk(ctx, chunks);
}
}
}
示例14: preg_match
public static int preg_match(Context ctx, string pattern, string subject, out PhpArray matches, int flags = 0, long offset = 0)
{
throw new NotImplementedException();
}
示例15: preg_match_all
public static int preg_match_all(Context ctx, string pattern, string subject, out PhpArray matches, int flags = PREG_PATTERN_ORDER, int offset = 0)
{
throw new NotImplementedException();
}