/** * Provides information on a specific character. * @access public * @param string $characterName The characters' name. * @param string $realmName The characters' realm name. * @param bool $onlyBasicData If true, only the basic character data will be fetched. * @return array $result Returns an array containing characterData if $characterName and $realmName are valid, otherwise FALSE. */ public function getCharacterData($characterName = NULL, $realmName = NULL, $onlyBasicData = false) { $this->cacheID = "c" . md5($characterName . $realmName); $cached = $this->getCachedData($this->cacheID); if (!is_array($cached)) { $cached = parent::getCharacterData($characterName, $realmName, $onlyBasicData); if ($this->cacheID && is_array($cached)) { $scached = serialize($cached); $this->setCachedData($this->cacheID, $scached); unset($this->cacheID); } else { return FALSE; } return $cached; } else { return $cached; } }
/** * getCharacterData * * Attempts to fetch a cached version of the requested * character. Otherwise, it calls the parent function. * * @return string[] An associative array * @param string $character The name of the character * @param string $realm The character's realm */ public function getCharacterData($characterName = NULL, $realmName = NULL) { if ($characterName == NULL && $this->characterName) { $characterName = $this->characterName; } if ($realmName == NULL && $this->realmName) { $realmName = $this->realmName; } $this->cacheID = "c" . md5($characterName . $realmName); $cached = $this->cacheFetch($this->cacheID); if (!is_array($cached)) { $cached = parent::getCharacterData($characterName, $realmName); if ($this->cacheID) { $scached = serialize($cached); $this->cacheSave($this->cacheID, $scached); unset($this->cacheID); } return $cached; } else { return $cached; } }
<?php /** * phpArmory5 test case * * A test case to derive a new class object from the phpArmory5 class. * @package phpArmory * @subpackage tests */ // Include the phpArmory class library require_once '../phpArmory.class.php'; $areaName = 'eu'; $characterName = "Arkanella"; $characterRealmName = "Madmortem"; $sapi_type = substr(php_sapi_name(), 0, 3); // Instantiate the class library if ($armory = new phpArmory5($areaName = $areaName)) { $characterData = $armory->getCharacterData($characterName, $characterRealmName); if ($sapi_type == 'cli') { var_dump($characterData); } else { $string = print_r($characterData, 1); $string = str_replace(array(" ", "\n"), array(" ", "<br />\n"), $string); echo "\$character = " . $string; } } else { echo "Failed to create a phpArmory5 instance.\n"; }