Skip to content

Commit bf01796

Browse files
committed
Merge branch '2.x'
* 2.x: update year in license fix typo bump version for removal of deprecated features fix Travis CI job update changelog bump version for removal of deprecated features drop build job for HHVM [#47] add changelog entry Add a StateDocumentsFilter class Deprecate constructing State with anything other than Agent as 2nd argument [#60] remove unneeded docblocks Introduce a new Person class add spec test to not use version when comparing Conflicts: .travis.yml CHANGELOG.md src/State.php
2 parents 1544c68 + 7a780ea commit bf01796

File tree

9 files changed

+432
-3
lines changed

9 files changed

+432
-3
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ CHANGELOG
1616
* The `Object` class was renamed to `StatementObject` for compatibility with PHP
1717
7.2.
1818

19+
2.2.0
20+
-----
21+
22+
* Introduce a new `Person` class.
23+
* Constructing a `State` object with an instance of any child class of `Actor`
24+
other than `Agent` as the second argument is deprecated. Starting with `4.0`,
25+
only instances of `Agent` will be accepted.
26+
* The `State::getActor()` method is deprecated and will be removed in `4.0`.
27+
Use `State::getAgent()` instead.
28+
* Added a `StateDocumentsFilter` class that allows to draft filters for
29+
`StateDocument` objects.
30+
1931
2.1.0
2032
-----
2133

@@ -55,6 +67,14 @@ CHANGELOG
5567
3.0. Use `SubStatement::getCreated()` instead.
5668
* The `SubStatement::withTimestamp()` method is deprecated and will be removed in
5769
3.0. Use `SubStatement::withCreated()` instead.
70+
* Introduce a new `Person` class.
71+
* Constructing a `State` object with an instance of any child class of `Actor`
72+
other than `Agent` as the second argument is deprecated. Starting with `4.0`,
73+
only instances of `Agent` will be accepted.
74+
* The `State::getActor()` method is deprecated and will be removed in `4.0`.
75+
Use `State::getAgent()` instead.
76+
* Added a `StateDocumentsFilter` class that allows to draft filters for
77+
`StateDocument` objects.
5878

5979
1.1.1
6080
-----

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014-2017 Christian Flothmann
1+
Copyright (c) 2014-2018 Christian Flothmann
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

spec/PersonSpec.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace spec\Xabbuh\XApi\Model;
13+
14+
use PhpSpec\ObjectBehavior;
15+
use Xabbuh\XApi\Model\Account;
16+
use Xabbuh\XApi\Model\Agent;
17+
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
18+
use Xabbuh\XApi\Model\IRI;
19+
use Xabbuh\XApi\Model\IRL;
20+
21+
class PersonSpec extends ObjectBehavior
22+
{
23+
function it_can_be_built_from_an_array_of_agents()
24+
{
25+
$agents = array(
26+
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]'))),
27+
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]'))),
28+
);
29+
30+
$this->beConstructedThrough('createFromAgents', array($agents));
31+
32+
$this->shouldHaveType('Xabbuh\XApi\Model\Person');
33+
}
34+
35+
function it_has_mboxes_from_agents()
36+
{
37+
$mbox = IRI::fromString('mailto:[email protected]');
38+
$mbox2 = IRI::fromString('mailto:[email protected]');
39+
$agents = array(
40+
new Agent(InverseFunctionalIdentifier::withMbox($mbox)),
41+
new Agent(InverseFunctionalIdentifier::withMbox($mbox2)),
42+
);
43+
44+
$this->beConstructedThrough('createFromAgents', array($agents));
45+
46+
$this->getMboxes()->shouldReturn(array(
47+
$mbox,
48+
$mbox2,
49+
));
50+
}
51+
52+
function it_has_mbox_sha_1_sums_from_agents()
53+
{
54+
$sha1Sum = 'sha1Sum';
55+
$sha1Sum2 = 'sha1Sum2';
56+
$agents = array(
57+
new Agent(InverseFunctionalIdentifier::withMboxSha1Sum($sha1Sum)),
58+
new Agent(InverseFunctionalIdentifier::withMboxSha1Sum($sha1Sum2)),
59+
);
60+
61+
$this->beConstructedThrough('createFromAgents', array($agents));
62+
63+
$this->getMboxSha1Sums()->shouldReturn(array(
64+
$sha1Sum,
65+
$sha1Sum2,
66+
));
67+
}
68+
69+
function it_has_open_ids_from_agents()
70+
{
71+
$openId = 'openId';
72+
$openId2 = 'openId2';
73+
$agents = array(
74+
new Agent(InverseFunctionalIdentifier::withOpenId($openId)),
75+
new Agent(InverseFunctionalIdentifier::withOpenId($openId2)),
76+
);
77+
78+
$this->beConstructedThrough('createFromAgents', array($agents));
79+
80+
$this->getOpenIds()->shouldReturn(array(
81+
$openId,
82+
$openId2,
83+
));
84+
}
85+
86+
function it_has_accounts_from_agents()
87+
{
88+
$account = new Account('test', IRL::fromString('http://example.com'));
89+
$account2 = new Account('test2', IRL::fromString('http://example.com'));
90+
$agents = array(
91+
new Agent(InverseFunctionalIdentifier::withAccount($account)),
92+
new Agent(InverseFunctionalIdentifier::withAccount($account2)),
93+
);
94+
95+
$this->beConstructedThrough('createFromAgents', array($agents));
96+
97+
$this->getAccounts()->shouldReturn(array(
98+
$account,
99+
$account2,
100+
));
101+
}
102+
103+
function it_has_names_from_agents()
104+
{
105+
$name = 'name';
106+
$name2 = 'name2';
107+
$agents = array(
108+
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]')), $name),
109+
new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]')), $name2),
110+
);
111+
112+
$this->beConstructedThrough('createFromAgents', array($agents));
113+
114+
$this->getNames()->shouldReturn(array(
115+
$name,
116+
$name2,
117+
));
118+
}
119+
}

spec/StateDocumentSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class StateDocumentSpec extends ObjectBehavior
2525
function let()
2626
{
2727
$activity = new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid'));
28-
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]')));
29-
$this->beConstructedWith(new State($activity, $actor, 'state-id'), new DocumentData(array(
28+
$agent = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]')));
29+
$this->beConstructedWith(new State($activity, $agent, 'state-id'), new DocumentData(array(
3030
'x' => 'foo',
3131
'y' => 'bar',
3232
)));

spec/StateDocumentsFilterSpec.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace spec\Xabbuh\XApi\Model;
13+
14+
use PhpSpec\ObjectBehavior;
15+
use Xabbuh\XApi\Model\Activity;
16+
use Xabbuh\XApi\Model\Agent;
17+
use Xabbuh\XApi\Model\InverseFunctionalIdentifier;
18+
use Xabbuh\XApi\Model\IRI;
19+
use Xabbuh\XApi\Model\LanguageMap;
20+
use Xabbuh\XApi\Model\Verb;
21+
22+
class StateDocumentsFilterSpec extends ObjectBehavior
23+
{
24+
function it_does_not_filter_anything_by_default()
25+
{
26+
$filter = $this->getFilter();
27+
$filter->shouldHaveCount(0);
28+
}
29+
30+
function it_can_filter_by_activity()
31+
{
32+
$this->byActivity(new Activity(IRI::fromString('http://tincanapi.com/conformancetest/activityid')))->shouldReturn($this);
33+
34+
$filter = $this->getFilter();
35+
$filter->shouldHaveCount(1);
36+
$filter->shouldHaveKeyWithValue('activity', 'http://tincanapi.com/conformancetest/activityid');
37+
}
38+
39+
function it_can_filter_by_agent()
40+
{
41+
$actor = new Agent(InverseFunctionalIdentifier::withMbox(IRI::fromString('mailto:[email protected]')));
42+
$this->byAgent($actor)->shouldReturn($this);
43+
44+
$filter = $this->getFilter();
45+
$filter->shouldHaveCount(1);
46+
$filter->shouldHaveKeyWithValue('agent', $actor);
47+
}
48+
49+
function it_can_filter_by_registration()
50+
{
51+
$this->byRegistration('foo')->shouldReturn($this);
52+
53+
$filter = $this->getFilter();
54+
$filter->shouldHaveCount(1);
55+
$filter->shouldHaveKeyWithValue('registration', 'foo');
56+
}
57+
58+
function it_can_filter_by_timestamp()
59+
{
60+
$this->since(\DateTime::createFromFormat(\DateTime::ISO8601, '2013-05-18T05:32:34Z'))->shouldReturn($this);
61+
$this->getFilter()->shouldHaveKeyWithValue('since', '2013-05-18T05:32:34+00:00');
62+
}
63+
}

spec/StatementSpec.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,12 @@ function it_is_not_equal_with_other_statement_if_attachments_differ()
388388

389389
$statement->equals($statement->withAttachments(array($jsonAttachment)))->shouldReturn(false);
390390
}
391+
392+
function it_is_equal_with_other_statement_even_if_versions_differ()
393+
{
394+
$statement = $this->withVersion('1.0.0');
395+
$otherStatement = $this->withVersion('1.0.1');
396+
397+
$statement->equals($otherStatement)->shouldReturn(true);
398+
}
391399
}

src/Person.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the xAPI package.
5+
*
6+
* (c) Christian Flothmann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Xabbuh\XApi\Model;
13+
14+
/**
15+
* Combined informations from multiple {@link Agent agents}.
16+
*
17+
* @author Jérôme Parmentier <[email protected]>
18+
*/
19+
final class Person
20+
{
21+
/**
22+
* @var string[] List of names of Agents
23+
*/
24+
private $names = array();
25+
26+
/**
27+
* @var IRI[] List of mailto IRIs of Agents
28+
*/
29+
private $mboxes = array();
30+
31+
/**
32+
* @var string[] List of the SHA1 hashes of mailto IRIs of Agents
33+
*/
34+
private $mboxSha1Sums = array();
35+
36+
/**
37+
* @var string[] List of openids that uniquely identify the Agents
38+
*/
39+
private $openIds = array();
40+
41+
/**
42+
* @var Account[] List of accounts of Agents
43+
*/
44+
private $accounts = array();
45+
46+
private function __construct()
47+
{
48+
}
49+
50+
/**
51+
* @param Agent[] $agents
52+
*
53+
* @return $this
54+
*/
55+
public static function createFromAgents(array $agents)
56+
{
57+
$person = new self();
58+
59+
foreach ($agents as $agent) {
60+
$iri = $agent->getInverseFunctionalIdentifier();
61+
62+
if (null !== $mbox = $iri->getMbox()) {
63+
$person->mboxes[] = $mbox;
64+
}
65+
66+
if (null !== $mboxSha1Sum = $iri->getMboxSha1Sum()) {
67+
$person->mboxSha1Sums[] = $mboxSha1Sum;
68+
}
69+
70+
if (null !== $openId = $iri->getOpenId()) {
71+
$person->openIds[] = $openId;
72+
}
73+
74+
if (null !== $account = $iri->getAccount()) {
75+
$person->accounts[] = $account;
76+
}
77+
78+
if (null !== $name = $agent->getName()) {
79+
$person->names[] = $name;
80+
}
81+
}
82+
83+
return $person;
84+
}
85+
86+
public function getNames()
87+
{
88+
return $this->names;
89+
}
90+
91+
public function getMboxes()
92+
{
93+
return $this->mboxes;
94+
}
95+
96+
public function getMboxSha1Sums()
97+
{
98+
return $this->mboxSha1Sums;
99+
}
100+
101+
public function getOpenIds()
102+
{
103+
return $this->openIds;
104+
}
105+
106+
public function getAccounts()
107+
{
108+
return $this->accounts;
109+
}
110+
}

src/State.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ final class State
2525

2626
public function __construct(Activity $activity, Actor $actor, string $stateId, string $registrationId = null)
2727
{
28+
if (!$actor instanceof Agent) {
29+
@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);
30+
}
31+
2832
$this->activity = $activity;
2933
$this->actor = $actor;
3034
$this->stateId = $stateId;
@@ -41,8 +45,22 @@ public function getActivity(): Activity
4145

4246
/**
4347
* Returns the actor.
48+
*
49+
* @deprecated since 1.2, to be removed in 4.0
4450
*/
4551
public function getActor(): Actor
52+
{
53+
@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);
54+
55+
return $this->getAgent();
56+
}
57+
58+
/**
59+
* Returns the agent.
60+
*
61+
* @return Actor The agent
62+
*/
63+
public function getAgent()
4664
{
4765
return $this->actor;
4866
}

0 commit comments

Comments
 (0)