Create api

I want to create an api with createAccount data that when a new sign up is done, the form data will be pass to an api system that my users can do whatever they wish to do with form data such as sending it to a third party script or whatever. I was thinking about creating a class with the name newAccountApi and in my createAccount controller I call this class and pass $_POST data to constructor of this class, this way they can do whatever they wish with form data in that class. But then I tought how they can do action with this data as this is a class not a controller! The same if I do this with a function instead of class. Which way do you suggest to do this?

Sounds like all you need is an event dispatching system. That way someone can add an observer with a listener for said event and achieve whatever action is necessary without hacking your controller class.

Thanks. As you suggested I added an eventListener like this: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#onflush
I have this:

foreach ($uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof User) {
             // Do something with User entity object.
         }
}

$entity is not a simple objects, It has lots of other mapped proxies etc. So how to prepare a json or array to pass to third party script other than getter methods inside entity class?

Of course I can use:
$data[‘username’] = $entity->getUsername();
$data[‘email’] = $entity->getEmail();

then pass $data to third part script, but I wanted to see if there is a way to have a clean object just with entity properties?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.