Skip to content

Commit

Permalink
Switch to using PhpCallableExtension.Invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
arontsang committed Feb 15, 2025
1 parent 2e60ced commit 6e41d1e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Peachpie.Runtime/ClrEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void remove(TDelegate callback)

#region IPhpCallable

PhpValue IPhpCallable.Invoke(Context ctx, params ReadOnlySpan<PhpValue> arguments)
PhpValue IPhpCallable.Invoke(Context ctx, ReadOnlySpan<PhpValue> arguments)
{
//TODO: check caller, invoke EventInfo.RaiseMethod?.Invoke(Target, arguments)
throw new NotSupportedException();
Expand Down
6 changes: 6 additions & 0 deletions src/Peachpie.Runtime/PhpCallableExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace Pchp.Core;
static partial class PhpCallableExtension
{

public static PhpValue Invoke(this IPhpCallable callable, Context context)
{
Span<PhpValue> args = Array.Empty<PhpValue>();
return callable.Invoke(context, args);
}

public static PhpValue Invoke(this IPhpCallable callable, Context context, PhpValue @parameter0)
{
var buffer = ArrayPool<PhpValue>.Shared.Rent(1);
Expand Down
4 changes: 2 additions & 2 deletions src/Peachpie.Runtime/PhpCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public interface IPhpCallable
/// <summary>
/// Invokes the object with given arguments.
/// </summary>
PhpValue Invoke(Context ctx, params ReadOnlySpan<PhpValue> arguments) => Invoke(ctx, arguments.ToArray());
PhpValue Invoke(Context ctx, ReadOnlySpan<PhpValue> arguments) => Invoke(ctx, arguments.ToArray());

/// <summary>
/// Invokes the object with given arguments.
/// </summary>
[Obsolete("Use Invoke(Context, ReadOnlySpan<PhpValue>) instead.")]
PhpValue Invoke(Context ctx, params PhpValue[] arguments) => Invoke(ctx, arguments.AsSpan());
PhpValue Invoke(Context ctx, PhpValue[] arguments) => Invoke(ctx, arguments.AsSpan());
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Peachpie.Runtime/Reflection/PhpRoutineInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected RoutineInfo(int index, string name)

#region IPhpCallable

PhpValue IPhpCallable.Invoke(Context ctx, params ReadOnlySpan<PhpValue> arguments) => Invoke(ctx, Target, arguments);
PhpValue IPhpCallable.Invoke(Context ctx, ReadOnlySpan<PhpValue> arguments) => Invoke(ctx, Target, arguments);

PhpValue IPhpCallable.ToPhpValue() => PhpValue.Null;

Expand Down
2 changes: 1 addition & 1 deletion src/Peachpie.Runtime/std/Closure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public PhpValue __invoke(params ReadOnlySpan<PhpValue> parameters)
/// <summary>
/// Implementation of <see cref="IPhpCallable"/>, invokes the anonymous function.
/// </summary>
PhpValue IPhpCallable.Invoke(Context ctx, params ReadOnlySpan<PhpValue> arguments) => __invoke(arguments);
PhpValue IPhpCallable.Invoke(Context ctx, ReadOnlySpan<PhpValue> arguments) => __invoke(arguments);

PhpValue IPhpCallable.ToPhpValue() => PhpValue.FromClass(this);

Expand Down

0 comments on commit 6e41d1e

Please sign in to comment.