Student http://semisalsaja.com/sekolah/student.asmx?WSDL
- studentList
Mentor http://semisalsaja.com/sekolah/mentor.asmx?WSDL
- mentorList
study http://semisalsaja.com/sekolah/study.asmx?WSDL
- studyList
I’m trying to get data from some SOAP resources (mentioned above):
class SchoolSoap {
protected $_config = array();
public $_soap, $_error, $_params, $_result;
public function __construct($params = array()) {
$this->_config = $params;
try {
$this->_soap = new SoapClient($this->_config['url'], array('trace' => 1, 'exception' => 1));
} catch (Exception $e) {
$this->_error = $e->getMessage();
}
}
public function actionSoap($function) {
try {
$result = $this->_soap->__soapCall($function, array('parameters' => $this->_params));
$this->_result = $result;
return true;
} catch (Exception $e) {
$this->_error = $e->getMessage();
return false;
}
}
public function setParam($params) {
$this->_params = $params;
return $this;
}
}
The 1st class is for calling SOAP and it will be called/ instanced from static classes.
class StudentHelper {
public static function getStudentList($config, $params, SchoolSoap $soap = null) {
$function = 'studentList';
if ($soap == null) {
$soap = new SchoolSoap($config);
}
$result = $soap->setParam($params)->actionSoap($function);
if ($result == false) {
return false;
} else {
return $soap->_result->$function;
}
}
}
class MentorHelper {
#similar with class StudentHelper
}
class StudyHelper {
#similar with class StudentHelper
}
The next next classes (I called Helper) are static class. I created resources Student, Mentor, Study, for every SOAP. For example, in class StudentHelper, there is a method named getStudentList that will get the student’s data, and it will be called from a function (next code). class Mentor and Study are similar.
function printStudentList() {
$config = array(
'url' => 'http://semisalsaja.com/sekolah/student.asmx?WSDL',
'username' => 'user123',
'key' => 'abcdefghij'
);
$params = array('start' => 1, 'limit' => 20);
return StudentHelper::getStudentList($config, $params);
}
Next is function to call Static class (example, call StudentHelper). I passed configs and params in this function, and it will return bool false if soap failed and data of student if soap succeeded.
$student_list = printStudentList();
print_r($student_list);
Here I call parse function into variable, then print the variable.
Is my design correct with the concept of OOP in PHP? Any suggestion for me to make it better? I’m still new to learning about programming, especially OOP.