In the feat to update Route annotations from the deprecated
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method
and Sensio\Bundle\FrameworkExtraBundle\Configuration\Method
to use Symfony\Component\Routing\Annotation\Route
.
First of all I fixed the routes cos I realized I had some routes that ended with double closing bracket: ")".
The Fix:
Replace:
(\* @Route\(.*\))\)
With:
$1
Next, run a regex replace to update your route annotations:
Replace:
((\*\s)@Route\((.*))\)([\s]+\*(.*))?(\s+\*\s(@Method\(\{?(("\w+"(, )?)+)\}?\)))
With:
$1, methods={$8})$4
This helps you process replacements as shown below:
From:
/**
* Reset the password for a user (only use-able by super-admins)
*
* @Route("/{id}/confirm", name="user_reset")
* @Method({"GET", "POST"})
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $id
*/
To:
/**
* Reset the password for a user (only use-able by super-admins)
*
* @Route("/{id}/confirm", name="user_reset", methods={"GET", "POST"})
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $id
*/
From:
/**
* Delete the user
*
* @Route("/{id}/delete", name="user_reset")
* @template()
* @Method({"GET"})
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $id
*/
To:
/**
* Delete the user
*
* @Route("/{id}/delete", name="user_reset", methods={"GET"})
* @template()
* @param \Symfony\Component\HttpFoundation\Request $request
* @param int $id
*/
If like me, you have to update over 150 controllers that have one or more routes, then you'll find this useful if you haven't already started.
IDEs like VSCode will always show you a preview of what the replacements will look like before you click replace. Cheers!!
Have you ever had to do this? tell me how you did yours