Skip to content

Instantly share code, notes, and snippets.

@Toflar
Last active October 26, 2018 15:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Toflar/2d641617419c18a497aa3aa2b301f244 to your computer and use it in GitHub Desktop.
Save Toflar/2d641617419c18a497aa3aa2b301f244 to your computer and use it in GitHub Desktop.
Simple way to get my profile in ApiPlatform
<?php
namespace App\Action;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class ProfileAction extends Controller
{
/**
* @Route("/profile", methods={"GET"})
*/
public function __invoke()
{
$user = $this->getUser();
if (!$user instanceof User) {
throw new NotFoundHttpException();
}
$route = $this->get('router')->getRouteCollection()->get('api_users_get_item');
$path = array_merge($route->getDefaults(), ['id' => $user->getId()]);
return $this->forward(
$path['_controller'],
$path
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment