99 *
1010 * @author Kevin Saliou <kevin at saliou dot name>
1111 * Website: http://github.com/kbsali/php-redmine-api
12+ *
13+ * @property Api\Attachment $attachment
14+ * @property Api\Group $group
15+ * @property Api\CustomField $custom_fields
16+ * @property Api\Issue $issue
17+ * @property Api\IssueCategory $issue_category
18+ * @property Api\IssuePriority $issue_priority
19+ * @property Api\IssueRelation $issue_relation
20+ * @property Api\IssueStatus $issue_status
21+ * @property Api\Membership $membership
22+ * @property Api\News $news
23+ * @property Api\Project $project
24+ * @property Api\Query $query
25+ * @property Api\Role $role
26+ * @property Api\TimeEntry $time_entry
27+ * @property Api\TimeEntryActivity $time_entry_activity
28+ * @property Api\Tracker $tracker
29+ * @property Api\User $user
30+ * @property Api\Version $version
31+ * @property Api\Wiki $wiki
1232 */
1333class Client
1434{
@@ -97,6 +117,28 @@ class Client
97117 JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded ' ,
98118 JSON_ERROR_SYNTAX => 'Syntax error ' ,
99119 );
120+
121+ private $ classes = array (
122+ 'attachment ' => 'Attachment ' ,
123+ 'group ' => 'Group ' ,
124+ 'custom_fields ' => 'CustomField ' ,
125+ 'issue ' => 'Issue ' ,
126+ 'issue_category ' => 'IssueCategory ' ,
127+ 'issue_priority ' => 'IssuePriority ' ,
128+ 'issue_relation ' => 'IssueRelation ' ,
129+ 'issue_status ' => 'IssueStatus ' ,
130+ 'membership ' => 'Membership ' ,
131+ 'news ' => 'News ' ,
132+ 'project ' => 'Project ' ,
133+ 'query ' => 'Query ' ,
134+ 'role ' => 'Role ' ,
135+ 'time_entry ' => 'TimeEntry ' ,
136+ 'time_entry_activity ' => 'TimeEntryActivity ' ,
137+ 'tracker ' => 'Tracker ' ,
138+ 'user ' => 'User ' ,
139+ 'version ' => 'Version ' ,
140+ 'wiki ' => 'Wiki ' ,
141+ );
100142
101143 /**
102144 * Usage: apikeyOrUsername can be auth key or username.
@@ -113,6 +155,20 @@ public function __construct($url, $apikeyOrUsername, $pass = null)
113155 $ this ->apikeyOrUsername = $ apikeyOrUsername ;
114156 $ this ->pass = $ pass ;
115157 }
158+
159+ /**
160+ * PHP getter magic method.
161+ *
162+ * @param string $name
163+ *
164+ * @return Api\AbstractApi
165+ *
166+ * @throws \InvalidArgumentException
167+ */
168+ public function __get ($ name )
169+ {
170+ return $ this ->api ($ name );
171+ }
116172
117173 /**
118174 * @param string $name
@@ -123,34 +179,13 @@ public function __construct($url, $apikeyOrUsername, $pass = null)
123179 */
124180 public function api ($ name )
125181 {
126- $ classes = array (
127- 'attachment ' => 'Attachment ' ,
128- 'group ' => 'Group ' ,
129- 'custom_fields ' => 'CustomField ' ,
130- 'issue ' => 'Issue ' ,
131- 'issue_category ' => 'IssueCategory ' ,
132- 'issue_priority ' => 'IssuePriority ' ,
133- 'issue_relation ' => 'IssueRelation ' ,
134- 'issue_status ' => 'IssueStatus ' ,
135- 'membership ' => 'Membership ' ,
136- 'news ' => 'News ' ,
137- 'project ' => 'Project ' ,
138- 'query ' => 'Query ' ,
139- 'role ' => 'Role ' ,
140- 'time_entry ' => 'TimeEntry ' ,
141- 'time_entry_activity ' => 'TimeEntryActivity ' ,
142- 'tracker ' => 'Tracker ' ,
143- 'user ' => 'User ' ,
144- 'version ' => 'Version ' ,
145- 'wiki ' => 'Wiki ' ,
146- );
147- if (!isset ($ classes [$ name ])) {
182+ if (!isset ($ this ->classes [$ name ])) {
148183 throw new \InvalidArgumentException ();
149184 }
150185 if (isset ($ this ->apis [$ name ])) {
151186 return $ this ->apis [$ name ];
152187 }
153- $ c = 'Redmine\Api \\' .$ classes [$ name ];
188+ $ c = 'Redmine\Api \\' .$ this -> classes [$ name ];
154189 $ this ->apis [$ name ] = new $ c ($ this );
155190
156191 return $ this ->apis [$ name ];
0 commit comments