-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bare minimum capable of sending statements
- Loading branch information
1 parent
cf31a1f
commit 9cd4479
Showing
22 changed files
with
1,299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
A PHP library for implementing Tin Can API. | ||
|
||
http://tincanapi.com/ | ||
|
||
Requires PHP 5.4 or later. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
date_default_timezone_set('UTC'); | ||
|
||
require_once('tests/Constants.php'); | ||
|
||
require_once('src/LRSInterface.php'); | ||
require_once('src/StatementTargetInterface.php'); | ||
require_once('src/VersionableInterface.php'); | ||
|
||
require_once('src/FromJSONTrait.php'); | ||
|
||
require_once('src/Util.php'); | ||
require_once('src/Version.php'); | ||
require_once('src/Activity.php'); | ||
require_once('src/Agent.php'); | ||
require_once('src/Verb.php'); | ||
require_once('src/Statement.php'); | ||
require_once('src/RemoteLRS.php'); | ||
|
||
register_shutdown_function( | ||
function () { | ||
if ($err = error_get_last()) { | ||
print "\n\nNon-exception error occurred:\n\n"; | ||
print $err['type'] . ": " . $err['message'] . "\n"; | ||
print $err['file'] . " (" . $err['line'] . ")\n\n"; | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="phpunit.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false" | ||
> | ||
<testsuites> | ||
<testsuite name="TinCanPHP Test Suite"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist addUncoveredFilesFromWhitelist="false"> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/* | ||
Copyright 2014 Rustici Software | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
namespace TinCan; | ||
|
||
class Activity implements VersionableInterface, StatementTargetInterface { | ||
use FromJSONTrait; | ||
private $objectType = 'Activity'; | ||
|
||
protected $id; | ||
protected $definition; | ||
|
||
public function __construct() { | ||
if (func_num_args() == 1) { | ||
$arg = func_get_arg(0); | ||
|
||
if (isset($arg['id'])) { | ||
$this->setId($arg['id']); | ||
} | ||
if (isset($arg['definition'])) { | ||
$this->setDefinition($arg['definition']); | ||
} | ||
} | ||
} | ||
|
||
public function asVersion($version) { | ||
$result = array( | ||
'objectType' => $this->objectType | ||
); | ||
if (isset($this->id)) { | ||
$result['id'] = $this->id; | ||
} | ||
if (isset($this->definition)) { | ||
$result['definition'] = $this->definition; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function getObjectType() { return $this->objectType; } | ||
|
||
// FEATURE: check IRI? | ||
public function setId($value) { $this->id = $value; return $this; } | ||
public function getId() { return $this->id; } | ||
|
||
public function setDefinition($value) { $this->definition = $value; return $this; } | ||
public function getDefinition() { return $this->definition; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/* | ||
Copyright 2014 Rustici Software | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
namespace TinCan; | ||
|
||
class Agent implements VersionableInterface, StatementTargetInterface { | ||
use FromJSONTrait; | ||
private $objectType = 'Agent'; | ||
|
||
protected $name; | ||
protected $mbox; | ||
protected $mbox_sha1sum; | ||
protected $openid; | ||
protected $account; | ||
|
||
public function __construct() { | ||
if (func_num_args() == 1) { | ||
$arg = func_get_arg(0); | ||
|
||
if (isset($arg['name'])) { | ||
$this->setName($arg['name']); | ||
} | ||
if (isset($arg['mbox'])) { | ||
$this->setMbox($arg['mbox']); | ||
} | ||
} | ||
} | ||
|
||
public function asVersion($version) { | ||
$result = array( | ||
'objectType' => $this->objectType | ||
); | ||
|
||
if (isset($this->name)) { | ||
$result['name'] = $this->name; | ||
} | ||
if (isset($this->mbox)) { | ||
$result['mbox'] = $this->mbox; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function getObjectType() { return $this->objectType; } | ||
|
||
public function setName($value) { $this->name = $value; return $this; } | ||
public function getName() { return $this->name; } | ||
|
||
// TODO: prepend 'mailto:' when not present | ||
public function setMbox($value) { $this->mbox = $value; return $this; } | ||
public function getMbox() { return $this->mbox; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/* | ||
Copyright 2014 Rustici Software | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
namespace TinCan; | ||
|
||
trait FromJSONTrait { | ||
static public function fromJSON($jsonStr) { | ||
// | ||
// 2nd arg as true means return value is an assoc. array rather than object | ||
// | ||
$cfg = json_decode($jsonStr, true); | ||
|
||
if (is_null($cfg)) { | ||
$err = json_last_error(); | ||
throw new \InvalidArgumentException("Invalid JSON: $err"); | ||
} | ||
return new self($cfg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/* | ||
Copyright 2014 Rustici Software | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
namespace TinCan; | ||
|
||
interface LRSInterface { | ||
public function about(); | ||
|
||
public function saveStatement($statement); | ||
public function saveStatements($statements); | ||
public function retrieveStatement($id); | ||
public function retrieveVoidedStatement($id); | ||
public function queryStatements($query); | ||
public function moreStatements($moreURL); | ||
|
||
public function retrieveStateKeys(); | ||
public function retrieveState(); | ||
public function saveState(); | ||
public function deleteState(); | ||
|
||
public function retrieveActivityProfileKeys(); | ||
public function retrieveActivityProfile(); | ||
public function saveActivityProfile(); | ||
public function deleteActivityProfile(); | ||
|
||
public function retrieveAgentProfileKeys(); | ||
public function retrieveAgentProfile(); | ||
public function saveAgentProfile(); | ||
public function deleteAgentProfile(); | ||
} |
Oops, something went wrong.