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

View File

@@ -0,0 +1,3 @@
/composer.lock
/phpunit.xml
/vendor

View File

@@ -0,0 +1,22 @@
language: php
cache:
directories:
- $HOME/.composer/cache/files
matrix:
include:
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
fast_finish: true
install:
- composer install
script:
- find -name '*.php' -not -path './vendor/*' -name '*.php' | xargs -n1 php -l

View File

@@ -0,0 +1,26 @@
<?php
namespace XApi\Repository\Api;
use Xabbuh\XApi\Common\Exception\NotFoundException;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\IRI;
/**
* Public API of an Experience API (xAPI) {@link Activity} repository.
*
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
interface ActivityRepositoryInterface
{
/**
* Finds an {@link Activity} by id.
*
* @param IRI $activityId The activity id to filter by
*
* @return Activity The activity
*
* @throws NotFoundException if no Activity with the given IRI does exist
*/
public function findActivityById(IRI $activityId);
}

View File

@@ -0,0 +1,77 @@
CHANGELOG
=========
0.4.0
-----
* dropped suppport for PHP < 5.6 and HHVM
* made the package compatible with `3.x` releases of `ramsey/uuid`
* allow `2.x` and `3.x` releases of the `php-xapi/model` package too
* added an `ActivityRepositoryInterface` that defines the public API of
an activity repository
0.3.1
-----
* allow `3.x` releases of `ramsey/uuid`
* fix compatibility with PHPUnit 6+
0.3.0
-----
* Removed the `MappedStatement` and `MappedVerb` classes. They are needed
for Doctrine based implementations and thus have been moved to the
`php-xapi/repository-doctrine` package. Consequently, the `StatementRepository`
class has been removed too. You now have to implement the `StatementRepositoryInterface`
and handle `Statement` classes directly instead.
* Removed the `NotFoundException` in favor of the exception with the same
name from the `php-xapi/exception` package.
* The public API now uses `StatementId` instances instead of strings to carry
information about statement ids. This means changes to the following methods:
* `StatementRepositoryInterface::findStatementById()`: The `$statementId`
argument is now type hinted with `StatementId`.
* `StatementRepositoryInterface::findVoidedStatementById()`: The `$voidedStatementId`
argument is now type hinted with `StatementId`.
* `StatementRepositoryInterface::storeStatement()`: The method returns a
`StatementId` instance instead of a string.
* Added a `StatementRepositoryInterface` that defines the public API of a
statement repository. You can still extend the base `StatementRepository`
class or provide your own implementation of this new interface.
* The requirements for `php-xapi/model` and `php-xapi/test-fixtures` have
been bumped to `^1.0` to make use of their stable releases.
0.2.0
-----
* changed base namespace of all classes from `Xabbuh\XApi\Storage\Api` to
`XApi\Repository\Api`
0.1.2
-----
Do not allow to pull in packages that could potentially break backwards
compatibility.
0.1.1
-----
Moved `php-xapi/test-fixtures` package to the `require` section as the package
is required by other packages that make use of the base test class.
0.1.0
-----
First release defining a common interface for LRS repository backends.
This package replaces the `xabbuh/xapi-storage-api` package which is now
deprecated and should no longer be used.

19
vendor/php-xapi/repository-api/LICENSE vendored Normal file
View File

@@ -0,0 +1,19 @@
Copyright (c) 2014-2020 Christian Flothmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,7 @@
Common API for Experience API Repository Implementations
========================================================
[![Build Status](https://travis-ci.org/php-xapi/repository-api.svg?branch=master)](https://travis-ci.org/php-xapi/repository-api)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/php-xapi/repository-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/php-xapi/repository-api/?branch=master)
This package defines a common interface for various xAPI repository backends.

View File

@@ -0,0 +1,69 @@
<?php
namespace XApi\Repository\Api;
use Xabbuh\XApi\Common\Exception\NotFoundException;
use Xabbuh\XApi\Model\Actor;
use Xabbuh\XApi\Model\Statement;
use Xabbuh\XApi\Model\StatementId;
use Xabbuh\XApi\Model\StatementsFilter;
/**
* Public API of an Experience API (xAPI) {@link Statement} repository.
*
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
interface StatementRepositoryInterface
{
/**
* Finds a {@link Statement} by id.
*
* @param StatementId $statementId The statement id to filter by
* @param Actor|null $authority (Optional) actor that must be the authority
* of the returned statement
*
* @return Statement The statement
*
* @throws NotFoundException if no Statement with the given UUID does exist
*/
public function findStatementById(StatementId $statementId, Actor $authority = null);
/**
* Finds a voided {@link Statement} by id.
*
* @param StatementId $voidedStatementId The voided statement id to filter
* by
* @param Actor|null $authority (Optional) actor that must be the
* authority of the returned statement
*
* @return Statement The statement
*
* @throws NotFoundException if no voided Statement with the given UUID
* does exist
*/
public function findVoidedStatementById(StatementId $voidedStatementId, Actor $authority = null);
/**
* Finds a collection of {@link Statement Statements} filtered by the given
* criteria.
*
* @param StatementsFilter $criteria The criteria to filter by
* @param Actor|null $authority (Optional) actor that must be the
* authority of the returned statements
*
* @return Statement[] The statements
*/
public function findStatementsBy(StatementsFilter $criteria, Actor $authority = null);
/**
* Writes a {@link Statement} to the underlying data storage.
*
* @param Statement $statement The statement to store
* @param bool $flush Whether or not to flush the managed objects
* immediately (i.e. write them to the data
* storage)
*
* @return StatementId The id of the created Statement
*/
public function storeStatement(Statement $statement, $flush = true);
}

View File

@@ -0,0 +1,76 @@
<?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 XApi\Repository\Api\Test\Functional;
use PHPUnit\Framework\TestCase;
use Xabbuh\XApi\Model\Activity;
use Xabbuh\XApi\Model\IRI;
use XApi\Repository\Api\ActivityRepositoryInterface;
/**
* @author Jérôme Parmentier <jerome.parmentier@acensi.fr>
*/
abstract class ActivityRepositoryTest extends TestCase
{
/**
* @var ActivityRepositoryInterface
*/
private $activityRepository;
protected function setUp()
{
$this->activityRepository = $this->createActivityRepository();
$this->cleanDatabase();
}
protected function tearDown()
{
$this->cleanDatabase();
}
/**
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
*/
public function testFetchingNonExistingActivityThrowsException()
{
$this->activityRepository->findActivityById(IRI::fromString('not-existing'));
}
/**
* @dataProvider getStatementsWithId
*/
public function testActivitiesCanBeRetrievedById(Activity $activity)
{
$fetchedActivity = $this->activityRepository->findActivityById($activity->getId());
$this->assertTrue($activity->equals($fetchedActivity));
}
public function getActivitiesWithId()
{
$fixtures = array();
foreach (get_class_methods('Xabbuh\XApi\DataFixtures\ActivityFixtures') as $method) {
$activity = call_user_func(array('Xabbuh\XApi\DataFixtures\ActivityFixtures', $method));
if ($activity instanceof Activity) {
$fixtures[$method] = array($activity);
}
}
return $fixtures;
}
abstract protected function createActivityRepository();
abstract protected function cleanDatabase();
}

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 XApi\Repository\Api\Test\Functional;
use PHPUnit\Framework\TestCase;
use Xabbuh\XApi\DataFixtures\StatementFixtures;
use Xabbuh\XApi\Model\Statement;
use Xabbuh\XApi\Model\StatementId;
use XApi\Repository\Api\StatementRepository;
/**
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
*/
abstract class StatementRepositoryTest extends TestCase
{
const UUID_REGEXP = '/^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/i';
/**
* @var StatementRepository
*/
private $statementRepository;
protected function setUp()
{
$this->statementRepository = $this->createStatementRepository();
$this->cleanDatabase();
}
protected function tearDown()
{
$this->cleanDatabase();
}
/**
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
*/
public function testFetchingNonExistingStatementThrowsException()
{
$this->statementRepository->findStatementById(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
}
/**
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
*/
public function testFetchingStatementAsVoidedStatementThrowsException()
{
$statement = StatementFixtures::getTypicalStatement()->withId(null);
$statementId = $this->statementRepository->storeStatement($statement);
$this->statementRepository->findVoidedStatementById($statementId);
}
/**
* @dataProvider getStatementsWithoutId
*/
public function testUuidIsGeneratedForNewStatementIfNotPresent(Statement $statement)
{
$statement = $statement->withId(null);
$statementId = $this->statementRepository->storeStatement($statement);
$this->assertNull($statement->getId());
$this->assertRegExp(self::UUID_REGEXP, $statementId->getValue());
}
/**
* @dataProvider getStatementsWithId
*/
public function testUuidIsNotGeneratedForNewStatementIfPresent(Statement $statement)
{
$statementId = $this->statementRepository->storeStatement($statement);
$this->assertEquals($statement->getId(), $statementId);
}
/**
* @dataProvider getStatementsWithId
*/
public function testCreatedStatementCanBeRetrievedByOriginalId(Statement $statement)
{
$this->statementRepository->storeStatement($statement);
if ($statement->getVerb()->isVoidVerb()) {
$fetchedStatement = $this->statementRepository->findVoidedStatementById($statement->getId());
} else {
$fetchedStatement = $this->statementRepository->findStatementById($statement->getId());
}
$this->assertTrue($statement->equals($fetchedStatement));
}
/**
* @dataProvider getStatementsWithoutId
*/
public function testCreatedStatementCanBeRetrievedByGeneratedId(Statement $statement)
{
$statement =$statement->withId(null);
$statementId = $this->statementRepository->storeStatement($statement);
if ($statement->getVerb()->isVoidVerb()) {
$fetchedStatement = $this->statementRepository->findVoidedStatementById($statementId);
} else {
$fetchedStatement = $this->statementRepository->findStatementById($statementId);
}
$this->assertNull($statement->getId());
$this->assertTrue($statement->equals($fetchedStatement->withId(null)));
}
public function getStatementsWithId()
{
$fixtures = array();
foreach (get_class_methods('Xabbuh\XApi\DataFixtures\StatementFixtures') as $method) {
$statement = call_user_func(array('Xabbuh\XApi\DataFixtures\StatementFixtures', $method));
if ($statement instanceof Statement) {
$fixtures[$method] = array($statement->withId(StatementId::fromString(StatementFixtures::DEFAULT_STATEMENT_ID)));
}
}
return $fixtures;
}
public function getStatementsWithoutId()
{
$fixtures = array();
foreach (get_class_methods('Xabbuh\XApi\DataFixtures\StatementFixtures') as $method) {
$statement = call_user_func(array('Xabbuh\XApi\DataFixtures\StatementFixtures', $method));
if ($statement instanceof Statement) {
$fixtures[$method] = array($statement->withId(null));
}
}
return $fixtures;
}
/**
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
*/
public function testFetchingNonExistingVoidStatementThrowsException()
{
$this->statementRepository->findVoidedStatementById(StatementId::fromString('12345678-1234-5678-8234-567812345678'));
}
/**
* @expectedException \Xabbuh\XApi\Common\Exception\NotFoundException
*/
public function testFetchingVoidStatementAsStatementThrowsException()
{
$statement = StatementFixtures::getVoidingStatement()->withId(null);
$statementId = $this->statementRepository->storeStatement($statement);
$this->statementRepository->findStatementById($statementId);
}
public function testUuidIsGeneratedForNewVoidStatementIfNotPresent()
{
$statement = StatementFixtures::getVoidingStatement()->withId(null);
$statementId = $this->statementRepository->storeStatement($statement);
$this->assertNull($statement->getId());
$this->assertRegExp(self::UUID_REGEXP, $statementId->getValue());
}
public function testUuidIsNotGeneratedForNewVoidStatementIfPresent()
{
$statement = StatementFixtures::getVoidingStatement();
$statementId = $this->statementRepository->storeStatement($statement);
$this->assertEquals($statement->getId(), $statementId);
}
public function testCreatedVoidStatementCanBeRetrievedByOriginalId()
{
$statement = StatementFixtures::getVoidingStatement();
$this->statementRepository->storeStatement($statement);
$fetchedStatement = $this->statementRepository->findVoidedStatementById($statement->getId());
$this->assertTrue($statement->equals($fetchedStatement));
}
public function testCreatedVoidStatementCanBeRetrievedByGeneratedId()
{
$statement = StatementFixtures::getVoidingStatement()->withId(null);
$statementId = $this->statementRepository->storeStatement($statement);
$fetchedStatement = $this->statementRepository->findVoidedStatementById($statementId);
$this->assertNull($statement->getId());
$this->assertTrue($statement->equals($fetchedStatement->withId(null)));
}
abstract protected function createStatementRepository();
abstract protected function cleanDatabase();
}

View File

@@ -0,0 +1,35 @@
UPGRADE
=======
Upgrading from 0.2 to 0.3
-------------------------
* Removed the `MappedStatement` and `MappedVerb` classes. They are needed
for Doctrine based implementations and thus have been moved to the
`php-xapi/repository-doctrine` package. Consequently, the `StatementRepository`
class has been removed too. You now have to implement the `StatementRepositoryInterface`
and handle `Statement` classes directly instead.
* Removed the `NotFoundException` in favor of the exception with the same
name from the `php-xapi/exception` package.
* The public API now uses `StatementId` instances instead of strings to carry
information about statement ids. This means changes to the following methods:
* `StatementRepositoryInterface::findStatementById()`: The `$statementId`
argument is now type hinted with `StatementId`.
* `StatementRepositoryInterface::findVoidedStatementById()`: The `$voidedStatementId`
argument is now type hinted with `StatementId`.
* `StatementRepositoryInterface::storeStatement()`: The method returns a
`StatementId` instance instead of a string.
* The requirements for `php-xapi/model` and `php-xapi/test-fixtures` have
been bumped to `^1.0` to make use of their stable releases.
Upgrading from 0.1 to 0.2
-------------------------
The base namespace of all classes was changed from `Xabbuh\XApi\Storage\Api` to
`XApi\Repository\Api`.

View File

@@ -0,0 +1,33 @@
{
"name": "php-xapi/repository-api",
"description": "abstract definition of an xAPI repository interface",
"keywords": ["xAPI", "Tin Can API", "Experience API", "storage", "database", "repository"],
"homepage": "https://github.com/php-xapi/repository-api",
"license": "MIT",
"authors": [
{
"name": "Christian Flothmann",
"homepage": "https://github.com/xabbuh"
}
],
"require": {
"php": "^5.6 || ^7.0",
"ramsey/uuid": "^2.8 || ^3.0",
"php-xapi/model": "^1.1 || ^2.0 || ^3.0",
"php-xapi/test-fixtures": "^1.0"
},
"minimum-stability": "dev",
"conflict": {
"xabbuh/xapi-storage-api": "*"
},
"autoload": {
"psr-4": {
"XApi\\Repository\\Api\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "0.4.x-dev"
}
}
}