Hello again,

I didn't finish posting the complete issue with the Console class, so
I will repeat everything here, I really apologize for this.

After watching the Symfony slides about the Console, I tried giving a
whirl to finally write some much needed utilities I need when setting
up a project.

Looking at the code and through usage I have come across a possible
enhancement in the Symfony\Components\Console\DialogHelper.

The function askAndValidate, should take an extra parameter where we
can define an array of extra arguments that can be parsed to the
closure which will validate the $value.

A sample situation is the following:

1.) I want to ask my user for a directory destination
2.) I provide a suggestion on the question that is displayed
3.) I askAndValidate, using my closure that will validate if I can
create that directory.
4.) In case the user doesn't type anything and just presses enter, I
can use the default that I suggested to fall through the validator.

So looking at my interact method bellow:

protected function interact(InputInterface $input, OutputInterface
$output){

        $docRootFunction = function($doc_root){

                if(file_exists($doc_root)){
                        return $doc_root;
                }

                if(!mkdir($doc_root)){
                        throw new \Exception("The $doc_root cannot be created");
                }

                return $doc_root;

        };


        $calc_docRoot= getcwd().'/web';

        $docRoot = $this->getHelper('dialog')->askAndValidate(
                                                                                
                        $output,
                                                                                
                        "Doc Root? [$calc_docRoot]",
                                                                                
                        $docRootFunction
                                                                                
                        );
}



The problem here is that the code for askAndValidate, does not allow a
second or arbitrary number of arguments to be passed in to the
$docRootFunction closure. I can work around this, but I just want to
suggest an enhancement.

An example usage could be:

protected function interact(InputInterface $input, OutputInterface
$output){

        $docRootFunction = function($args){ // <- Get an array of arguments
rather than a single value

                if(sizeof($args) < 2){
                        throw new \Exception("There  is a problem with your 
arguments");
                }

                $doc_root = $args[0] == '' ? $args[1] : $args[0]; //<-- Get the
default

                //Fall through the validation normally

                if(file_exists($doc_root)){
                        return $doc_root;
                }

                if(!mkdir($doc_root)){
                        throw new \Exception("The $doc_root cannot be created");
                }

                return $doc_root;

        };


        $calc_docRoot= getcwd().'/web';

        $docRoot = $this->getHelper('dialog')->askAndValidate(
                                                                                
                        $output,
                                                                                
                        "Doc Root? [$calc_docRoot]",
                                                                                
                        $docRootFunction, //<-- The closure
                                                                                
                        array($calc_docRoot), //<-- Any "extra" arguments you
would like for the closure
                                                                                
                        1       //<-- Repeat once
                                                                                
                        );
}

If you require further information please let me know.

Best Regards,
Fotis

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to