class LTIToolProviderController in LTI Tool Provider 8
Same name and namespace in other branches
- 2.x src/Controller/LTIToolProviderController.php \Drupal\lti_tool_provider\Controller\LTIToolProviderController
Returns responses for lti_tool_provider module routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\lti_tool_provider\Controller\LTIToolProviderController
Expanded class hierarchy of LTIToolProviderController
1 file declares its use of LTIToolProviderController
- LTIToolProviderControllerTest.php in tests/
src/ Unit/ LTIToolProviderControllerTest.php
File
- src/
Controller/ LTIToolProviderController.php, line 26
Namespace
Drupal\lti_tool_provider\ControllerView source
class LTIToolProviderController extends ControllerBase {
/**
* The configuration factory.
*
* @var ConfigFactoryInterface
*/
protected $configFactory;
/**
* A logger instance.
*
* @var LoggerChannelFactoryInterface
*/
protected $loggerFactory;
/**
* The event dispatcher.
*
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* The page cache kill switch.
*
* @var ResponsePolicyInterface|KillSwitch
*/
protected $killSwitch;
/**
* The request.
*
* @var Request
*/
protected $request;
/**
* The request session.
*
* @var SessionInterface
*/
protected $session;
/**
* The LTI context.
*
* @var mixed
*/
protected $context;
/**
* Optional destination.
*
* @var string
*/
protected $destination;
/**
* Constructs a HTTP basic authentication provider object.
*
* @param ConfigFactoryInterface $configFactory
* The configuration factory.
* @param LoggerChannelFactoryInterface $loggerFactory
* A logger instance.
* @param EventDispatcherInterface $eventDispatcher
* The event dispatcher.
* @param ResponsePolicyInterface $killSwitch
* The page cache kill switch.
* @param Request $request
* The request.
* @param SessionInterface $session
* The request session.
* @param mixed $context
* The LTI context.
* @param string | null $destination
* Optional destination.
*/
public function __construct(ConfigFactoryInterface $configFactory, LoggerChannelFactoryInterface $loggerFactory, EventDispatcherInterface $eventDispatcher, ResponsePolicyInterface $killSwitch, Request $request, SessionInterface $session, $context, ?string $destination) {
$this->configFactory = $configFactory;
$this->loggerFactory = $loggerFactory
->get('lti_tool_provider');
$this->eventDispatcher = $eventDispatcher;
$this->killSwitch = $killSwitch;
$this->request = $request;
$this->session = $session;
$this->context = $context;
$this->destination = $destination;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) : LTIToolProviderController {
/* @var $configFactory ConfigFactoryInterface */
$configFactory = $container
->get('config.factory');
/* @var $loggerFactory LoggerChannelFactoryInterface */
$loggerFactory = $container
->get('logger.factory');
/* @var $eventDispatcher EventDispatcherInterface */
$eventDispatcher = $container
->get('event_dispatcher');
/* @var $killSwitch ResponsePolicyInterface */
$killSwitch = $container
->get('page_cache_kill_switch');
$request = Drupal::request();
$session = $request
->getSession();
$context = $session
->get('lti_tool_provider_context');
$destination = Drupal::config('lti_tool_provider.settings')
->get('destination');
return new static($configFactory, $loggerFactory, $eventDispatcher, $killSwitch, $request, $session, $context, $destination);
}
/**
* LTI launch.
*
* Authenticates the user via the authentication.lti_tool_provider service,
* login that user, and then redirect the user to the appropriate page.
*
* @return RedirectResponse
* Redirect user to appropriate LTI url.
*
* @see \Drupal\lti_tool_provider\Authentication\Provider\LTIToolProvider
* This controller requires that the authentication.lti_tool_provider
* service is attached to this route in lti_tool_provider.routing.yml.
*/
public function ltiLaunch() : RedirectResponse {
try {
$destination = '/';
if (empty($this->context)) {
throw new Exception('LTI context missing.');
}
if (!empty($this->destination)) {
$destination = $this->destination;
}
if (isset($this->context['custom_destination']) && !empty($this->context['custom_destination'])) {
$destination = $this->context['custom_destination'];
}
$this->killSwitch
->trigger();
$event = new LtiToolProviderLaunchRedirectEvent($this->context, $destination);
LtiToolProviderEvent::dispatchEvent($this->eventDispatcher, $event);
if ($event
->isCancelled()) {
throw new Exception($event
->getMessage());
}
$destination = $event
->getDestination();
return new RedirectResponse($destination);
} catch (Exception $e) {
$this->loggerFactory
->warning($e
->getMessage());
return new RedirectResponse('/', 500);
}
}
/**
* LTI return.
*
* Logs the user out and returns the user to the LMS.
*
* @return RedirectResponse
* Redirect user to appropriate return url.
*/
public function ltiReturn() {
try {
$destination = '/';
if (empty($this->context)) {
throw new Exception('LTI context missing in return request.');
}
if (!empty($this->destination)) {
$destination = $this->destination;
}
if (isset($this->context['launch_presentation_return_url']) && !empty($this->context['launch_presentation_return_url'])) {
$destination = $this->context['launch_presentation_return_url'];
}
$this->killSwitch
->trigger();
$event = new LtiToolProviderReturnEvent($this->context, $destination);
LtiToolProviderEvent::dispatchEvent($this->eventDispatcher, $event);
if ($event
->isCancelled()) {
throw new Exception($event
->getMessage());
}
$destination = $event
->getDestination();
$this
->userLogout();
return new TrustedRedirectResponse($destination);
} catch (Exception $e) {
$this->loggerFactory
->warning($e
->getMessage());
return new RedirectResponse('/', 500);
}
}
/**
* Checks access for LTI routes.
*
* @return AccessResult
* The access result.
*/
public function access() : AccessResult {
return AccessResult::allowedIf(!empty($this->context));
}
protected function userLogout() {
user_logout();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
LTIToolProviderController:: |
protected | property |
The configuration factory. Overrides ControllerBase:: |
|
LTIToolProviderController:: |
protected | property | The LTI context. | |
LTIToolProviderController:: |
protected | property | Optional destination. | |
LTIToolProviderController:: |
protected | property | The event dispatcher. | |
LTIToolProviderController:: |
protected | property | The page cache kill switch. | |
LTIToolProviderController:: |
protected | property |
A logger instance. Overrides LoggerChannelTrait:: |
|
LTIToolProviderController:: |
protected | property | The request. | |
LTIToolProviderController:: |
protected | property | The request session. | |
LTIToolProviderController:: |
public | function | Checks access for LTI routes. | |
LTIToolProviderController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
LTIToolProviderController:: |
public | function | LTI launch. | |
LTIToolProviderController:: |
public | function | LTI return. | |
LTIToolProviderController:: |
protected | function | ||
LTIToolProviderController:: |
public | function | Constructs a HTTP basic authentication provider object. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |