Coder Social home page Coder Social logo

Comments (7)

miladr avatar miladr commented on August 31, 2024

It's already optional!
If you pass a variable as second argument of execute method of "CommanderTrait", "mapInputToCommand" won't execute.

from commander.

curranjensen avatar curranjensen commented on August 31, 2024

Hi miladir

When I checked the source I see execute always calls mapInputToCommand and reflects into your command class no matter what you give as second argument. I'm saying that for times that you don't need to have your class reflected into we could have a simple optional parameter on execute that would optionally abort calling mapInputToCommand. Otherwise, you are always stuck with input::all, or a default value on your command class parameter, or having to pass your own array. Perhaps passing your own array is what Jeff intended?

from commander.

miladr avatar miladr commented on August 31, 2024

"mapInputToCommand" could not be optional because trait is responsible for creating a command object and than pass it to CommandBus.
If you pass null as second argument, "execute" will make a Command object from Input::all(), otherwise it will make Command object from input array.

from commander.

curranjensen avatar curranjensen commented on August 31, 2024

Yeah I see that, I was just thinking say you had a command object already made, and then just pass it to execute with a flag to not reflect. In that case you wouldn't have to construct that input array. But no big deal if you don't like my idea.

from commander.

curranjensen avatar curranjensen commented on August 31, 2024

You wouldn't even have to have a flag, mapInputToCommand could run depending on if you passed a class or an existing object to execute

from commander.

miladr avatar miladr commented on August 31, 2024

Your idea works too but the idea behind CommandBus design pattern is making code in Controller as close as possible to real world Business language. In real world business a manager will say to his/her employers to do something with the input data. Manager is not responsible to shape data. Employer should shape data before use it and report to Manager that the job is done or fail.

from commander.

curranjensen avatar curranjensen commented on August 31, 2024

You could do this in the execute method. It would allow an existing command object to pass through and not be reflected.

if( ! is_object($command)) {
    $command = $this->mapInputToCommand($command, $input);
 }

from commander.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.