Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
26 / 26 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Lti1p3LaunchRequestFactory | |
100.00% |
26 / 26 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| withLtiLaunchRequestBuilder | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
2 | |||
| getLaunchRequestBuilder | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRegistrationRepository | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020 (original work) Open Assessment Technologies SA |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoLti\models\classes\Tool\Factory; |
| 24 | |
| 25 | use ErrorException; |
| 26 | use OAT\Library\Lti1p3Core\Exception\LtiExceptionInterface; |
| 27 | use OAT\Library\Lti1p3Core\Message\Launch\Builder\LtiResourceLinkLaunchRequestBuilder; |
| 28 | use OAT\Library\Lti1p3Core\Message\LtiMessageInterface; |
| 29 | use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface; |
| 30 | use OAT\Library\Lti1p3Core\Resource\LtiResourceLink\LtiResourceLink; |
| 31 | use oat\oatbox\service\ConfigurableService; |
| 32 | use oat\taoLti\models\classes\Platform\Repository\Lti1p3RegistrationRepository; |
| 33 | use oat\taoLti\models\classes\Tool\LtiLaunchCommandInterface; |
| 34 | |
| 35 | class Lti1p3LaunchRequestFactory extends ConfigurableService |
| 36 | { |
| 37 | /** @var LtiResourceLinkLaunchRequestBuilder */ |
| 38 | private $ltiLaunchRequestBuilder; |
| 39 | |
| 40 | public function withLtiLaunchRequestBuilder(LtiResourceLinkLaunchRequestBuilder $ltiLaunchRequestBuilder): self |
| 41 | { |
| 42 | $this->ltiLaunchRequestBuilder = $ltiLaunchRequestBuilder; |
| 43 | |
| 44 | return $this; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @throws ErrorException |
| 49 | * @throws LtiExceptionInterface |
| 50 | */ |
| 51 | public function create(LtiLaunchCommandInterface $command): LtiMessageInterface |
| 52 | { |
| 53 | $registration = $this->getRegistrationRepository() |
| 54 | ->find($command->getLtiProvider()->getId()); |
| 55 | |
| 56 | if (!$registration) { |
| 57 | throw new ErrorException( |
| 58 | sprintf( |
| 59 | 'Registration for provider %s not found', |
| 60 | $command->getLtiProvider()->getId() |
| 61 | ) |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | return $this->getLaunchRequestBuilder()->buildLtiResourceLinkLaunchRequest( |
| 66 | new LtiResourceLink( |
| 67 | $command->getResourceIdentifier(), |
| 68 | [ |
| 69 | 'url' => $command->getLaunchUrl(), |
| 70 | ] |
| 71 | ), |
| 72 | $registration, |
| 73 | $command->getOpenIdLoginHint(), |
| 74 | $registration->getDefaultDeploymentId(), |
| 75 | $command->getRoles(), |
| 76 | $command->getClaims() |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | private function getLaunchRequestBuilder(): LtiResourceLinkLaunchRequestBuilder |
| 81 | { |
| 82 | return $this->ltiLaunchRequestBuilder ?? new LtiResourceLinkLaunchRequestBuilder(); |
| 83 | } |
| 84 | |
| 85 | private function getRegistrationRepository(): RegistrationRepositoryInterface |
| 86 | { |
| 87 | return $this->getServiceLocator()->get(Lti1p3RegistrationRepository::SERVICE_ID); |
| 88 | } |
| 89 | } |