Your question is pretty broad, so I'll explain "over the top" what you can do if the idea is to really use Symfony 3:
Create your Symfony 3 project with the command composer create-project symfony/framework-standard-edition <nome-do-projeto>
; this will create a project with several basic dependencies for most web projects (Doctrine, Swiftmailer, Twig etc);
create a class AppBundle\Entity\Data
with the data you will receive (I put an example below);
modify the single route to receive the request data and map it to the class created above.
Enable the serializer
service in its config.yml
(example below);
run your project with the command bin/console server:start
Test the route with a POST
request through HTTPie : echo '<data><tag>oi</tag></data>' | http 127.0.0.1:8000/
File config.yml
:
framework:
serializer:
enabled: true
(ps: You do not need to delete all settings from the framework
key, just add the serializer
setting).
Class AppBundle\Controller\DefaultController
:
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Data;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\SerializerInterface;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$data = $this->getSerializer()->deserialize($request->getContent(), Data::class, 'xml');
print_r($data); die;
}
/**
* @return SerializerInterface
*/
private function getSerializer()
{
return $this->get('serializer');
}
}
Class AppBundle\Entity\Data
:
<?php
namespace AppBundle\Entity;
class Data
{
public $tag;
}
If all went well, you will have an instance of class AppBundle\Entity\Data
populated with data received via POST
:
HTTP/1.1 200 OK
Connection: close
Content-type: text/html; charset=UTF-8
Host: 127.0.0.1:8000
X-Powered-By: PHP/5.6.22
AppBundle\Entity\Data Object
(
[tag] => oi
)