/** * Basic sanitisation of request input data. * Ensures that all expected arguments are present and of the correct data type. * Removes any arguments from the array that were not expected. * @param $args array Would normally be $_REQUEST, $_POST or similar. */ public function populateArgs($args) { unset($args['module']); //once we're here we know what module & lib we're in, so can drop those args. unset($args['lib']); $expected = $this->expectedArgs(); $expected['paGame'] = array('default' => paConfig::getGame()); $this->args = $args; //compare args we've been given with the ones we expect. //drop any args we weren't expecting. foreach (array_keys($this->args) as $key) { if (!isset($expected[$key])) { unset($this->args[$key]); } } //and for the ones we are expecting, make sure they meet expectations. foreach ($expected as $key => $props) { $defvalue = $this->defaultValue($props); $deftype = $this->defaultType($props); if (!isset($this->args[$key])) { $this->args[$key] = $defvalue; } if ($deftype && isset($this->args[$key])) { settype($this->args[$key], $deftype); } $this->validateArg($key, $props); } if (count($this->errorData)) { throw new paException('Invalid arguments', $this->errorData); } }
/** * Currently sqlite; Change this to use mySQL (or whatever). * @return string The PDO DSN string for the database. */ private function dsn() { $dsn = paConfig::load('dsn'); $dsn = str_replace('@gamedir', ADVENGAME_ROOT . '/assets/' . paConfig::getGame(), $dsn); return $dsn; }