|
Posted by David Haynes on 11/23/05 21:58
From a pure OO perspective, 'validate' is a method not an object.
What you really have is an emailAddress object that requires a validate
method.
Something like:
$email = new emailAddress($_POST['email']);
if( $email->isValid() {
...
} else {
...
}
-david-
Angelos wrote:
> Hello again,
>
> I have written three classes : validate.class.php,
> report_handler.class.php, sentry.class.php.
>
> The problem is that the "validate" class uses the "reporting" class and
> the "sentry" uses the "validate" that uses the "reporting".
>
> So I end up having something like that inside sentry.class.php:
> $validate->report->getReport();
>
> But although that's working... it doesn't seem to be really OO :p
>
> So can you tell me what I can do ?
>
> If what I am saying doesn't make any sense at all... let me know and I
> will try to explain it better.
>
> Bellow I have some snippets from each class that may help you to
> understand what I am trying to do.
> ********************************************************************
> class report_handler {
> ...
> /* This Function populates the array with reports (ERRORS,MESSAGES)
> * Syntax: setReport($reportType,$string)
> */
> function setReport($reportType,$string='') {
> if($this->validateReportTypes($reportType)) {
> $this->counter++;
> $this->report[$this->counter] = array( 'category' =>
> $reportType,
> 'description' =>
> $string);
> }
> else
> echo "Report type '".$reportType."' is not valid";
> }
> /* Output the report to the user
> */
> function getReport() {
> if(is_array($this->report))
> {
> foreach($this->report as $i => $value)
> {
> echo "<pre>".
> $value['category'].': '.
> $value['description']
> ."</pre>";
> }
> }
> }
> ...
> }
> /*****************END of class report_handler********************/
>
> class validate {
>
> function validate()
> {
> $this->report = new report_handler();
> }
>
> function checkEmail($email)
> {
> // checks proper syntax
> if(
> !preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/',
> $email))
> {
> $this->report->setReport('Error','Syntax Error');
> return false;
> }
> ....
> }
> }
> /*****************END of class validate ********************/
> class sentry {
> var $user_id;
> var $session_timeout;
>
> function sentry()
> {
> $this->report = new report_handler;
> }
> ....
>
> function validateLoginForm()
> {
> $validate = new validate();
> if($validate->checkEmail($_POST['email']))
> {
> $this->loginUserName = $_POST['email'];
> $this->loginPassword = $_POST['passwd'];
> return true;
> }
> else
> {
> $validate->report->getReport();
> return false;
> }
> }
> ....
> }
> /*****************END of class sentry********************/
>
>
>
>
> Thanks a lot for reading and for any help you may provide.
> Angelos.
[Back to original message]
|