Created
April 1, 2016 21:22
-
-
Save lsloan/8d454d5b865b9be03a13dbff0964445f to your computer and use it in GitHub Desktop.
PHP example of "use" keyword to shorten references' namespaces.
This file contains hidden or 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
<?php | |
use | |
IMS\Caliper\Client, | |
IMS\Caliper\Options, | |
IMS\Caliper\Sensor, | |
IMS\Caliper\actions\Action, | |
IMS\Caliper\entities\agent\Person, | |
IMS\Caliper\entities\agent\SoftwareApplication, | |
IMS\Caliper\entities\reading\EPubVolume, | |
IMS\Caliper\entities\reading\Frame, | |
IMS\Caliper\entities\session\Session, | |
IMS\Caliper\events\SessionEvent, | |
\Zzzzzzzzzz; | |
require_once realpath(dirname(__FILE__) . '/../vendor/autoload.php'); | |
class SessionEventSampleApp { | |
/** @var SessionEvent */ | |
private $sessionEvent; | |
/** @var Person */ | |
private $personEntity; | |
/** @return Person */ | |
public function getPersonEntity() { | |
return $this->personEntity; | |
} | |
/** @return SessionEvent */ | |
public function getSessionEvent() { | |
return $this->sessionEvent; | |
} | |
function setUp() { | |
$createdTime = new DateTime('1977-05-25T17:00:00.000Z'); | |
$modifiedTime = new DateTime('2015-06-24T19:48:00.000Z'); | |
$sessionStartTime = new DateTime('2015-12-18T11:38:00.000Z'); | |
$person = new Person('https://example.edu/user/poe_dameron'); | |
$person->setDateCreated($createdTime) | |
->setDateModified($modifiedTime); | |
$this->personEntity = $person; | |
$eventObj = new SoftwareApplication('https://example.com/viewer'); | |
$eventObj->setName('Holocron v7') | |
->setDateCreated($createdTime) | |
->setDateModified($modifiedTime); | |
$ePubVolume = new EPubVolume('https://example.com/viewer/book/1138#epubcfi(/4/3)'); | |
$ePubVolume->setName('Star Wars: The Magic of Myth') | |
->setDateCreated($createdTime) | |
->setDateModified($modifiedTime) | |
->setVersion('1st ed.'); | |
$targetObj = new Frame('https://example.com/viewer/book/1138#epubcfi(/4/3/1)'); | |
$targetObj->setName('The Resurgence of Evil') | |
->setDateCreated($createdTime) | |
->setDateModified($modifiedTime) | |
->setIsPartOf($ePubVolume) | |
->setIndex(1) | |
->setVersion('1st ed.'); | |
$generatedObj = new Session('https://example.com/viewer/session-19440514'); | |
$generatedObj->setName('session-19440514') | |
->setDateCreated($createdTime) | |
->setDateModified($modifiedTime) | |
->setActor($person) | |
->setStartedAtTime($sessionStartTime); | |
$sessionEvent = new SessionEvent(); | |
$sessionEvent->setAction(new Action(Action::LOGGED_IN)) | |
->setActor($person) | |
->setObject($eventObj) | |
->setTarget($targetObj) | |
->setGenerated($generatedObj) | |
->setEventTime($sessionStartTime); | |
$this->sessionEvent = $sessionEvent; | |
} | |
} | |
$sensor = new Sensor('id'); | |
$options = (new Options()) | |
->setApiKey('org.imsglobal.caliper.php.apikey') | |
->setDebug(true) | |
->setHost('http://localhost:8000/'); | |
$sensor->registerClient('http', new Client('clientId', $options)); | |
$sessionTest = new SessionEventSampleApp(); | |
$sessionTest->setUp(); | |
echo "sending...\r"; | |
$sensor->send($sensor, $sessionTest->getSessionEvent()); | |
echo "send() done\n"; | |
echo "describing...\r"; | |
$sensor->describe($sensor, $sessionTest->getPersonEntity()); | |
echo "describe() done\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment