I have a symfony2 based application that basically exposes REST APIs. The application does not have any UI.
In the same application there are some commands that are created to manipulate the resources. Like creating a user, reseting password of a user, delete a user, assigning a user to particular group etc.
Now I want the command classes to use the REST APIs (they are nothing but controller actions) to perform the actual operations because those REST APIs are already equipped with validation logics or required other business logics etc.
Question: What is the best option to use the REST APIs (aka the controller actions) from Command classes? I can think of following two approaches.
Creating Request object inside command class. Setting proper request content, header etc. Include the controller class and call the controller action statically with the created request object.
Use curl to make the http calls with proper content and headers.
Among these two approaches above, the first one seems saner to me however it feels like there should be more elegant way to achieve this. Any suggestion?