Created
September 23, 2016 14:43
-
-
Save alexwilson/f8bcb5f249b7caf7b26ff04fbfe20644 to your computer and use it in GitHub Desktop.
how to curl up into a fetal position and cry
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 // Why does syntax highlighting need this? | |
use eZ\Publish\Core\MVC\Symfony\Security\User as EzUser; | |
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Session\Session; | |
$securityContext = $container->get('security.context'); | |
$router = $container->get('router'); | |
$requestStack = $container->get('request_stack'); | |
if ($requestStack->getCurrentRequest() === null) { | |
// Log in as admin to subvert permissions from outside standard context. | |
$user = new EzUser($repository->getUserService()->loadUserByLogin('admin'), ['ROLE_USER']); | |
$token = new UsernamePasswordToken( | |
$user, | |
null, | |
'main', | |
$user->getRoles() | |
); | |
$securityContext->setToken($token); | |
// Generate full URL, optionally with site-access, and use it to build a new request. | |
$url = $router->generate('ez_urlalias', ['locationId' => 2, 'siteaccess' => '<OPTIONAL SITEACCESS HERE>'], true); | |
$request = Request::create($url); | |
// Start a new Session and assign it to our request. | |
$session = new Session(); | |
$request->setSession($session); | |
$requestStack->push($request); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment