1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Executing with non-xf PHP

Discussion in 'XenForo Development Discussions' started by silence, Jun 6, 2013.

  1. silence

    silence Well-Known Member

    I'm creating a callback to execute some stuff (executing stuff via this)

    How can I go about doing this in a callback since everything I try gives me errors (calling statically, etc)
     
  2. Jeremy

    Jeremy Well-Known Member

    How are you attempting to run that code within your callback?
     
  3. silence

    silence Well-Known Member

    Calling it statically, but that doesn't work since it's not a static class. If I define that specific code as a static class the $this objects won't work so I have no idea what to do.
     
  4. Jeremy

    Jeremy Well-Known Member

    Create a static class that creates an instance of the above class and uses it accordingly?
     
  5. silence

    silence Well-Known Member

    Would I cache it like any other xf model? Is there an example in XF's code that showcases this?
     
  6. Jeremy

    Jeremy Well-Known Member

    Quick glance looks like it happens on certain events, so realistically shouldn't need cached.
    PHP:
    <?php

    class myCallback {
      public static function 
    callback() {
        
    // do its work here. initalize, etc.
      
    }
    }
     
  7. silence

    silence Well-Known Member

    What about the $this objects then in the php script since everything is now static functions?
     
  8. Jeremy

    Jeremy Well-Known Member

    Why are you changing the actual class to static? You'll have to create a new instance of said class within the PHP:
    PHP:
    <?php

    class MyCallBack {
        public static function 
    callback() {
            
    $CServerRcon = new CServerRcon('pass''port''third argument');
            
    $CServerRcon->sendCommand('command');
        }
    }
    You won't change CServerRcon at all. If you wanted it all self contained you could do:
    PHP:
    <?php
    class CServerRcon {
      
    // current class

      
    public static function callback() {
        
    $self = new self();
      }
    }
    (self may not work in that instance, but I think it will).
     
    silence likes this.
  9. silence

    silence Well-Known Member

    $*(#@$ Alright
    One more: how would I call that class then? (since just CServerRcon would be locally called and i rather have that bulky script in a separate file)
     
  10. Jeremy

    Jeremy Well-Known Member

    What do you mean how would you call that class? You have to set the callback to be MyCallBack::callback() (for my example), and then require the CServerRcon file and initialize and use it as any other normal class.
     
  11. silence

    silence Well-Known Member

    Oh so literally include/require the file in that callback?
     
  12. Jeremy

    Jeremy Well-Known Member

    Yes.
     
    silence likes this.
  13. silence

    silence Well-Known Member

    Alright thanks mate! Sorry about the silly questions!
     
  14. silence

    silence Well-Known Member

    Weird issue in that script:
    fwrite() expects parameter 1 to be resource, null given

    Why wouldn't it be writing to the global variable even though it's set to do so?
     
  15. Jeremy

    Jeremy Well-Known Member

    The socket isn't being created and/or stored correctly.
     

Share This Page