uwdoem / person
华盛顿大学人员和学生网络服务客户端库
Requires
- uwdoem/connection: 3.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpdocumentor/phpdocumentor: 2.7.*
- phpunit/phpunit: 4.5.*
- squizlabs/php_codesniffer: 2.*
- uwdoem/standard: *
README
UWDOEM/Person
通过X.509证书身份验证,平滑地轮询华盛顿大学的 人员网络服务(PWS)和 学生网络服务(SWS),以聚合特定附属机构的数据。
例如
// Intialize the required settings
define('UW_WS_BASE_PATH', '/path/to/my/private.key');
define('UW_WS_SSL_KEY_PATH', '/path/to/my/private.key');
define('UW_WS_SSL_CERT_PATH', '/path/to/my/public_cert.pem');
define('UW_WS_SSL_KEY_PASSWD', 'myprivatekeypassword'); // Can be blank for no password: ''
define('UW_WS_VERBOSE', false); // (Optional) Whether to include verbose cURL messages in error messages.
/* Query the web services */
$student = Student::fromStudentNumber("1033334");
echo $student->getAttr("RegisteredFirstMiddleName");
// "JAMES AVERAGE"
echo $student->getAttr("UWNetID");
// "javerage"
/* Retrieve registration for James Average*/
$registrations = $student->registrationSearch("2009", "summer");
echo $registrations[0]["CurriculumAbbreviation"]; // "TRAIN"
echo $registrations[0]["CourseNumber"]; // "100"
/* Retrieve employee information from the web services */
$employee = Employee::fromUWNetID("jschilz");
echo $employee->getAttr("Department1");
// "Student Financial Aid Office"
echo $employee->getAttr("Title1");
// "Web Developer"
注意
这不是一个官方库,也没有得到通过PWS或SWS管理或拥有信息的任何方的认可或支持。此库没有得到华盛顿大学招生管理部的认可或支持。
安装
此库已在Packagist上发布。要使用Composer安装,请将"uwdoem/person": "1.*"
行添加到您的"require"依赖项中。
{
"require": {
"uwdoem/person": "1.*"
}
}
当然,您也可以通过直接下载来使用Person而无需Composer,但强烈建议使用Composer来管理软件包。有关更多信息,请参阅Composer。
使用
此客户端库提供四个数据容器类:Person
、Student
、Employee
和Alumni
。
如果您尚未这样做,请按照PWS在获取PWS访问权限的说明操作。类似的一组步骤将允许您获取SWS访问权限。您需要将您创建的私钥和大学签名的证书放置在您的Web服务器上,并允许您的Web服务器进程进行读取。
在查询网络服务之前,您必须首先通过调用::createInstance
初始化连接。
// Intialize the required settings
define('UW_WS_BASE_PATH', '/path/to/my/private.key');
define('UW_WS_SSL_KEY_PATH', '/path/to/my/private.key');
define('UW_WS_SSL_CERT_PATH', '/path/to/my/public_cert.pem');
define('UW_WS_SSL_KEY_PASSWD', 'myprivatekeypassword'); // Can be blank for no password: ''
define('UW_WS_VERBOSE', false); // (Optional) Whether to include verbose cURL messages in error messages.
术语UW_WS_SSL_KEY_PATH
和UW_WS_SSL_CERT_PATH
对应于您的私钥和大学签名的证书的绝对位置。术语UW_WS_SSL_KEY_PASSWD
对应于解锁您的私钥的字符串;如果您的密钥没有密码,则使用空字符串,例如:''
。
术语UW_WS_BASE_PATH
对应于UW网络服务的共享基本URL。目前,对于生产访问网络服务,它是"https://ws.admin.washington.edu/"
,对于测试/开发访问网络服务,它是"https://wseval.s.uw.edu/"
。
您现在可以针对网络服务发出查询。
// Queries PWS/SWS for a student with StudentNumber "1033334".
$student = Student::fromStudentNumber("1033334");
// If no such student was found, then $student is null
if ($student != null) {
echo $student->getAttr("RegisteredFirstMiddleName");
}
在上面的情况下,确实存在一个学生,学号为"1033334",他是大学的一个虚拟测试学生。因此,此脚本将输出"JAMES AVERAGE"。
可以使用以下方法查询数据库
// Available to Person, and all subclasses of Person
$person = Person::fromUWNetID($uwnetid);
$person = Person::fromUWRegID($uwregid);
$person = Person::fromIdentifier("uwregid", $uwregid);
$person = Person::fromIdentifier("uwnetid", $uwnetid);
$person = Person::fromIdentifier("employee_id", $employeeid);
$person = Person::fromIdentifier("student_number", $studentnumber);
$person = Person::fromIdentifier("student_system_key", $studentsystemkey);
$person = Person::fromIdentifier("development_id", $developmentid);
// Available only to Student
$student = Student::fromStudentNumber($studentnumber);
$registrations = $student->registrationSearch($year, $quarter, [$extraSearchTerms]);
// Available only to Employee
$employee = Employee::fromEmployeeID($employeeid);
// Available only to Alumni
$alumni = Alumni::fromDevelopmentID($developmentid);
您可以在容器类的每个::fromPerson
方法之间进行类型转换
$person = Person::fromUWNetID($uwnetid);
// Cast the Person object into a Student
$person = Student::fromPerson($person);
::hasAffiliation
方法可以告诉您给定的人是否是学生、员工和/或校友
$person = Person::fromUWNetID($uwnetid);
// The ::hasAffiliation method check is useful, but not required:
if ($person->hasAffiliation("employee") {
$person = Employee::fromPerson($person);
}
使用::getAttr
从人员检索属性
$person = Person::fromUWNetID($uwnetid);
$displayName = $person->getAttr("DisplayName");
$person = Student::fromPerson($person);
$academicDepartment = $person->getAttr("Department1");
Student::registrationSearch
方法返回一个关联数组格式的注册资源数组
$student = Student::fromStudentNumber("1033334");
$registrations = $student->registrationSearch("2009", "summer");
foreach ($registrations as $registration) {
echo $registration["CurriculumAbbreviation"];
echo $registration["CourseNumber"];
}
您可以在注册搜索中包含可选参数,具体请参考注册搜索资源规范
$student = Student::fromStudentNumber("1033334");
$registrations = $student->registrationSearch("2009", "summer", ["is_active" => "true"]);
公开属性
容器类公开以下属性,对应于此PWS词汇表中描述的属性
Exposed by all classes:
"DisplayName"
"IsTestEntity"
"RegisteredFirstMiddleName"
"RegisteredName"
"RegisteredSurname"
"UIDNumber"
"UWNetID"
"UWRegID"
"WhitepagesPublish"
Exposed only by Employee:
"EmployeeID"
"Address1"
"Address2"
"Department1"
"Department2"
"Email1"
"Email2"
"Fax"
"Name"
"Phone1"
"Phone2"
"PublishInDirectory"
"Title1"
"Title2"
"TouchDial"
"VoiceMail"
Exposed only by Student:
"StudentNumber"
"StudentSystemKey"
"Class"
"Department1"
"Department2"
"Department3"
"Email"
"Name"
"Phone"
"PublishInDirectory"
Exposed by Student, when SWS access is enabled:
"RegID"
"FirstName"
"LastName"
"StudentName"
"EmployeeID"
"BirthDate"
"Gender"
"DirectoryRelease"
"LocalAddress"
"Line1"
"Line2"
"City"
"State"
"Zip"
"Country"
"PostalCode"
"PermanentAddress"
"Line1"
"Line2"
"City"
"State"
"Zip"
"Country"
"PostalCode"
"LocalPhone"
"PermanentPhone"
"Veteran"
"Code"
"Description"
"LastEnrolled"
"Href"
"Year"
"Quarter"
"Notices"[]
"RegID"
"Href"
"PersonFinancial"[]
"RegID"
"Href"
"Resident"
"VisaType"
"TestScore"[]
"RegID"
"Href"
Exposed only by Alumni:
"DevelopmentID"
故障排除
当此库识别到错误时,将会抛出警告和异常。打开错误报告以查看这些信息。对于涉及cURL、SSL或脚本执行停止/无输出错误的错误,请参阅UWEnrollmentManagement/Connection故障排除。
兼容性
- 人员Web服务v1
- 学生Web服务v5
要求
- PHP 7.0
- uwdoem/connection 3.*
待办事项
请参阅GitHub 问题跟踪器。
参与其中
请随时提交拉取请求或问题。本项目的主场位于GitHub。
以下是代码贡献的一般步骤
- 在问题跟踪器中打开一个问题。
- 顺序不限
- 提交一个带有失败的测试的拉取请求,以展示问题/功能。
- 获取确认。
- 修改您的拉取请求以通过(2)中的测试。如有必要,请包含文档。
PSR-2兼容性由Travis中的CodeSniffer强制执行。