Skip to content

Instantly share code, notes, and snippets.

@DanielHe4rt
Created February 6, 2021 16:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielHe4rt/5d100a673b5ec9fc43f19e83b666e222 to your computer and use it in GitHub Desktop.
Save DanielHe4rt/5d100a673b5ec9fc43f19e83b666e222 to your computer and use it in GitHub Desktop.
Script de Orientação a Objetos - Chat
<?php
// Speedrun Aula de Orientação a Objetos
$chatMessages = [];
class Chatter
{
/**
* @var string
*/
public $name;
/**
* @var array
*/
public $log = [];
/**
* @var string
*/
private $password;
public function __construct(string $name, string $password)
{
// setando um valor = setter
$this->name = $name;
$this->password = $password;
}
/**
* Create a message
*
* @param $message
*
* @return string
*/
public function say($message): string
{
$time = date('H:i');
$message = "($time) $this->name: $message";
$this->log[] = $message;
return $message;
}
/**
* Change password
*
* @param string $oldPassword
* @param string $password
* @throws Exception
*/
public function changePassword(string $oldPassword, string $password): string
{
if ($this->password != $oldPassword) {
throw new Exception('mano para de tentar invadi o amiguinho');
}
$this->password = $password;
$time = date('H:i');
return "($time) Admin: senha do $this->name alterada com sucesso!";
}
}
$danielhe4rt = new Chatter('danielhe4rt', 'secret');
$mattacrime = new Chatter('mattacrime', 'secret');
$zuruck = new Chatter('zuruck', 'secret');
$zuruck->name = "zika do pantano";
$chatMessages[] = $danielhe4rt->say('eae rapaziada ajuda no ar condicionado');
$chatMessages[] = $mattacrime->say('porra lek com certeza vo te ajuda nessa ai toma o prime');
$chatMessages[] = $zuruck->say('po mano já so sub dá um desconto');
$chatMessages[] = $danielhe4rt->say('@zuruck demoro mano obg vc é d+ mas eu vo te hackear anonemos');
$chatMessages[] = $zuruck->say('vai nada pois trocarei a senha agora seu bobo');
$chatMessages[] = $zuruck->changePassword('secret', 'fodase');
foreach ($chatMessages as $message) {
echo $message . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment