Last active
October 26, 2018 15:14
-
-
Save Toflar/2d641617419c18a497aa3aa2b301f244 to your computer and use it in GitHub Desktop.
Simple way to get my profile in ApiPlatform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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