-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from oat-sa/develop
Develop
- Loading branch information
Showing
17 changed files
with
1,495 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OAT\Library\Lti1p3Core\Role; | ||
|
||
use OAT\Library\Lti1p3Core\Exception\LtiException; | ||
use OAT\Library\Lti1p3Core\Exception\LtiExceptionInterface; | ||
|
||
abstract class AbstractRole implements RoleInterface | ||
{ | ||
/** @var string */ | ||
protected $name; | ||
|
||
/** | ||
* @throws LtiExceptionInterface | ||
*/ | ||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
|
||
if (!$this->isValid()) { | ||
throw new LtiException(sprintf('Role %s is invalid for type %s', $this->name, static::getType())); | ||
} | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getSubName(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public function isCore(): bool | ||
{ | ||
$exp = explode('#', $this->name); | ||
|
||
return $this->getMap()[end($exp)]; | ||
} | ||
|
||
protected function isValid(): bool | ||
{ | ||
if (strpos($this->name, static::getNamespace()) !== 0) { | ||
return false; | ||
} | ||
|
||
$exp = explode('#', $this->name); | ||
|
||
return array_key_exists(end($exp), $this->getMap()); | ||
} | ||
|
||
abstract protected function getMap(): array; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OAT\Library\Lti1p3Core\Role\Collection; | ||
|
||
use OAT\Library\Lti1p3Core\Role\RoleInterface; | ||
use OAT\Library\Lti1p3Core\Util\Collection\Collection; | ||
use OAT\Library\Lti1p3Core\Util\Collection\CollectionInterface; | ||
|
||
class RoleCollection | ||
{ | ||
/** @var RoleInterface[]|CollectionInterface */ | ||
private $roles; | ||
|
||
public function __construct(array $roles = []) | ||
{ | ||
$this->roles = new Collection(); | ||
|
||
foreach ($roles as $role) { | ||
$this->add($role); | ||
} | ||
} | ||
|
||
public function all(): array | ||
{ | ||
return $this->roles->all(); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return $this->roles->count(); | ||
} | ||
|
||
public function add(RoleInterface $role): self | ||
{ | ||
$this->roles->set($role->getName(), $role); | ||
|
||
return $this; | ||
} | ||
|
||
public function has(string $name): bool | ||
{ | ||
return $this->roles->has($name); | ||
} | ||
|
||
public function get(string $name): RoleInterface | ||
{ | ||
return $this->roles->getMandatory($name); | ||
} | ||
|
||
public function canFindBy(?string $type = null, ?bool $core = null): bool | ||
{ | ||
return !empty($this->findBy($type, $core)); | ||
} | ||
|
||
/** | ||
* @return RoleInterface[] | ||
*/ | ||
public function findBy(?string $type = null, ?bool $core = null): array | ||
{ | ||
$roles = []; | ||
|
||
foreach ($this->roles as $name => $role) { | ||
$add = true; | ||
|
||
if (null !== $type) { | ||
$add = $add && $role::getType() === $type; | ||
} | ||
|
||
if (null !== $core) { | ||
$add = $add && $role->isCore() === $core; | ||
} | ||
|
||
if ($add) { | ||
$roles[$name] = $role; | ||
} | ||
} | ||
|
||
return $roles; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OAT\Library\Lti1p3Core\Role\Factory; | ||
|
||
use OAT\Library\Lti1p3Core\Exception\LtiExceptionInterface; | ||
use OAT\Library\Lti1p3Core\Role\RoleInterface; | ||
use OAT\Library\Lti1p3Core\Role\Type\ContextRole; | ||
use OAT\Library\Lti1p3Core\Role\Type\InstitutionRole; | ||
use OAT\Library\Lti1p3Core\Role\Type\SystemRole; | ||
|
||
class RoleFactory | ||
{ | ||
/** | ||
* @throws LtiExceptionInterface | ||
*/ | ||
public static function create(string $name): RoleInterface | ||
{ | ||
if (strpos($name, SystemRole::getNameSpace()) === 0) { | ||
return new SystemRole($name); | ||
} | ||
|
||
if (strpos($name, InstitutionRole::getNameSpace()) === 0) { | ||
return new InstitutionRole($name); | ||
} | ||
|
||
return new ContextRole($name); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2021 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OAT\Library\Lti1p3Core\Role; | ||
|
||
/** | ||
* @see http://www.imsglobal.org/spec/lti/v1p3/#role-vocabularies | ||
*/ | ||
interface RoleInterface | ||
{ | ||
public const TYPE_SYSTEM = 'system'; | ||
public const TYPE_INSTITUTION = 'institution'; | ||
public const TYPE_CONTEXT = 'context'; | ||
|
||
public const NAMESPACE_SYSTEM = 'http://purl.imsglobal.org/vocab/lis/v2/system/person'; | ||
public const NAMESPACE_INSTITUTION = 'http://purl.imsglobal.org/vocab/lis/v2/institution/person'; | ||
public const NAMESPACE_CONTEXT = 'http://purl.imsglobal.org/vocab/lis/v2/membership'; | ||
|
||
public static function getType(): string; | ||
|
||
public static function getNamespace(): string; | ||
|
||
public function getName(): string; | ||
|
||
public function getSubName(): ?string; | ||
|
||
public function isCore(): bool; | ||
} |
Oops, something went wrong.