Created
December 20, 2008 07:27
-
-
Save nicolish/38260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller_ModeA(){ | |
function getPost($key){ | |
return isset($_POST[$key])?$_POST[$key]:null; | |
} | |
private $validator; | |
function accept($validator){ | |
$this->validator = $validator; | |
$this->validator->visit($this); | |
} | |
function getErrorMessage(){ | |
return $this->validator->errorMessages; | |
} | |
} | |
class Validator_ModeA{ | |
private $controller; | |
public $errorMessages = array(); | |
function visit($controller){ | |
$this->controller = $controller; | |
$this->execute(); | |
} | |
private function execute(){ | |
if(false === MyDate::validate($this->controller->getPost('date')){ | |
$this->errorMessages[] = '日付が変です'; | |
} | |
if(false === HogeID::validate($this->controller->getPost('hoge_id')){ | |
$this->errorMessages[] = 'なんとかIDが変です'; | |
} | |
/* | |
* 単純なのはその場でやる | |
*/ | |
if(1000 < strlen(($this->controller->getPost('message'))){ | |
$this->errorMessages[] = 'メッセージ長いです'; | |
} | |
if(false === ctype_digit($this->controller->getPost('chojin_power'))){ | |
$this->errorMessages[] = '超人パワーが数値ではありません'; | |
} | |
} | |
} | |
?> | |
<?php | |
$c = new Controller_ModeA(); | |
$c->accept(new Validator_ModeA()); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment