Page MenuHomeCode

choice.php
No OneTemporary

choice.php

<?php
/**
* Story choice.
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* @package Zed
* @subpackage Story
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
/**
* Story choice class
*
* This class is a PHP mapping from the Story XML format's <choice> tag.
*
* <code>
* $xml = "<choice goto=\"city.entry\">Descendre vers le centre ville</choice>";
* $parser = new SimpleXmlElement($xml);
* $choice = StoryChoice::from_xml($parser);
*
* echo $choice->text; //That will output Descendre vers le centre ville
* echo $choice->goto; //That will output city.entry
* echo $choice->guid; //That will output any guid generated for this instance
*
* $thesamechoice = StoryChoice::from_xml($parser);
* echo $thesamechoice->guid; //That will ouput another guid
* </code>
*/
class StoryChoice {
/**
* The section key this choices links to
*
* @var string
*/
public $goto;
/**
* The choice text
*
* @var string
*/
public $text;
/**
* The choice GUID
*
* It will be automatically generated by the constructor, and so is an
* ephemere data for this StoryChoice instance.
*
* @see new_guid
*
* @var string
*/
public $guid;
/**
* Constructor
*/
function __construct () {
//The guid allows to build temporary URLs to get to right choice
$this->guid = new_guid();
}
/**
* Gets the story text as a string representation of the class
*
* @return string The story text
*/
function __toString () {
return $this->text;
}
/**
* Initializes a new instance of StoryChoice class from a XML element
*
* @param SimpleXMLElement the xml element to parse
* @return StoryChoice the story choice class
*/
static function from_xml ($xml) {
$choice = new StoryChoice();
//Parses attribute
foreach ($xml->attributes() as $key => $value) {
switch ($key) {
case 'goto':
$choice->$key = (string)$value;
break;
default:
message_die(GENERAL_ERROR, "Unknown attribute: $key = \"$value\"", "Story error");
}
}
//Parses content
$choice->text = (string)$xml;
return $choice;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Feb 22, 20:24 (1 d, 3 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21952
Default Alt Text
choice.php (2 KB)

Event Timeline