Frederik Holljen wrote: >> > Design goals >> > ============ >> > >> > The workflow of a creating a SystemProcess object applying certain >> arguments as >> > well as options to it and finally spawning the process should be >> intuitive as >> > possible. The best way to achieve such an intuitive API would be to >> design it >> > having the fluent interface pattern in mind. The used interface should >> look >> > something like this:: >> > >> > new ezcSystemProcess( 'echo' )->argument( 'foo' )->execute(); >> >> Method chaining can not be done with "new classname", so it has to be: >> >> $p = new ezcSystemProcess( 'echo' ); >> $p->argument( 'foo' )->execute(); > > I don't see why the fluent interface pattern makes this more > intuitive. I'd say it makes it less intuitive as a command is really > not complicated at all and the fluent interface pattern is to make a > complicated API more intuitive to use. > > Consider: > cmd = array( 'program_name', 'arg1', 'arg2', 'arg3', 'arg4', 'arg5', > 'arg6', 'arg7' ) > pOpbject = ezcSystemProcess::execute( cmd ) > > vs > $p = new ezcSystemProcess( 'program_name' ); > $p->argument( 'arg1' )->argument( 'arg2' )->argument( 'arg3' > )->argument( 'arg4' )->argument( 'arg5' )->argument( 'arg6' > )->argument( 'arg7' )->execute(); > > Which one is easier to read and less hassle to write? Another > advantage of the top one is that you can easily alter one parameter > and then run the command again. > > I'd take a look at the python subprocess module. It's an elegant > solution which should provide some good ideas.
How about keeping the same syntax as the Database component? To execute for example this command: $ pear install -a ezc/eZComponents you can write: <?php $p = new ezcSystemProcess(); $p->prepare( 'pear :command :arg1 :component' ); $p->bindValue( ':command', 'install' ); $p->bindValue( ':arg1', '-a' ); $p->bindValue( ':component', 'ezc/eZComponents' ); $p->execute(); ?> to reuse the same prepared command for '$ pear ugrade ezc/eZComponents': <?php // same $p as before $p->bindValue( ':command', 'upgrade' ); $p->bindValue( ':arg1', '' ); $p->execute(); ?> -- Alexandru Stanoi System Developer eZ Systems | http://ez.no -- Components mailing list Components@lists.ez.no http://lists.ez.no/mailman/listinfo/components