Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

63
vendor/php-xapi/model/src/Account.php vendored Normal file
View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A user account on an existing system.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Account
{
private $name;
private $homePage;
public function __construct(string $name, IRL $homePage)
{
$this->name = $name;
$this->homePage = $homePage;
}
/**
* Returns the unique id or name used to log in to this account.
*/
public function getName(): string
{
return $this->name;
}
/**
* Returns the home page for the system the account is on.
*/
public function getHomePage(): IRL
{
return $this->homePage;
}
/**
* Checks if another account is equal.
*
* Two accounts are equal if and only if all of their properties are equal.
*/
public function equals(Account $account): bool
{
if ($this->name !== $account->name) {
return false;
}
if (!$this->homePage->equals($account->homePage)) {
return false;
}
return true;
}
}

73
vendor/php-xapi/model/src/Activity.php vendored Normal file
View File

@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An Activity in a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Activity extends StatementObject
{
private $id;
private $definition;
public function __construct(IRI $id, Definition $definition = null)
{
$this->id = $id;
$this->definition = $definition;
}
/**
* Returns the Activity's unique identifier.
*/
public function getId(): IRI
{
return $this->id;
}
/**
* Returns the Activity's {@link Definition}.
*/
public function getDefinition(): ?Definition
{
return $this->definition;
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $object): bool
{
if (!$object instanceof Activity) {
return false;
}
if (!$this->id->equals($object->id)) {
return false;
}
if (null === $this->definition && null !== $object->definition) {
return false;
}
if (null !== $this->definition && null === $object->definition) {
return false;
}
if (null !== $this->definition && !$this->definition->equals($object->definition)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A {@link Profile} related to an {@link Activity}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ActivityProfile extends Profile
{
private $activity;
public function __construct(string $profileId, Activity $activity)
{
parent::__construct($profileId);
$this->activity = $activity;
}
/**
* Returns the {@link Activity}.
*/
public function getActivity(): Activity
{
return $this->activity;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A {@link Document} that is related to an {@link Activity}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ActivityProfileDocument extends Document
{
private $profile;
public function __construct(ActivityProfile $profile, DocumentData $data)
{
parent::__construct($data);
$this->profile = $profile;
}
public function getActivityProfile(): ActivityProfile
{
return $this->profile;
}
}

75
vendor/php-xapi/model/src/Actor.php vendored Normal file
View File

@@ -0,0 +1,75 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* The Actor of a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class Actor extends StatementObject
{
private $iri;
private $name;
public function __construct(InverseFunctionalIdentifier $iri = null, string $name = null)
{
$this->iri = $iri;
$this->name = $name;
}
/**
* Returns the Actor's {@link InverseFunctionalIdentifier inverse functional identifier}.
*/
public function getInverseFunctionalIdentifier(): ?InverseFunctionalIdentifier
{
return $this->iri;
}
/**
* Returns the name of the {@link Agent} or {@link Group}.
*/
public function getName(): ?string
{
return $this->name;
}
/**
* Checks if another actor is equal.
*
* Two actors are equal if and only if all of their properties are equal.
*/
public function equals(StatementObject $actor): bool
{
if (!parent::equals($actor)) {
return false;
}
if (!$actor instanceof Actor) {
return false;
}
if ($this->name !== $actor->name) {
return false;
}
if (null !== $this->iri xor null !== $actor->iri) {
return false;
}
if (null !== $this->iri && null !== $actor->iri && !$this->iri->equals($actor->iri)) {
return false;
}
return true;
}
}

37
vendor/php-xapi/model/src/Agent.php vendored Normal file
View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An individual Agent of an xAPI {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Agent extends Actor
{
public function __construct(InverseFunctionalIdentifier $iri, string $name = null)
{
parent::__construct($iri, $name);
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $actor): bool
{
if (!parent::equals($actor)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A {@link Profile} related to an {@link Agent}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class AgentProfile extends Profile
{
private $agent;
public function __construct(string $profileId, Agent $agent)
{
parent::__construct($profileId);
$this->agent = $agent;
}
public function getAgent(): Agent
{
return $this->agent;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A {@link Document} that is related to an {@link Agent}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class AgentProfileDocument extends Document
{
private $profile;
public function __construct(AgentProfile $profile, DocumentData $data)
{
parent::__construct($data);
$this->profile = $profile;
}
public function getAgentProfile(): AgentProfile
{
return $this->profile;
}
}

137
vendor/php-xapi/model/src/Attachment.php vendored Normal file
View File

@@ -0,0 +1,137 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An Experience API statement {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#attachments attachment}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Attachment
{
private $usageType;
private $contentType;
private $length;
private $sha2;
private $display;
private $description;
private $fileUrl;
private $content;
/**
* @param IRI $usageType The type of usage of this attachment
* @param string $contentType The content type of the attachment
* @param int $length The length of the attachment data in octets
* @param string $sha2 The SHA-2 hash of the attachment data
* @param LanguageMap $display Localized display name (title)
* @param LanguageMap|null $description Localized description
* @param IRL|null $fileUrl An IRL at which the attachment data can be retrieved
* @param string|null $content The raw attachment content, please note that the content is not validated against
* the given SHA-2 hash
*/
public function __construct(IRI $usageType, string $contentType, int $length, string $sha2, LanguageMap $display, LanguageMap $description = null, IRL $fileUrl = null, string $content = null)
{
if (null === $fileUrl && null === $content) {
throw new \InvalidArgumentException('An attachment cannot be created without a file URL or raw content data.');
}
$this->usageType = $usageType;
$this->contentType = $contentType;
$this->length = $length;
$this->sha2 = $sha2;
$this->display = $display;
$this->description = $description;
$this->fileUrl = $fileUrl;
$this->content = $content;
}
public function getUsageType(): IRI
{
return $this->usageType;
}
public function getContentType(): string
{
return $this->contentType;
}
public function getLength(): int
{
return $this->length;
}
public function getSha2(): string
{
return $this->sha2;
}
public function getDisplay(): LanguageMap
{
return $this->display;
}
public function getDescription(): ?LanguageMap
{
return $this->description;
}
public function getFileUrl(): ?IRL
{
return $this->fileUrl;
}
public function getContent(): ?string
{
return $this->content;
}
public function equals(Attachment $attachment): bool
{
if (!$this->usageType->equals($attachment->usageType)) {
return false;
}
if ($this->contentType !== $attachment->contentType) {
return false;
}
if ($this->length !== $attachment->length) {
return false;
}
if ($this->sha2 !== $attachment->sha2) {
return false;
}
if (!$this->display->equals($attachment->display)) {
return false;
}
if (null !== $this->description xor null !== $attachment->description) {
return false;
}
if (null !== $this->description && null !== $attachment->description && !$this->description->equals($attachment->description)) {
return false;
}
if (null !== $this->fileUrl xor null !== $attachment->fileUrl) {
return false;
}
if (null !== $this->fileUrl && null !== $attachment->fileUrl && !$this->fileUrl->equals($attachment->fileUrl)) {
return false;
}
return true;
}
}

204
vendor/php-xapi/model/src/Context.php vendored Normal file
View File

@@ -0,0 +1,204 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* Contextual information for an xAPI statement.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Context
{
private $registration;
private $instructor;
private $team;
private $contextActivities;
private $revision;
private $platform;
private $language;
private $statement;
private $extensions;
public function withRegistration(string $registration): self
{
$context = clone $this;
$context->registration = $registration;
return $context;
}
public function withInstructor(Actor $instructor): self
{
$context = clone $this;
$context->instructor = $instructor;
return $context;
}
public function withTeam(Group $team): self
{
$context = clone $this;
$context->team = $team;
return $context;
}
public function withContextActivities(ContextActivities $contextActivities): self
{
$context = clone $this;
$context->contextActivities = $contextActivities;
return $context;
}
public function withRevision(string $revision): self
{
$context = clone $this;
$context->revision = $revision;
return $context;
}
public function withPlatform(string $platform): self
{
$context = clone $this;
$context->platform = $platform;
return $context;
}
public function withLanguage(string $language): self
{
$context = clone $this;
$context->language = $language;
return $context;
}
public function withStatement(StatementReference $statement): self
{
$context = clone $this;
$context->statement = $statement;
return $context;
}
public function withExtensions(Extensions $extensions): self
{
$context = clone $this;
$context->extensions = $extensions;
return $context;
}
public function getRegistration(): ?string
{
return $this->registration;
}
public function getInstructor(): ?Actor
{
return $this->instructor;
}
public function getTeam(): ?Group
{
return $this->team;
}
public function getContextActivities(): ?ContextActivities
{
return $this->contextActivities;
}
public function getRevision(): ?string
{
return $this->revision;
}
public function getPlatform(): ?string
{
return $this->platform;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function getStatement(): ?StatementReference
{
return $this->statement;
}
public function getExtensions(): ?Extensions
{
return $this->extensions;
}
public function equals(Context $context): bool
{
if ($this->registration !== $context->registration) {
return false;
}
if (null !== $this->instructor xor null !== $context->instructor) {
return false;
}
if (null !== $this->instructor && null !== $context->instructor && !$this->instructor->equals($context->instructor)) {
return false;
}
if (null !== $this->team xor null !== $context->team) {
return false;
}
if (null !== $this->team && null !== $context->team && !$this->team->equals($context->team)) {
return false;
}
if ($this->contextActivities != $context->contextActivities) {
return false;
}
if ($this->revision !== $context->revision) {
return false;
}
if ($this->platform !== $context->platform) {
return false;
}
if ($this->language !== $context->language) {
return false;
}
if (null !== $this->statement xor null !== $context->statement) {
return false;
}
if (null !== $this->statement && null !== $context->statement && !$this->statement->equals($context->statement)) {
return false;
}
if (null !== $this->extensions xor null !== $context->extensions) {
return false;
}
if (null !== $this->extensions && null !== $context->extensions && !$this->extensions->equals($context->extensions)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,155 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* xAPI context activities.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ContextActivities
{
private $parentActivities;
private $groupingActivities;
private $categoryActivities;
private $otherActivities;
/**
* @param Activity[]|null $parentActivities
* @param Activity[]|null $groupingActivities
* @param Activity[]|null $categoryActivities
* @param Activity[]|null $otherActivities
*/
public function __construct(array $parentActivities = null, array $groupingActivities = null, array $categoryActivities = null, array $otherActivities = null)
{
$this->parentActivities = $parentActivities;
$this->groupingActivities = $groupingActivities;
$this->categoryActivities = $categoryActivities;
$this->otherActivities = $otherActivities;
}
public function withAddedParentActivity(Activity $parentActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->parentActivities)) {
$contextActivities->parentActivities = array();
}
$contextActivities->parentActivities[] = $parentActivity;
return $contextActivities;
}
public function withoutParentActivities(): self
{
$contextActivities = clone $this;
$contextActivities->parentActivities = null;
return $contextActivities;
}
public function withAddedGroupingActivity(Activity $groupingActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->groupingActivities)) {
$contextActivities->groupingActivities = array();
}
$contextActivities->groupingActivities[] = $groupingActivity;
return $contextActivities;
}
public function withoutGroupingActivities(): self
{
$contextActivities = clone $this;
$contextActivities->groupingActivities = null;
return $contextActivities;
}
public function withAddedCategoryActivity(Activity $categoryActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->categoryActivities)) {
$contextActivities->categoryActivities = array();
}
$contextActivities->categoryActivities[] = $categoryActivity;
return $contextActivities;
}
public function withoutCategoryActivities(): self
{
$contextActivities = clone $this;
$contextActivities->categoryActivities = null;
return $contextActivities;
}
public function withAddedOtherActivity(Activity $otherActivity): self
{
$contextActivities = clone $this;
if (!is_array($contextActivities->otherActivities)) {
$contextActivities->otherActivities = array();
}
$contextActivities->otherActivities[] = $otherActivity;
return $contextActivities;
}
public function withoutOtherActivities(): self
{
$contextActivities = clone $this;
$contextActivities->otherActivities = null;
return $contextActivities;
}
/**
* @return Activity[]|null
*/
public function getParentActivities(): ?array
{
return $this->parentActivities;
}
/**
* @return Activity[]|null
*/
public function getGroupingActivities(): ?array
{
return $this->groupingActivities;
}
/**
* @return Activity[]|null
*/
public function getCategoryActivities(): ?array
{
return $this->categoryActivities;
}
/**
* @return Activity[]|null
*/
public function getOtherActivities(): ?array
{
return $this->otherActivities;
}
}

206
vendor/php-xapi/model/src/Definition.php vendored Normal file
View File

@@ -0,0 +1,206 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* Definition of an {@link Activity}.
*
* A number of derived classes exists each of them covering a specialized
* type of user interaction:
*
* <ul>
* <li>ChoiceInteractionDefinition</li>
* <li>FillInteractionDefinition</li>
* <li>LikertInteractionDefinition</li>
* <li>LongFillInInteractionDefinition</li>
* <li>MatchingInteractionDefinition</li>
* <li>NumericInteractionDefinition</li>
* <li>PerformanceInteractionDefinition</li>
* <li>OtherInteractionDefinition</li>
* <li>SequencingInteractionDefinition</li>
* <li>TrueFalseInteractionDefinition</li>
* </ul>
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class Definition
{
private $name;
private $description;
private $type;
private $moreInfo;
private $extensions;
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null)
{
$this->name = $name;
$this->description = $description;
$this->type = $type;
$this->moreInfo = $moreInfo;
$this->extensions = $extensions;
}
public function withName(LanguageMap $name = null): self
{
$definition = clone $this;
$definition->name = $name;
return $definition;
}
public function withDescription(LanguageMap $description = null): self
{
$definition = clone $this;
$definition->description = $description;
return $definition;
}
public function withType(IRI $type = null): self
{
$definition = clone $this;
$definition->type = $type;
return $definition;
}
public function withMoreInfo(IRL $moreInfo = null): self
{
$definition = clone $this;
$definition->moreInfo = $moreInfo;
return $definition;
}
public function withExtensions(Extensions $extensions): self
{
$definition = clone $this;
$definition->extensions = $extensions;
return $definition;
}
/**
* Returns the human readable names.
*/
public function getName(): ?LanguageMap
{
return $this->name;
}
/**
* Returns the human readable descriptions.
*/
public function getDescription(): ?LanguageMap
{
return $this->description;
}
/**
* Returns the {@link Activity} type.
*/
public function getType(): ?IRI
{
return $this->type;
}
/**
* Returns an IRL where human-readable information about the activity can be found.
*/
public function getMoreInfo(): ?IRL
{
return $this->moreInfo;
}
public function getExtensions(): ?Extensions
{
return $this->extensions;
}
/**
* Checks if another definition is equal.
*
* Two definitions are equal if and only if all of their properties are equal.
*/
public function equals(Definition $definition): bool
{
if (get_class($this) !== get_class($definition)) {
return false;
}
if (null !== $this->type xor null !== $definition->type) {
return false;
}
if (null !== $this->type && null !== $definition->type && !$this->type->equals($definition->type)) {
return false;
}
if (null !== $this->moreInfo xor null !== $definition->moreInfo) {
return false;
}
if (null !== $this->moreInfo && null !== $definition->moreInfo && !$this->moreInfo->equals($definition->moreInfo)) {
return false;
}
if (null !== $this->extensions xor null !== $definition->extensions) {
return false;
}
if (null !== $this->name xor null !== $definition->name) {
return false;
}
if (null !== $this->description xor null !== $definition->description) {
return false;
}
if (null !== $this->name) {
if (count($this->name) !== count($definition->name)) {
return false;
}
foreach ($this->name as $language => $value) {
if (!isset($definition->name[$language])) {
return false;
}
if ($value !== $definition->name[$language]) {
return false;
}
}
}
if (null !== $this->description) {
if (count($this->description) !== count($definition->description)) {
return false;
}
foreach ($this->description as $language => $value) {
if (!isset($definition->description[$language])) {
return false;
}
if ($value !== $definition->description[$language]) {
return false;
}
}
}
if (null !== $this->extensions && null !== $definition->extensions && !$this->extensions->equals($definition->extensions)) {
return false;
}
return true;
}
}

71
vendor/php-xapi/model/src/Document.php vendored Normal file
View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An Experience API document.
*
* A document is immutable. This means that it can be accessed like an array.
* But you can only do this to read data. Thus an {@link UnsupportedOperationException}
* is thrown when you try to unset data or to manipulate them.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class Document implements \ArrayAccess
{
private $data;
public function __construct(DocumentData $data)
{
$this->data = $data;
}
/**
* {@inheritDoc}
*/
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}
/**
* {@inheritDoc}
*/
public function offsetGet($offset)
{
return $this->data[$offset];
}
/**
* {@inheritDoc}
*/
public function offsetSet($offset, $value): void
{
$this->data[$offset] = $value;
}
/**
* {@inheritDoc}
*/
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
/**
* Returns the document's data.
*/
public function getData(): DocumentData
{
return $this->data;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
use Xabbuh\XApi\Common\Exception\UnsupportedOperationException;
/**
* An xAPI document's data.
*
* Document data are immutable. This means that they can be accessed like an array.
* But you can only do this to read data. Thus an {@link UnsupportedOperationException}
* is thrown when you try to unset data or to manipulate them.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class DocumentData implements \ArrayAccess
{
private $data = array();
public function __construct(array $data = array())
{
$this->data = $data;
}
/**
* {@inheritDoc}
*/
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}
/**
* {@inheritDoc}
*/
public function offsetGet($offset)
{
if (!isset($this->data[$offset])) {
throw new \InvalidArgumentException(sprintf('No data for name "%s" registered.', $offset));
}
return $this->data[$offset];
}
/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException Documents are immutable
*/
public function offsetSet($offset, $value): void
{
throw new UnsupportedOperationException('A document is immutable.');
}
/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException Documents are immutable
*/
public function offsetUnset($offset): void
{
throw new UnsupportedOperationException('A document is immutable.');
}
/**
* Returns all data as an array.
*/
public function getData(): array
{
return $this->data;
}
}

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Exception;
use Xabbuh\XApi\Common\Exception\XApiException;
/**
* Exception indicating that an xAPI statement is in an invalid state (e.g.
* some necessary properties are missing).
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class InvalidStateException extends XApiException
{
}

117
vendor/php-xapi/model/src/Extensions.php vendored Normal file
View File

@@ -0,0 +1,117 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
use Xabbuh\XApi\Common\Exception\UnsupportedOperationException;
/**
* xAPI statement extensions.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Extensions implements \ArrayAccess
{
private $extensions;
public function __construct(\SplObjectStorage $extensions = null)
{
$this->extensions = array();
if (null !== $extensions) {
foreach ($extensions as $iri) {
if (!$iri instanceof IRI) {
throw new \InvalidArgumentException(sprintf('Expected an IRI instance as key (got %s).', is_object($iri) ? get_class($iri) : gettype($iri)));
}
$this->extensions[$iri->getValue()] = $extensions[$iri];
}
}
}
/**
* {@inheritdoc}
*/
public function offsetExists($offset): bool
{
if (!$offset instanceof IRI) {
throw new \InvalidArgumentException(sprintf('Expected an IRI instance as key (got %s).', is_object($offset) ? get_class($offset) : gettype($offset)));
}
return isset($this->extensions[$offset->getValue()]);
}
/**
* {@inheritdoc}
*/
public function offsetGet($offset)
{
if (!$offset instanceof IRI) {
throw new \InvalidArgumentException(sprintf('Expected an IRI instance as key (got %s).', is_object($offset) ? get_class($offset) : gettype($offset)));
}
if (!isset($this->extensions[$offset->getValue()])) {
throw new \InvalidArgumentException(sprintf('No extension for key "%s" registered.', $offset->getValue()));
}
return $this->extensions[$offset->getValue()];
}
/**
* {@inheritdoc}
*
* @throws UnsupportedOperationException Statement extensions are immutable
*/
public function offsetSet($offset, $value): void
{
throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
}
/**
* {@inheritdoc}
*
* @throws UnsupportedOperationException Statement extensions are immutable
*/
public function offsetUnset($offset): void
{
throw new UnsupportedOperationException('xAPI statement extensions are immutable.');
}
public function getExtensions(): \SplObjectStorage
{
$extensions = new \SplObjectStorage();
foreach ($this->extensions as $iri => $value) {
$extensions->attach(IRI::fromString($iri), $value);
}
return $extensions;
}
public function equals(Extensions $otherExtensions): bool
{
if (count($this->extensions) !== count($otherExtensions->extensions)) {
return false;
}
foreach ($this->extensions as $iri => $value) {
if (!array_key_exists($iri, $otherExtensions->extensions)) {
return false;
}
if ($this->extensions[$iri] != $otherExtensions->extensions[$iri]) {
return false;
}
}
return true;
}
}

66
vendor/php-xapi/model/src/Group.php vendored Normal file
View File

@@ -0,0 +1,66 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A group of {@link Agent Agents} of a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Group extends Actor
{
private $members = array();
/**
* @param Agent[] $members
*/
public function __construct(InverseFunctionalIdentifier $iri = null, string $name = null, array $members = array())
{
parent::__construct($iri, $name);
$this->members = $members;
}
/**
* Returns the members of this group.
*
* @return Agent[]
*/
public function getMembers(): array
{
return $this->members;
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $actor): bool
{
if (!parent::equals($actor)) {
return false;
}
/** @var Group $actor */
if (count($this->members) !== count($actor->members)) {
return false;
}
foreach ($this->members as $member) {
if (!in_array($member, $actor->members)) {
return false;
}
}
return true;
}
}

47
vendor/php-xapi/model/src/IRI.php vendored Normal file
View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An internationalized resource identifier according to RFC 3987.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class IRI
{
private $value;
private function __construct()
{
}
/**
* @throws \InvalidArgumentException if the given value is no valid IRI
*/
public static function fromString(string $value): self
{
$iri = new self();
$iri->value = $value;
return $iri;
}
public function getValue(): string
{
return $this->value;
}
public function equals(IRI $iri): bool
{
return $this->value === $iri->value;
}
}

47
vendor/php-xapi/model/src/IRL.php vendored Normal file
View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An internationalized resource locator.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class IRL
{
private $value;
private function __construct()
{
}
/**
* @throws \InvalidArgumentException if the given value is no valid IRL
*/
public static function fromString(string $value): self
{
$iri = new self();
$iri->value = $value;
return $iri;
}
public function getValue(): string
{
return $this->value;
}
public function equals(IRL $irl): bool
{
return $this->value === $irl->value;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
/**
* An interaction with a number of possible choices from which the learner
* can select.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class ChoiceInteractionDefinition extends InteractionDefinition
{
private $choices;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $choices
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $choices = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->choices = $choices;
}
/**
* @param InteractionComponent[]|null $choices
*/
public function withChoices(array $choices = null): self
{
$interaction = clone $this;
$interaction->choices = $choices;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getChoices(): ?array
{
return $this->choices;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof ChoiceInteractionDefinition) {
return false;
}
if (null !== $this->choices xor null !== $definition->choices) {
return false;
}
if (null !== $this->choices) {
if (count($this->choices) !== count($definition->choices)) {
return false;
}
foreach ($this->choices as $key => $choice) {
if (!isset($definition->choices[$key])) {
return false;
}
if (!$choice->equals($definition->choices[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
/**
* An interaction which requires the learner to supply a short response
* in the form of one or more strings of characters.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class FillInInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,58 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\LanguageMap;
/**
* An XAPI activity interaction component.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class InteractionComponent
{
private $id;
private $description;
public function __construct(string $id, LanguageMap $description = null)
{
$this->id = $id;
$this->description = $description;
}
public function getId(): string
{
return $this->id;
}
public function getDescription(): ?LanguageMap
{
return $this->description;
}
public function equals(InteractionComponent $interactionComponent): bool
{
if ($this->id !== $interactionComponent->id) {
return false;
}
if (null !== $this->description xor null !== $interactionComponent->description) {
return false;
}
if (null !== $this->description && null !== $interactionComponent->description && !$this->description->equals($interactionComponent->description)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,86 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
/**
* Base class for interaction definitions of an {@link Activity}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class InteractionDefinition extends Definition
{
private $correctResponsesPattern;
/**
* @param string[]|null $correctResponsesPattern
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions);
$this->correctResponsesPattern = $correctResponsesPattern;
}
/**
* @param string[]|null $correctResponsesPattern
*/
public function withCorrectResponsesPattern(array $correctResponsesPattern = null): self
{
$interaction = clone $this;
$interaction->correctResponsesPattern = $correctResponsesPattern;
return $interaction;
}
/**
* @return string[]|null
*/
public function getCorrectResponsesPattern(): ?array
{
return $this->correctResponsesPattern;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof InteractionDefinition) {
return false;
}
if (null !== $this->correctResponsesPattern xor null !== $definition->correctResponsesPattern) {
return false;
}
if (null !== $this->correctResponsesPattern) {
if (count($this->correctResponsesPattern) !== count($definition->correctResponsesPattern)) {
return false;
}
foreach ($this->correctResponsesPattern as $value) {
if (!in_array($value, $definition->correctResponsesPattern, true)) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
/**
* An interaction which asks the learner to select from a discrete set of
* choices on a scale.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class LikertInteractionDefinition extends InteractionDefinition
{
private $scale;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $scale
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $scale = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->scale = $scale;
}
/**
* @param InteractionComponent[]|null $scale
*/
public function withScale(array $scale = null): self
{
$interaction = clone $this;
$interaction->scale = $scale;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getScale(): ?array
{
return $this->scale;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof LikertInteractionDefinition) {
return false;
}
if (null !== $this->scale xor null !== $definition->scale) {
return false;
}
if (null !== $this->scale) {
if (count($this->scale) !== count($definition->scale)) {
return false;
}
foreach ($this->scale as $key => $scale) {
if (!isset($definition->scale[$key])) {
return false;
}
if (!$scale->equals($definition->scale[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
/**
* An interaction which requires the learner to supply a response in the
* form of a long string of characters.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class LongFillInInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,134 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
/**
* An interaction where the learner is asked to match items in one set
* (the source set) to items in another set (the target set).
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class MatchingInteractionDefinition extends InteractionDefinition
{
private $source;
private $target;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $source
* @param InteractionComponent[]|null $target
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $source = null, array $target = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->source = $source;
$this->target = $target;
}
/**
* @param InteractionComponent[]|null $source
*/
public function withSource(array $source = null): self
{
$interaction = clone $this;
$interaction->source = $source;
return $interaction;
}
/**
* @param InteractionComponent[]|null $target
*/
public function withTarget(array $target = null): self
{
$interaction = clone $this;
$interaction->target = $target;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getSource(): ?array
{
return $this->source;
}
/**
* @return InteractionComponent[]|null
*/
public function getTarget(): ?array
{
return $this->target;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof MatchingInteractionDefinition) {
return false;
}
if (null !== $this->source xor null !== $definition->source) {
return false;
}
if (null !== $this->target xor null !== $definition->target) {
return false;
}
if (null !== $this->source) {
if (count($this->source) !== count($definition->source)) {
return false;
}
foreach ($this->source as $key => $source) {
if (!isset($definition->source[$key])) {
return false;
}
if (!$source->equals($definition->source[$key])) {
return false;
}
}
}
if (null !== $this->target) {
if (count($this->target) !== count($definition->target)) {
return false;
}
foreach ($this->target as $key => $target) {
if (!isset($definition->target[$key])) {
return false;
}
if (!$target->equals($definition->target[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
/**
* Any interaction which requires a numeric response from the learner.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class NumericInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
/**
* A type of interaction that does not fit into the other defined ones.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class OtherInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,92 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
/**
* An interaction that requires the learner to perform a task that requires
* multiple steps.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class PerformanceInteractionDefinition extends InteractionDefinition
{
private $steps;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $steps
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $steps = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->steps = $steps;
}
/**
* @param InteractionComponent[]|null $steps
*/
public function withSteps(array $steps = null): self
{
$interaction = clone $this;
$interaction->steps = $steps;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getSteps(): ?array
{
return $this->steps;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof PerformanceInteractionDefinition) {
return false;
}
if (null !== $this->steps xor null !== $definition->steps) {
return false;
}
if (null !== $this->steps) {
if (count($this->steps) !== count($definition->steps)) {
return false;
}
foreach ($this->steps as $key => $step) {
if (!isset($definition->steps[$key])) {
return false;
}
if (!$step->equals($definition->steps[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
use Xabbuh\XApi\Model\Definition;
use Xabbuh\XApi\Model\Extensions;
use Xabbuh\XApi\Model\IRI;
use Xabbuh\XApi\Model\IRL;
use Xabbuh\XApi\Model\LanguageMap;
/**
* An interaction where the learner is asked to order items in a set.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class SequencingInteractionDefinition extends InteractionDefinition
{
private $choices;
/**
* @param string[]|null $correctResponsesPattern
* @param InteractionComponent[]|null $choices
*/
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $choices = null)
{
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern);
$this->choices = $choices;
}
/**
* @param InteractionComponent[]|null $choices
*/
public function withChoices(array $choices = null): self
{
$interaction = clone $this;
$interaction->choices = $choices;
return $interaction;
}
/**
* @return InteractionComponent[]|null
*/
public function getChoices(): ?array
{
return $this->choices;
}
public function equals(Definition $definition): bool
{
if (!parent::equals($definition)) {
return false;
}
if (!$definition instanceof SequencingInteractionDefinition) {
return false;
}
if (null !== $this->choices xor null !== $definition->choices) {
return false;
}
if (null !== $this->choices) {
if (count($this->choices) !== count($definition->choices)) {
return false;
}
foreach ($this->choices as $key => $choice) {
if (!isset($definition->choices[$key])) {
return false;
}
if (!$choice->equals($definition->choices[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model\Interaction;
/**
* An interaction with two possible responses: true or false.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class TrueFalseInteractionDefinition extends InteractionDefinition
{
}

View File

@@ -0,0 +1,149 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* The inverse functional identifier of an {@link Actor}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class InverseFunctionalIdentifier
{
private $mbox;
private $mboxSha1Sum;
private $openId;
private $account;
/**
* Use one of the with*() factory methods to obtain an InverseFunctionalIdentifier
* instance.
*/
private function __construct()
{
}
public static function withMbox(IRI $mbox): self
{
$iri = new InverseFunctionalIdentifier();
$iri->mbox = $mbox;
return $iri;
}
public static function withMboxSha1Sum(string $mboxSha1Sum): self
{
$iri = new InverseFunctionalIdentifier();
$iri->mboxSha1Sum = $mboxSha1Sum;
return $iri;
}
public static function withOpenId(string $openId): self
{
$iri = new InverseFunctionalIdentifier();
$iri->openId = $openId;
return $iri;
}
public static function withAccount(Account $account): self
{
$iri = new InverseFunctionalIdentifier();
$iri->account = $account;
return $iri;
}
/**
* Returns the mailto IRI.
*/
public function getMbox(): ?IRI
{
return $this->mbox;
}
/**
* Returns the SHA1 hash of a mailto IRI.
*/
public function getMboxSha1Sum(): ?string
{
return $this->mboxSha1Sum;
}
/**
* Returns the openID.
*/
public function getOpenId(): ?string
{
return $this->openId;
}
/**
* Returns the user account of an existing system.
*/
public function getAccount(): ?Account
{
return $this->account;
}
/**
* Checks if another IRI is equal.
*
* Two inverse functional identifiers are equal if and only if all of their
* properties are equal.
*/
public function equals(InverseFunctionalIdentifier $iri): bool
{
if (null !== $this->mbox && null !== $iri->mbox && !$this->mbox->equals($iri->mbox)) {
return false;
}
if ($this->mboxSha1Sum !== $iri->mboxSha1Sum) {
return false;
}
if ($this->openId !== $iri->openId) {
return false;
}
if (null === $this->account && null !== $iri->account) {
return false;
}
if (null !== $this->account && null === $iri->account) {
return false;
}
if (null !== $this->account && !$this->account->equals($iri->account)) {
return false;
}
return true;
}
public function __toString(): string
{
if (null !== $this->mbox) {
return $this->mbox->getValue();
}
if (null !== $this->mboxSha1Sum) {
return $this->mboxSha1Sum;
}
if (null !== $this->openId) {
return $this->openId;
}
return sprintf('%s (%s)', $this->account->getName(), $this->account->getHomePage()->getValue());
}
}

View File

@@ -0,0 +1,121 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* Read-only dictionary mapping RFC 5646 language tags to translated strings.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class LanguageMap implements \ArrayAccess, \Countable
{
private $map;
/**
* Creates a language map from the given dictionary.
*
* Keys are RFC 5646 language tags and each value is a string in the
* language specified by the key.
*/
public static function create(array $map): self
{
$languageMap = new self();
$languageMap->map = $map;
return $languageMap;
}
/**
* Creates a new language map based on the current map including the given entry.
*
* An existing entry will be overridden if the given language tag is already
* present in this language map.
*/
public function withEntry(string $languageTag, string $value): self
{
$languageMap = clone $this;
$languageMap->map[$languageTag] = $value;
return $languageMap;
}
/**
* Returns an unordered list of all language tags being used as keys
* in this language map.
*
* @return string[]
*/
public function languageTags(): array
{
return array_keys($this->map);
}
/**
* {@inheritdoc}
*/
public function offsetExists($languageTag): bool
{
return isset($this->map[$languageTag]);
}
/**
* {@inheritdoc}
*/
public function offsetGet($languageTag): string
{
if (!isset($this->map[$languageTag])) {
throw new \InvalidArgumentException(sprintf('The requested language tag "%s" does not exist in this language map.', $languageTag));
}
return $this->map[$languageTag];
}
/**
* {@inheritdoc}
*/
public function offsetSet($languageTag, $value): void
{
throw new \LogicException('The values of a language map cannot be modified. Use withEntry() instead to retrieve a new language map with the added or modified value.');
}
/**
* {@inheritdoc}
*/
public function offsetUnset($languageTag): void
{
throw new \LogicException('Entries of a language map cannot be removed.');
}
public function count(): int
{
return count($this->map);
}
public function equals(LanguageMap $languageMap): bool
{
if (count($this->map) !== count($languageMap->map)) {
return false;
}
foreach ($this->map as $languageTag => $value) {
if (!isset($languageMap[$languageTag])) {
return false;
}
if ($value !== $languageMap[$languageTag]) {
return false;
}
}
return true;
}
}

123
vendor/php-xapi/model/src/Person.php vendored Normal file
View File

@@ -0,0 +1,123 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* Combined informations from multiple {@link Agent agents}.
*
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
final class Person
{
/**
* @var string[] List of names of Agents
*/
private $names = array();
/**
* @var IRI[] List of mailto IRIs of Agents
*/
private $mboxes = array();
/**
* @var string[] List of the SHA1 hashes of mailto IRIs of Agents
*/
private $mboxSha1Sums = array();
/**
* @var string[] List of openids that uniquely identify the Agents
*/
private $openIds = array();
/**
* @var Account[] List of accounts of Agents
*/
private $accounts = array();
private function __construct()
{
}
/**
* @param Agent[] $agents
*/
public static function createFromAgents(array $agents): self
{
$person = new self();
foreach ($agents as $agent) {
$iri = $agent->getInverseFunctionalIdentifier();
if (null !== $mbox = $iri->getMbox()) {
$person->mboxes[] = $mbox;
}
if (null !== $mboxSha1Sum = $iri->getMboxSha1Sum()) {
$person->mboxSha1Sums[] = $mboxSha1Sum;
}
if (null !== $openId = $iri->getOpenId()) {
$person->openIds[] = $openId;
}
if (null !== $account = $iri->getAccount()) {
$person->accounts[] = $account;
}
if (null !== $name = $agent->getName()) {
$person->names[] = $name;
}
}
return $person;
}
/**
* @return string[]
*/
public function getNames(): array
{
return $this->names;
}
/**
* @return IRI[]
*/
public function getMboxes(): array
{
return $this->mboxes;
}
/**
* @return string[]
*/
public function getMboxSha1Sums(): array
{
return $this->mboxSha1Sums;
}
/**
* @return string[]
*/
public function getOpenIds(): array
{
return $this->openIds;
}
/**
* @return Account[]
*/
public function getAccounts(): array
{
return $this->accounts;
}
}

32
vendor/php-xapi/model/src/Profile.php vendored Normal file
View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A profile.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class Profile
{
private $profileId;
public function __construct(string $profileId)
{
$this->profileId = $profileId;
}
public function getProfileId(): string
{
return $this->profileId;
}
}

176
vendor/php-xapi/model/src/Result.php vendored Normal file
View File

@@ -0,0 +1,176 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An {@link Actor Actor's} outcome related to the {@link Statement} in which
* it is included.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Result
{
private $score;
private $success;
private $completion;
private $response;
private $duration;
private $extensions;
public function __construct(Score $score = null, bool $success = null, bool $completion = null, string $response = null, string $duration = null, Extensions $extensions = null)
{
$this->score = $score;
$this->success = $success;
$this->completion = $completion;
$this->response = $response;
$this->duration = $duration;
$this->extensions = $extensions;
}
public function withScore(Score $score = null): self
{
$result = clone $this;
$result->score = $score;
return $result;
}
public function withSuccess(bool $success = null): self
{
$result = clone $this;
$result->success = $success;
return $result;
}
public function withCompletion(bool $completion = null): self
{
$result = clone $this;
$result->completion = $completion;
return $result;
}
public function withResponse(string $response = null): self
{
$result = clone $this;
$result->response = $response;
return $result;
}
public function withDuration(string $duration = null): self
{
$result = clone $this;
$result->duration = $duration;
return $result;
}
public function withExtensions(Extensions $extensions = null): self
{
$result = clone $this;
$result->extensions = $extensions;
return $result;
}
/**
* Returns the user's score.
*/
public function getScore(): ?Score
{
return $this->score;
}
/**
* Returns whether or not the user finished a task successfully.
*/
public function getSuccess(): ?bool
{
return $this->success;
}
/**
* Returns the completion status.
*/
public function getCompletion(): ?bool
{
return $this->completion;
}
/**
* Returns the response.
*/
public function getResponse(): ?string
{
return $this->response;
}
/**
* Returns the period of time over which the Activity was performed.
*/
public function getDuration(): ?string
{
return $this->duration;
}
/**
* Returns the extensions associated with the result.
*/
public function getExtensions(): ?Extensions
{
return $this->extensions;
}
/**
* Checks if another result is equal.
*
* Two results are equal if and only if all of their properties are equal.
*/
public function equals(Result $result): bool
{
if (null !== $this->score xor null !== $result->score) {
return false;
}
if (null !== $this->score && !$this->score->equals($result->score)) {
return false;
}
if ($this->success !== $result->success) {
return false;
}
if ($this->completion !== $result->completion) {
return false;
}
if ($this->response !== $result->response) {
return false;
}
if ($this->duration !== $result->duration) {
return false;
}
if (null !== $this->extensions xor null !== $result->extensions) {
return false;
}
if (null !== $this->extensions && null !== $result->extensions && !$this->extensions->equals($result->extensions)) {
return false;
}
return true;
}
}

165
vendor/php-xapi/model/src/Score.php vendored Normal file
View File

@@ -0,0 +1,165 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* The outcome of an {@link Activity} achieved by an {@link Agent}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Score
{
private $scaled;
private $raw;
private $min;
private $max;
/**
* @param float|int|null $scaled
* @param float|int|null $raw
* @param float|int|null $min
* @param float|int|null $max
*/
public function __construct($scaled = null, $raw = null, $min = null, $max = null)
{
$this->scaled = $scaled;
$this->raw = $raw;
$this->min = $min;
$this->max = $max;
}
/**
* @param float|int|null $scaled
*/
public function withScaled($scaled): self
{
$score = clone $this;
$score->scaled = $scaled;
return $score;
}
/**
* @param float|int|null $raw
*/
public function withRaw($raw): self
{
$score = clone $this;
$score->raw = $raw;
return $score;
}
/**
* @param float|int|null $min
*/
public function withMin($min): self
{
$score = clone $this;
$score->min = $min;
return $score;
}
/**
* @param float|int|null $max
*/
public function withMax($max): self
{
$score = clone $this;
$score->max = $max;
return $score;
}
/**
* Returns the Agent's scaled score (a number between -1 and 1).
*
* @return float|int|null The scaled score
*/
public function getScaled()
{
return $this->scaled;
}
/**
* Returns the Agent's score (a number between min and max).
*
* @return float|int|null The score
*/
public function getRaw()
{
return $this->raw;
}
/**
* Returns the lowest possible score.
*
* @return float|int|null The lowest possible score
*/
public function getMin()
{
return $this->min;
}
/**
* Returns the highest possible score.
*
* @return float|int|null The highest possible score
*/
public function getMax()
{
return $this->max;
}
/**
* Checks if another score is equal.
*
* Two scores are equal if and only if all of their properties are equal.
*/
public function equals(Score $score): bool
{
if (null !== $this->scaled xor null !== $score->scaled) {
return false;
}
if ((float) $this->scaled !== (float) $score->scaled) {
return false;
}
if (null !== $this->raw xor null !== $score->raw) {
return false;
}
if ((float) $this->raw !== (float) $score->raw) {
return false;
}
if (null !== $this->min xor null !== $score->min) {
return false;
}
if ((float) $this->min !== (float) $score->min) {
return false;
}
if (null !== $this->max xor null !== $score->max) {
return false;
}
if ((float) $this->max !== (float) $score->max) {
return false;
}
return true;
}
}

81
vendor/php-xapi/model/src/State.php vendored Normal file
View File

@@ -0,0 +1,81 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An activity provider's state stored on a remote LRS.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class State
{
private $activity;
private $actor;
private $registrationId;
private $stateId;
public function __construct(Activity $activity, Actor $actor, string $stateId, string $registrationId = null)
{
if (!$actor instanceof Agent) {
@trigger_error(sprintf('Passing an instance of "%s" as the second argument is deprecated since 1.2. In 4.0, only instances of "Xabbuh\XApi\Model\Agent" will be accepted.', get_class($actor)), E_USER_DEPRECATED);
}
$this->activity = $activity;
$this->actor = $actor;
$this->stateId = $stateId;
$this->registrationId = $registrationId;
}
/**
* Returns the activity.
*/
public function getActivity(): Activity
{
return $this->activity;
}
/**
* Returns the actor.
*
* @deprecated since 1.2, to be removed in 4.0
*/
public function getActor(): Actor
{
@trigger_error(sprintf('The "%s()" method is deprecated since 1.2 and will be removed in 4.0, use "%s::getAgent()" instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED);
return $this->getAgent();
}
/**
* Returns the agent.
*/
public function getAgent(): Agent
{
return $this->actor;
}
/**
* Returns the registration id.
*/
public function getRegistrationId(): ?string
{
return $this->registrationId;
}
/**
* Returns the state's id.
*/
public function getStateId(): string
{
return $this->stateId;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A document associated to an activity provider state.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StateDocument extends Document
{
private $state;
public function __construct(State $state, DocumentData $data)
{
parent::__construct($data);
$this->state = $state;
}
/**
* Returns the document's {@link State}.
*/
public function getState(): State
{
return $this->state;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* Filter to apply on GET requests to the states API.
*
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
class StateDocumentsFilter
{
/**
* @var array The generated filter
*/
private $filter = array();
/**
* Filter by an Activity.
*/
public function byActivity(Activity $activity): self
{
$this->filter['activity'] = $activity->getId()->getValue();
return $this;
}
/**
* Filters by an Agent.
*/
public function byAgent(Agent $agent): self
{
$this->filter['agent'] = $agent;
return $this;
}
/**
* Filters for State documents matching the given registration id.
*/
public function byRegistration(string $registration): self
{
$this->filter['registration'] = $registration;
return $this;
}
/**
* Filters for State documents stored since the specified timestamp (exclusive).
*/
public function since(\DateTime $timestamp): self
{
$this->filter['since'] = $timestamp->format('c');
return $this;
}
/**
* Returns the generated filter.
*
* @return array The filter
*/
public function getFilter(): array
{
return $this->filter;
}
}

343
vendor/php-xapi/model/src/Statement.php vendored Normal file
View File

@@ -0,0 +1,343 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Statement
{
private $id;
private $verb;
private $actor;
private $object;
private $result;
private $authority;
private $created;
private $stored;
private $context;
private $attachments;
private $version;
/**
* @param Attachment[]|null $attachments
*/
public function __construct(StatementId $id = null, Actor $actor, Verb $verb, StatementObject $object, Result $result = null, Actor $authority = null, \DateTime $created = null, \DateTime $stored = null, Context $context = null, array $attachments = null, string $version = null)
{
$this->id = $id;
$this->actor = $actor;
$this->verb = $verb;
$this->object = $object;
$this->result = $result;
$this->authority = $authority;
$this->created = $created;
$this->stored = $stored;
$this->context = $context;
$this->attachments = null !== $attachments ? array_values($attachments) : null;
$this->version = $version;
}
public function withId(StatementId $id = null): self
{
$statement = clone $this;
$statement->id = $id;
return $statement;
}
public function withActor(Actor $actor): self
{
$statement = clone $this;
$statement->actor = $actor;
return $statement;
}
public function withVerb(Verb $verb): self
{
$statement = clone $this;
$statement->verb = $verb;
return $statement;
}
public function withObject(StatementObject $object): self
{
$statement = clone $this;
$statement->object = $object;
return $statement;
}
public function withResult(Result $result = null): self
{
$statement = clone $this;
$statement->result = $result;
return $statement;
}
/**
* Creates a new Statement based on the current one containing an Authority
* that asserts the Statement true.
*/
public function withAuthority(Actor $authority = null): self
{
$statement = clone $this;
$statement->authority = $authority;
return $statement;
}
public function withCreated(\DateTime $created = null): self
{
$statement = clone $this;
$statement->created = $created;
return $statement;
}
public function withStored(\DateTime $stored = null): self
{
$statement = clone $this;
$statement->stored = $stored;
return $statement;
}
public function withContext(Context $context = null): self
{
$statement = clone $this;
$statement->context = $context;
return $statement;
}
/**
* @param Attachment[]|null $attachments
*/
public function withAttachments(array $attachments = null): self
{
$statement = clone $this;
$statement->attachments = null !== $attachments ? array_values($attachments) : null;
return $statement;
}
public function withVersion(string $version = null): self
{
$statement = clone $this;
$statement->version = $version;
return $statement;
}
/**
* Returns the Statement's unique identifier.
*/
public function getId(): ?StatementId
{
return $this->id;
}
/**
* Returns the Statement's {@link Verb}.
*/
public function getVerb(): Verb
{
return $this->verb;
}
/**
* Returns the Statement's {@link Actor}.
*/
public function getActor(): Actor
{
return $this->actor;
}
/**
* Returns the Statement's {@link StatementObject}.
*/
public function getObject(): StatementObject
{
return $this->object;
}
/**
* Returns the {@link Activity} {@link Result}.
*/
public function getResult(): ?Result
{
return $this->result;
}
/**
* Returns the Authority that asserted the Statement true.
*/
public function getAuthority(): ?Actor
{
return $this->authority;
}
/**
* Returns the timestamp of when the events described in this statement
* occurred.
*/
public function getCreated(): ?\DateTime
{
return $this->created;
}
/**
* Returns the timestamp of when this statement was recorded by the LRS.
*/
public function getStored(): ?\DateTime
{
return $this->stored;
}
/**
* Returns the context that gives the statement more meaning.
*/
public function getContext(): ?Context
{
return $this->context;
}
/**
* @return Attachment[]|null
*/
public function getAttachments(): ?array
{
return $this->attachments;
}
public function getVersion(): ?string
{
return $this->version;
}
/**
* Tests whether or not this Statement is a void Statement (i.e. it voids
* another Statement).
*/
public function isVoidStatement(): bool
{
return $this->verb->isVoidVerb();
}
/**
* Returns a {@link StatementReference} for the Statement.
*/
public function getStatementReference(): StatementReference
{
return new StatementReference($this->id);
}
/**
* Returns a Statement that voids the current Statement.
*/
public function getVoidStatement(Actor $actor): self
{
return new Statement(
null,
$actor,
Verb::createVoidVerb(),
$this->getStatementReference()
);
}
/**
* Checks if another statement is equal.
*
* Two statements are equal if and only if all of their properties are equal.
*/
public function equals(Statement $statement): bool
{
if (null !== $this->id xor null !== $statement->id) {
return false;
}
if (null !== $this->id && null !== $statement->id && !$this->id->equals($statement->id)) {
return false;
}
if (!$this->actor->equals($statement->actor)) {
return false;
}
if (!$this->verb->equals($statement->verb)) {
return false;
}
if (!$this->object->equals($statement->object)) {
return false;
}
if (null === $this->result && null !== $statement->result) {
return false;
}
if (null !== $this->result && null === $statement->result) {
return false;
}
if (null !== $this->result && !$this->result->equals($statement->result)) {
return false;
}
if (null === $this->authority && null !== $statement->authority) {
return false;
}
if (null !== $this->authority && null === $statement->authority) {
return false;
}
if (null !== $this->authority && !$this->authority->equals($statement->authority)) {
return false;
}
if ($this->created != $statement->created) {
return false;
}
if (null !== $this->context xor null !== $statement->context) {
return false;
}
if (null !== $this->context && null !== $statement->context && !$this->context->equals($statement->context)) {
return false;
}
if (null !== $this->attachments xor null !== $statement->attachments) {
return false;
}
if (null !== $this->attachments && null !== $statement->attachments) {
if (count($this->attachments) !== count($statement->attachments)) {
return false;
}
foreach ($this->attachments as $key => $attachment) {
if (!$attachment->equals($statement->attachments[$key])) {
return false;
}
}
}
return true;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
use Xabbuh\XApi\Model\Exception\InvalidStateException;
/*
* Statement factory eases the creation of complex xAPI statements.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementFactory
{
private $id;
private $actor;
private $verb;
private $object;
private $result;
private $context;
private $created;
private $stored;
private $authority;
public function withId(StatementId $id): void
{
$this->id = $id;
}
public function withActor(Actor $actor): void
{
$this->actor = $actor;
}
public function withVerb(Verb $verb): void
{
$this->verb = $verb;
}
public function withObject(StatementObject $object): void
{
$this->object = $object;
}
public function withResult(Result $result = null): void
{
$this->result = $result;
}
public function withContext(Context $context = null): void
{
$this->context = $context;
}
public function withCreated(\DateTime $created = null): void
{
$this->created = $created;
}
public function withStored(\DateTime $stored = null): void
{
$this->stored = $stored;
}
public function withAuthority(Actor $authority = null): void
{
$this->authority = $authority;
}
/**
* Returns a statement based on the current configuration.
*
* Multiple calls to this method will return different instances.
*
* @throws InvalidStateException
*/
public function createStatement(): Statement
{
if (null === $this->actor) {
throw new InvalidStateException('A statement actor is missing.');
}
if (null === $this->verb) {
throw new InvalidStateException('A statement verb is missing.');
}
if (null === $this->object) {
throw new InvalidStateException('A statement object is missing.');
}
return new Statement($this->id, $this->actor, $this->verb, $this->object, $this->result, $this->authority, $this->created, $this->stored, $this->context);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* An Experience API {@link https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#statement Statement} identifier.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementId
{
private $uuid;
private function __construct()
{
}
public static function fromUuid(Uuid $uuid): self
{
$id = new self();
$id->uuid = $uuid;
return $id;
}
/**
* Creates a statement id based on the given UUID string.
*
* @throws \InvalidArgumentException when the given id is not a well-formed UUID
*/
public static function fromString(string $id): self
{
return self::fromUuid(Uuid::fromString($id));
}
public function getValue(): string
{
return (string) $this->uuid;
}
public function equals(StatementId $id): bool
{
return $this->uuid->equals($id->uuid);
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* The object of a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class StatementObject
{
/**
* Checks if another object is equal.
*
* Two objects are equal if and only if all of their properties are equal.
*/
public function equals(StatementObject $object): bool
{
return get_class($this) === get_class($object);
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A reference to an existing {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementReference extends StatementObject
{
private $statementId;
public function __construct(StatementId $statementId)
{
$this->statementId = $statementId;
}
/**
* Returns the id of the referenced Statement.
*/
public function getStatementId(): StatementId
{
return $this->statementId;
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $object): bool
{
if (!$object instanceof StatementReference) {
return false;
}
return $this->statementId->equals($object->statementId);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* Result when querying a Learning Record Store (LRS) for a list of
* {@link Statement Statements}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class StatementResult
{
private $statements;
private $moreUrlPath;
/**
* @param Statement[] $statements The collection of Statements
*/
public function __construct(array $statements, IRL $moreUrlPath = null)
{
$this->statements = $statements;
$this->moreUrlPath = $moreUrlPath;
}
/**
* Returns the Statements.
*
* @return Statement[]
*/
public function getStatements(): array
{
return $this->statements;
}
/**
* Relative IRL that can be used to retrieve the next results.
*/
public function getMoreUrlPath(): ?IRL
{
return $this->moreUrlPath;
}
}

View File

@@ -0,0 +1,168 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* Filter to apply on GET requests to the statements API.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
class StatementsFilter
{
private $filter = array();
/**
* Filters by an Agent or an identified Group.
*/
public function byActor(Actor $actor): self
{
$this->filter['agent'] = $actor;
return $this;
}
/**
* Filters by a verb.
*/
public function byVerb(Verb $verb): self
{
$this->filter['verb'] = $verb->getId()->getValue();
return $this;
}
/**
* Filter by an Activity.
*/
public function byActivity(Activity $activity): self
{
$this->filter['activity'] = $activity->getId()->getValue();
return $this;
}
/**
* Filters for Statements matching the given registration id.
*/
public function byRegistration(string $registration): self
{
$this->filter['registration'] = $registration;
return $this;
}
/**
* Applies the Activity filter to Sub-Statements.
*/
public function enableRelatedActivityFilter(): self
{
$this->filter['related_activities'] = 'true';
return $this;
}
/**
* Don't apply the Activity filter to Sub-Statements.
*/
public function disableRelatedActivityFilter(): self
{
$this->filter['related_activities'] = 'false';
return $this;
}
/**
* Applies the Agent filter to Sub-Statements.
*/
public function enableRelatedAgentFilter(): self
{
$this->filter['related_agents'] = 'true';
return $this;
}
/**
* Don't apply the Agent filter to Sub-Statements.
*/
public function disableRelatedAgentFilter(): self
{
$this->filter['related_agents'] = 'false';
return $this;
}
/**
* Filters for Statements stored since the specified timestamp (exclusive).
*/
public function since(\DateTime $timestamp): self
{
$this->filter['since'] = $timestamp->format('c');
return $this;
}
/**
* Filters for Statements stored at or before the specified timestamp.
*/
public function until(\DateTime $timestamp): self
{
$this->filter['until'] = $timestamp->format('c');
return $this;
}
/**
* Sets the maximum number of Statements to return. The server side sets
* the maximum number of results when this value is not set or when it is 0.
*
* @throws \InvalidArgumentException if the limit is not a non-negative
* integer
*/
public function limit(int $limit): self
{
if ($limit < 0) {
throw new \InvalidArgumentException('Limit must be a non-negative integer');
}
$this->filter['limit'] = $limit;
return $this;
}
/**
* Return statements in ascending order of stored time.
*/
public function ascending(): self
{
$this->filter['ascending'] = 'true';
return $this;
}
/**
*Return statements in descending order of stored time (the default behavior).
*/
public function descending(): self
{
$this->filter['ascending'] = 'false';
return $this;
}
/**
* Returns the generated filter.
*/
public function getFilter(): array
{
return $this->filter;
}
}

View File

@@ -0,0 +1,235 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* A {@link Statement} included as part of a parent Statement.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class SubStatement extends StatementObject
{
private $verb;
private $actor;
private $object;
private $result;
private $created;
private $context;
private $attachments;
/**
* @param Attachment[]|null $attachments
*/
public function __construct(Actor $actor, Verb $verb, StatementObject $object, Result $result = null, Context $context = null, \DateTime $created = null, array $attachments = null)
{
if ($object instanceof SubStatement) {
throw new \InvalidArgumentException('Nesting sub statements is forbidden by the xAPI spec.');
}
$this->actor = $actor;
$this->verb = $verb;
$this->object = $object;
$this->result = $result;
$this->created = $created;
$this->context = $context;
$this->attachments = null !== $attachments ? array_values($attachments) : null;
}
public function withActor(Actor $actor): self
{
$subStatement = clone $this;
$subStatement->actor = $actor;
return $subStatement;
}
public function withVerb(Verb $verb): self
{
$subStatement = clone $this;
$subStatement->verb = $verb;
return $subStatement;
}
public function withObject(StatementObject $object): self
{
$subStatement = clone $this;
$subStatement->object = $object;
return $subStatement;
}
public function withResult(Result $result): self
{
$subStatement = clone $this;
$subStatement->result = $result;
return $subStatement;
}
public function withCreated(\DateTime $created = null): self
{
$statement = clone $this;
$statement->created = $created;
return $statement;
}
public function withContext(Context $context): self
{
$subStatement = clone $this;
$subStatement->context = $context;
return $subStatement;
}
/**
* @param Attachment[]|null $attachments
*/
public function withAttachments(array $attachments = null): self
{
$statement = clone $this;
$statement->attachments = null !== $attachments ? array_values($attachments) : null;
return $statement;
}
/**
* Returns the Statement's {@link Verb}.
*/
public function getVerb(): Verb
{
return $this->verb;
}
/**
* Returns the Statement's {@link Actor}.
*/
public function getActor(): Actor
{
return $this->actor;
}
/**
* Returns the Statement's {@link StatementObject}.
*/
public function getObject(): StatementObject
{
return $this->object;
}
/**
* Returns the {@link Activity} {@link Result}.
*/
public function getResult(): ?Result
{
return $this->result;
}
/**
* Returns the timestamp of when the events described in this statement
* occurred.
*/
public function getCreated(): ?\DateTime
{
return $this->created;
}
/**
* Returns the {@link Statement} {@link Context}.
*/
public function getContext(): ?Context
{
return $this->context;
}
/**
* @return Attachment[]|null
*/
public function getAttachments(): ?array
{
return $this->attachments;
}
/**
* Tests whether or not this Statement is a void Statement (i.e. it voids
* another Statement).
*/
public function isVoidStatement(): bool
{
return $this->verb->isVoidVerb();
}
/**
* {@inheritdoc}
*/
public function equals(StatementObject $statement): bool
{
if (!$statement instanceof SubStatement) {
return false;
}
if (!$this->actor->equals($statement->actor)) {
return false;
}
if (!$this->verb->equals($statement->verb)) {
return false;
}
if (!$this->object->equals($statement->object)) {
return false;
}
if (null === $this->result && null !== $statement->result) {
return false;
}
if (null !== $this->result && null === $statement->result) {
return false;
}
if (null !== $this->result && !$this->result->equals($statement->result)) {
return false;
}
if ($this->created != $statement->created) {
return false;
}
if (null !== $this->context xor null !== $statement->context) {
return false;
}
if (null !== $this->context && null !== $statement->context && !$this->context->equals($statement->context)) {
return false;
}
if (null !== $this->attachments xor null !== $statement->attachments) {
return false;
}
if (null !== $this->attachments && null !== $statement->attachments) {
if (count($this->attachments) !== count($statement->attachments)) {
return false;
}
foreach ($this->attachments as $key => $attachment) {
if (!$attachment->equals($statement->attachments[$key])) {
return false;
}
}
}
return true;
}
}

112
vendor/php-xapi/model/src/Uuid.php vendored Normal file
View File

@@ -0,0 +1,112 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
use Ramsey\Uuid\Uuid as RamseyUuid;
use Rhumsaa\Uuid\Uuid as RhumsaaUuid;
/**
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
final class Uuid
{
/**
* @var RamseyUuid|RhumsaaUuid;
*/
private $uuid;
private function __construct($uuid)
{
$this->uuid = $uuid;
}
public static function fromString(string $uuid): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::fromString($uuid));
}
return new self(RamseyUuid::fromString($uuid));
}
/**
* Generate a version 1 UUID from a host ID, sequence number, and the current time.
*
* @param int|string $node a 48-bit number representing the hardware address
* This number may be represented as an integer or a hexadecimal string
* @param int $clockSeq a 14-bit number used to help avoid duplicates that
* could arise when the clock is set backwards in time or if the node ID
* changes
*/
public static function uuid1($node = null, int $clockSeq = null): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid1($node, $clockSeq));
}
return new self(RamseyUuid::uuid1($node, $clockSeq));
}
/**
* Generate a version 3 UUID based on the MD5 hash of a namespace identifier
* (which is a UUID) and a name (which is a string).
*
* @param string $ns The UUID namespace in which to create the named UUID
* @param string $name The name to create a UUID for
*/
public static function uuid3(string $ns, string $name): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid3($ns, $name));
}
return new self(RamseyUuid::uuid3($ns, $name));
}
/**
* Generate a version 4 (random) UUID.
*/
public static function uuid4(): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid4());
}
return new self(RamseyUuid::uuid4());
}
/**
* Generate a version 5 UUID based on the SHA-1 hash of a namespace
* identifier (which is a UUID) and a name (which is a string).
*
* @param string $ns The UUID namespace in which to create the named UUID
* @param string $name The name to create a UUID for
*/
public static function uuid5(string $ns, string $name): self
{
if (class_exists(RhumsaaUuid::class)) {
return new self(RhumsaaUuid::uuid5($ns, $name));
}
return new self(RamseyUuid::uuid5($ns, $name));
}
public function __toString(): string
{
return $this->uuid->toString();
}
public function equals(Uuid $uuid): bool
{
return $this->uuid->equals($uuid->uuid);
}
}

97
vendor/php-xapi/model/src/Verb.php vendored Normal file
View File

@@ -0,0 +1,97 @@
<?php
/*
* This file is part of the xAPI package.
*
* (c) Christian Flothmann <christian.flothmann@xabbuh.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Xabbuh\XApi\Model;
/**
* The verb in a {@link Statement}.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
final class Verb
{
private $id;
private $display;
public function __construct(IRI $id, LanguageMap $display = null)
{
$this->id = $id;
$this->display = $display;
}
/**
* Returns the verb definition reference.
*/
public function getId(): IRI
{
return $this->id;
}
/**
* Returns the human readable representation of the Verb in one or more languages.
*/
public function getDisplay(): ?LanguageMap
{
return $this->display;
}
/**
* Checks if another verb is equal.
*
* Two verbs are equal if and only if all of their properties are equal.
*/
public function equals(Verb $verb): bool
{
if (!$this->id->equals($verb->id)) {
return false;
}
if (null === $this->display && null === $verb->display) {
return true;
}
if (null !== $this->display xor null !== $verb->display) {
return false;
}
if (count($this->display) !== count($verb->getDisplay())) {
return false;
}
foreach ($this->display as $language => $value) {
if (!isset($verb->display[$language])) {
return false;
}
if ($value !== $verb->display[$language]) {
return false;
}
}
return true;
}
/**
* Tests if the Verb can be used to void a Statement.
*/
public function isVoidVerb(): bool
{
return $this->id->equals(IRI::fromString('http://adlnet.gov/expapi/verbs/voided'));
}
/**
* Creates a Verb that can be used to void a {@link Statement}.
*/
public static function createVoidVerb(): self
{
return new Verb(IRI::fromString('http://adlnet.gov/expapi/verbs/voided'));
}
}