Your question is quite broad, so I’ll explain "on top" what you can do if the idea is to actually 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 only route to receive the request data and map it to the class created above.
- Enable the service
serializer
in his config.yml
(example below);
- run your project with the command
bin/console server:start
- test the route with a request
POST
by means of the Httpie: echo '<data><tag>oi</tag></data>' | http 127.0.0.1:8000/
Filing cabinet config.yml
:
framework:
serializer:
enabled: true
(ps: no need to delete all key settings framework
, just add the configuration of serializer
).
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 the class AppBundle\Entity\Data
completed with the 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
)