skip to Main Content

Following cPanel UAPI function store_filter I need to call function with a iterated params if there is more than one rule or action, like:

  • action1
  • action2
  • action3
  • dest1
  • dest2
  • dest3
    and so on.

But I don’t really understand how can I pass this iterate params to a function.

UPD

    $cpanel = new CPANEL(); // Connect to cPanel - only do this once.

// Create a new filter for [email protected].
$new_filter = $cpanel->uapi(
    'Email', 'store_filter',
    array(
        'filtername'      => 'coffee',
        'account'         => '[email protected]',
        'action1'         => 'deliver',
        'dest1'           => '[email protected]',
        'part1'           => '$header_subject:',
        'match1'          => 'contains',
        'val1'            => 'curds',
        'opt1'            => 'or',
        'part2'           => '$message_body',
        'match2'          => 'is',
        'val2'            => 'whey',
         )
);

2

Answers


  1. IMHO you don’t have to do anything extra. JavaScript comes equipped with Arguments object, arguments is an reserved keyword which you can use like this:

    function unlimitedArgs() {
      console.log(arguments)
    }
    
    unlimitedArgs(2,4, 'v1');
    
    unlimitedArgs(2,4, 'v1', [2,4,5], "some other value");

    Or, you can use spread operator to do something like this perhaps:

    function unlimitedArgs(...gatherer) {
      console.log(gatherer)
    }
    
    unlimitedArgs(2,4, 'v1');
    
    unlimitedArgs(2,4, 'v1', [2,4,5], "some other value");

    NOTE: If you use spread operator the container variable (ie gatherer) will be of type Array.

    Login or Signup to reply.
  2. may be this example helps

    function printNames(...names) {
      console.log(`number of arguments: ${names.length}`);
      for (var name of names) {
        console.log(name);
      }
    }
    
    printNames('foo', 'bar', 'baz');
    

    Whatever may be the arguments you can pass unlimited arguments and access the same with the function like above.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search