PHP code example of symfonyboot / symfonyboot-bundle

1. Go to this page and download the library: Download symfonyboot/symfonyboot-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

symfonyboot / symfonyboot-bundle example snippets


/**
 * Payload converted with some serializer
 * @Route("/myAction", methods={"POST"}) 
 */
public function __invoke(Request $request, SerializerInterface $serializer)
{
    $myObject = $serializer->deserialize(
        $request->getContent(),
        MyObject::class,
        'json'
    );
    ...

use SilasYudi\RestBootBundle\Rest\Annotation\Body;

/**
 * Payload converted with @Body annotation
 * @Route("/myAction", methods={"POST"})
 * @Body("myObject")
 */
public function __invoke(MyObjectDTO $myObject)
{
    ...

/**
 * @Route("/myAction", methods={"POST"}) 
 */
public function __invoke()
{
    $connection = $this->getDoctrine()->getConnection(); 

    try {
        $connection->beginTransaction();
            
        $this->service->someAction();

        if ($connection->isTransactionActive()) {
            $connection->commit();
        }
    } catch (SomeException $exception) {
        if ($connection->isTransactionActive()) {
            $connection->rollback();
        }
    }

    ...

use SilasYudi\RestBootBundle\Transaction\Annotation\Transaction;

...

/**
 * @Route("/myAction", methods={"POST"})
 * @Transaction("myConnection")
 */
public function __invoke()
{
    $this->service->someAction();
    ...