Bonjour, je me met a la POO, intensivement, et je voudrais votre avis sur ma première class.
Merci a Sephi pour les petits coups de main
Ne pas faire gaffe au erreurs dans les commentaires en anglais, c'était fait vite fait
Et pour info, MySQL c'est mysqli
Merci a Sephi pour les petits coups de main
Ne pas faire gaffe au erreurs dans les commentaires en anglais, c'était fait vite fait
Et pour info, MySQL c'est mysqli
Code PHP :
<?php
/**
* Player
*
* @author El[u]ox <Lakers_suporter@hotmail.com>
* @copyright 2008
* @version 1.0
* @package Player
*/
class Player implements IPlayer
{
//Private Player Information
private $playerId;
private $name;
private $mail;
private $password;
private $avatar;
private $signature;
public function create($newPlayerInfo)
{
return System::addPlayer($newPlayerInfo);
}
public function load($playerID)
{
//Try to connect mysql
$mysql = Database::GetInstance();
//Select User Information
$sql = sprintf(
"SELECT email, name, password, avatar, signature
FROM player
WHERE id = %d;",
(int) $playerID
);
//Do the Query
$aPlayer = $mysql->sqlFetch($sql,MYSQLI_ASSOC);
$this->playerId = $playerID;
$this->mail = $aPlayer[0]['email']; //And assigning user information
$this->name = $aPlayer[0]['name'];
$this->password = $aPlayer[0]['password'];
$this->avatar = $aPlayer[0]['avatar'];
$this->signature = $aPlayer[0]['signature'];
}
public function getInfo($sKey) { //Recuperate an information
return $this->$sKey;
}
public function changeAvatar($newURL) //Change Avatar
{
$Extension = strtolower(substr(strrchr($newURL,'.'),1));
$allowedExtension = array('jpg','bmp','gif','png');
if(in_array($Extension,$allowedExtension) == false){
return 'Synthaxe URL incorrect';
exit;
}
$mysql = Database::GetInstance(); //Try to connect Mysql
$sql = sprintf("UPDATE player SET `avatar` = '%s' WHERE id = %d",strip_tags($newURL), $this->playerId); //Update query
$mysql->sqlQuery($sql); //Do the query
return 'Avatar Changé avec succès';
}
public function changeSignature($newSign) //Change Signature
{
$Extension = strtolower(substr(strrchr($newSign,'.'),1)) ;
$allowedExtension = array('jpg','bmp','gif','png');
if(in_array($Extension,$allowedExtension) == false){
return 'Synthaxe URL incorrect';
exit;
}
$mysql = Database::GetInstance(); //Try to connect Mysql
$sql = sprintf("UPDATE player SET `signature` = '%s' WHERE id = %d",strip_tags($newSign), $this->playerId); //Update query
$mysql->sqlQuery($sql); //Do the query
return 'Signature Changé avec succès';
}
/**
* @return string $this Dumping of $this
*/
public function toString() {
echo '<pre>', var_dump($this), '</pre>';
}
}
?>
Merci a ceux qui m'aiideront.