SA-MP Forums Archive
[php] All possible combinations of function arguments - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: [php] All possible combinations of function arguments (/showthread.php?tid=451811)



[php] All possible combinations of function arguments - Misiur - 18.07.2013

Hi guys, I'm building cool tool (which I'll be releasing on github soon), and I need some help with catching all corner cases.

PHP код:
protected function setDefaultOptions(OptionsResolverInterface $resolver)
{
    
$resolver->setRequired(array(
        
'name',
    ));
    
$resolver->setDefaults(array(
        
'tag' => null,
        
'reference' => false,
        
'arrayDimension' => 0,
        
'arrayEnumerator' => array(),
        
'default' => null,
        
'operator' => null,
    ));
    
$resolver->setAllowedTypes(array(
        
'reference' => 'boolean',
        
//'tag' => '', @TODO
        
'arrayDimension' => 'int',
        
'arrayEnumerator' => 'array',
        
'operator' => 'array',
    ));
    
$resolver->setAllowedValues(array(
        
'arrayDimension' => range(03),
        
//'arrayEnumerator' => array(), @TODO
        
'operator' => array('const''sizeof''tagof'),
    ));
    
$resolver->setNormalizers(array(
        
'reference' => function (Options $options$value) {
            
//If array dimensions are passed, it's a constant, or sizeof/tagof, the value is or cannot be passed by reference
            
return empty($options['operator']);
        },
        
'arrayDimension'  => function (Options $options$value) {
            
$numberOfEnumerators count($options['arrayEnumerator']);
            return 
max(array($numberOfEnumerators$value));
        },
    ));

This code tries to check all possible argument combinations.

pawn Код:
Float:Value = 5.0
CUSTOM_TAG:Something[CUSTOM_SOMETHING][][]
&number
const somestring[]
tagof something
We are talking about valid pawn code, and not about macro substitutions (using <> and other things).
Now, except for elipsis, I think that covers a most of possible stuff. Did I miss something?