If you have a piece of logic that should be reused, it probably doesn't belong in the controllers. You should try moving it to a service, which is easy to do.
In src/BundleName/Resources/config/services.yml:
services:
service_name:
class: BundleName\Service\ServiceName
arguments: [@doctrine.orm.default_entity_manager]
Then, create BundleName\Service\ServiceName class (as shown in the docs) with the logic to be reused. An example below:
class ServiceName {
protected $entityManager;
public function __construct($entityManager) {
$this->entityManager = $entityManager;
}
public function addProduct($product) {
//Get the array, hydrate the entity and save it, at last.
//...
$entity = new Product();
//...
$this->entityManager->persist($entity);
$this->entityManager->flush($entity);
return $entity;
}
}
Then, in your actions, just call $this->get('service_name')->addProduct($array)
, or something like that.
Of course, if you want a controller action to be reused, you can use your controller as a service. I'd advice you to add a service layer, though.