Page 1 of 1

Providing PHP functions to call C# functions in Context

PostPosted: May 22nd, 2015, 10:07 am
by LInsoDeTeh
Hi!
I have a problem getting started with Phalanger.

I've got a C# class called Mission, which loads a .php script into a ScriptContext when initialized. It's no problem now to call PHP functions from the C# class, but how can I provide functions from the C# class to the users, who write only PHP scripts, which get loaded by this class?

Code: Select all
public class Mission {
  private ScriptContext context; 

  public Mission() {
    context = ScriptContext.CurrentContext;
    context.Include("mission.php", true);

    var missionClass = (PhpObject)context.NewObject("Mission");
 
    var onLoadFunction = new PhpCallback(missionClass , "onLoadFunction");
    onLoadFunction.Invoke(null);
  }

  public void StartTimer() {
     //do something
  }
}




Now, in the mission.php I have the "onLoadFunction" function, which I want to call the "StartTimer" function of the Mission C# class.

Code: Select all
<?
class Mission {
  function onLoadFunction() {
    //do something and then
    StartTimer();
  }
}
?>


How can I achieve the function "StartTimer" is available in PHP, when the script is run by the Mission C# class itself?

I assumed I could achieve this goal with the context.DeclareFunction method, but somehow I failed to create a RoutineDelegate instance, which is one of the Parameters.
Another thought would be to pass "this" to any PHP function from the C# code, so all public functions of the Mission instance could be available in PHP via a variable pointing to the C# class instance.

Is one of the Solutions the way to go? Or how could I solve this problem?

Thanks so much in advance :-)
Cheers
Chris

Re: Providing PHP functions to call C# functions in Context

PostPosted: May 22nd, 2015, 7:06 pm
by LInsoDeTeh
Solved the problem myself. Thanks anyway.