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

Each array item as new argument

Comments in 'Plugin Development' started by Primus, Apr 11, 2016.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I can't think of any way to parse each value of arg into new argument
    PHP:
    $args = ['arg1''arg2''arg3'];
    # Method 1
    foreach($args as $arg){
       
    $class->function($arg);
    }
    # Method 2
    $class->function($args[0], $args[1], $args[2]);
    # Method 3
    $class->function($args[0].$args[1].$args[2]);
    I hope you understand that those methods above are useless and dumb :D
    HotFireyDeath likes this.
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    What do you actually want to do?
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Dynamic argument sending via $_POST data - something like that :D
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    if(isset($_POST['api_key'])){
       
        
    extract($_POST);
       
        
    $api = new Main($_POST);
       
        
    $r $api->hasPermission($_POST['api_key']);
        if(
    $r !== true){
            
    __error($r);
        } else {
           
           
            if(isset(
    $_POST['target'])){
                
    # What class is the method reffering to...
                # For example &target=BanManager&action=isBanned&args=Steve
               
                
    if(class_exists($target)){
                   
                    
    $s = new $target($api);
                   
                    if(isset(
    $_POST['action'])){
                        if(
    method_exists($s$action)){
                           
                            
    // 
                            
    $response['response'] = $s->$action($args);
                           
                        } else {
                            
    __error('007');
                        }
                    } else {
                        
    __error('006');
                    }
                   
                } else {
                    
    __error('005');
                }
               
            } else {
                
    __error('004');
            }
           
        }
       
    } else {
        die(
    'You don\'t have access to this file!');
    }
    HotFireyDeath likes this.
  5. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Try:
    PHP:
    $class = new Example();
    $args = ['arg1''arg2''arg3'];
    $argument "";
    foreach(
    $args as $arg){
     
    $argument .= $arg." ";
    }
    $class->function($argument);

    //Pretend this is the function:
    class Example {
     public function function(
    $argument){
      
    $args explode(" "$argument); // now has the args as array.
      //more code...
     
    }
    }
    theory
    Primus likes this.
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Not a bad idea but we have to add this code into each function then :/
    Just give the function array of args?

    Btw, I made first successful request to API, today :D
    Last edited: Apr 11, 2016
    HotFireyDeath likes this.

Share This Page

Advertisement