Hello again,
I have written three classes : validate.class. php,
report_handler. class.php, sentry.class.ph p.
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.ph p:
$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,MESSAGE S)
* Syntax: setReport($repo rtType,$string)
*/
function setReport($repo rtType,$string= '') {
if($this->validateReport Types($reportTy pe)) {
$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($th is->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($ema il)
{
// 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('Err or','Syntax Error');
return false;
}
....
}
}
/*************** **END of class validate *************** *****/
class sentry {
var $user_id;
var $session_timeou t;
function sentry()
{
$this->report = new report_handler;
}
....
function validateLoginFo rm()
{
$validate = new validate();
if($validate->checkEmail($_P OST['email']))
{
$this->loginUserNam e = $_POST['email'];
$this->loginPasswor d = $_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.
I have written three classes : validate.class. php,
report_handler. class.php, sentry.class.ph p.
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.ph p:
$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,MESSAGE S)
* Syntax: setReport($repo rtType,$string)
*/
function setReport($repo rtType,$string= '') {
if($this->validateReport Types($reportTy pe)) {
$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($th is->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($ema il)
{
// 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('Err or','Syntax Error');
return false;
}
....
}
}
/*************** **END of class validate *************** *****/
class sentry {
var $user_id;
var $session_timeou t;
function sentry()
{
$this->report = new report_handler;
}
....
function validateLoginFo rm()
{
$validate = new validate();
if($validate->checkEmail($_P OST['email']))
{
$this->loginUserNam e = $_POST['email'];
$this->loginPasswor d = $_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.
Comment