Subscribe to Events

To subscribe on ‘user available’ and ‘user changed’ events, use the following example:

public function provision() {
    ...
    $apsc2 = \APS\Request::getController();
    $apsc = $apsc2->impersonate($this);
    $sub = new \APS\EventSubscription(\APS\EventSubscription::Changed, "onUserChanged");
    $sub->source = new stdClass();
    $sub->source->type='http://aps-standard.org/types/core/user/1.0';
    $apsc->subscribe($this, $sub);

    $sub = new \APS\EventSubscription(\APS\EventSubscription::Available, "onUserAvailable");
    $sub->source = new stdClass();
    $sub->source->type='http://aps-standard.org/types/core/user/1.0';
    $apsc->subscribe($this, $sub);
    ...
}
  ....

/**
 * @verb(POST)
 * @path("/onUserChanged")
 * @param("http://aps-standard.org/types/core/resource/1.0#Notification",body)
 */
public function onUserChanged($notification) {
    $apsc = \APS\Request::getController();
    $apsc2 = $apsc->impersonate($this);
    $user = $apsc2->getResource($notification->source->id);
    $displayName = $user->displayName;
    $login = $user->login;
    $mail = $user->email;
    ...
}

/**
 * @verb(POST)
 * @path("/onUserAvailable")
 * @param("http://aps-standard.org/types/core/resource/1.0#Notification",body)
 */
public function onUserAvailable($notification) {
    $apsc = \APS\Request::getController();
    $apsc2 = $apsc->impersonate($this);
    $user = $apsc2->getResource($notification->source->id);
    $displayName = $user->displayName;
    $login = $user->login;
    $mail = $user->email;
    ...
}

Subscription Limit Changed event:

$apsc2 = \APS\Request::getController();
$apsc = $apsc2->impersonate($this);
$subLimitchange = new \APS\EventSubscription("http://parallels.com/aps/events/pa/subscription/limits/changed", "onSubcriptionLimitchange");
$subLimitchange->source = new stdClass();
$subLimitchange->source->id = $this->subscription->aps->id;
$apsc->subscribe($this, $subLimitchange);

/**
 * @verb(POST)
 * @path("/onSubcriptionLimitchange")
 * @param("http://aps-standard.org/types/core/resource/1.0#Notification",body)
 */
public function onSubcriptionLimitchange($notification) {
    $apsc = \APS\Request::getController();
    $apsc2 = $apsc->impersonate($this);
    $subscription = $apsc2->getResource($notification->source->id);
    $subscrRTs = $subscription->resources();
    ....
}

Read more: