Skip to content

Commit

Permalink
Bare minimum capable of sending statements
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjmiller committed Mar 1, 2014
1 parent cf31a1f commit 9cd4479
Show file tree
Hide file tree
Showing 22 changed files with 1,299 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
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.
29 changes: 29 additions & 0 deletions phpunit.php
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";
}
}
);
25 changes: 25 additions & 0 deletions phpunit.xml
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>
62 changes: 62 additions & 0 deletions src/Activity.php
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; }
}
66 changes: 66 additions & 0 deletions src/Agent.php
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; }
}
33 changes: 33 additions & 0 deletions src/FromJSONTrait.php
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);
}
}
44 changes: 44 additions & 0 deletions src/LRSInterface.php
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();
}
Loading

0 comments on commit 9cd4479

Please sign in to comment.