GuardianOfTheFlame
Programmer
hi all,
my question is (regarding the ReportType class):
is there a way to loop through the costants defined in the class?
this is my enum implementation:
I use it in function calls:
and to validate the function parameter:
I would like to create an array of defined costants similar to the result of get_class_vars... I need a sort of "get_class_costants":
Thanks,
Matteo
---
The surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us - Calvin (and Hobbes) ;-)
my question is (regarding the ReportType class):
is there a way to loop through the costants defined in the class?
this is my enum implementation:
Code:
final class ReportType {
const Total = 'total';
const SpecificCenter = 'specific_center';
const AllCenters = 'all_centers';
const Average = 'average';
// ensures that this class acts like an enum
// and that it cannot be instantiated
private function __construct(){}
public static function isValid($value) {
switch ($value) {
case ReportType::Total:
case ReportType::SpecificCenter:
case ReportType::AllCenters:
case ReportType::Average:
return true;
break;
default:
return false;
break;
}
return true;
}
}
Code:
$rec = $rep->getRecruitmentData('myStudy', 1, ReportType::AllCenters, 9);
Code:
public function getRecruitmentData($project_name, $user_id, $report_type, $center_id) {
if (!ReportType::isValid($report_type)) {
throw new InvalidParameterException('Cannot create recruitment report: invalid report type argument.');
return false;
}
[...]
}
Code:
public static function isValid($value) {
$valid_values = get_class_costants('ReportType');
return in_array($value, $valid_values);
}
Thanks,
Matteo
---
The surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us - Calvin (and Hobbes) ;-)