LTI Integration Library  3.1.0
PHP class library for building LTI integrations
ApiHook.php
Go to the documentation of this file.
1 <?php
2 
3 namespace ceLTIc\LTI\ApiHook;
4 
13 trait ApiHook
14 {
15 
19  public static $USER_ID_HOOK = "UserId";
20 
24  public static $CONTEXT_ID_HOOK = "ContextId";
25 
29  public static $MEMBERSHIPS_SERVICE_HOOK = "Memberships";
30 
34  public static $OUTCOMES_SERVICE_HOOK = "Outcomes";
35 
39  public static $TOOL_SETTINGS_SERVICE_HOOK = "ToolSettings";
40 
44  private static $API_HOOKS = array();
45 
53  public static function registerApiHook($hookName, $familyCode, $className)
54  {
55  $objectClass = get_class();
56  self::$API_HOOKS["{$objectClass}-{$hookName}-{$familyCode}"] = $className;
57  }
58 
65  private static function getApiHook($hookName, $familyCode)
66  {
67  $class = self::class;
68  return self::$API_HOOKS["{$class}-{$hookName}-{$familyCode}"];
69  }
70 
79  private static function hasApiHook($hookName, $familyCode)
80  {
81  $class = self::class;
82  return isset(self::$API_HOOKS["{$class}-{$hookName}-{$familyCode}"]);
83  }
84 
93  private function hasService($serviceName, $endpointSettingNames)
94  {
95  $found = false;
96  if (!is_array($endpointSettingNames)) {
97  $found = !empty($this->getSetting($endpointSettingNames));
98  } else {
99  foreach ($endpointSettingNames as $endpointSettingName) {
100  $found = $found || !empty($this->getSetting($endpointSettingName));
101  }
102  }
103  return $found || self::hasApiHook($serviceName, $this->getConsumer()->getFamilyCode());
104  }
105 
106 }
107 
108 ?>
static $OUTCOMES_SERVICE_HOOK
Outcomes service hook name.
Definition: ApiHook.php:34
static $CONTEXT_ID_HOOK
Context Id hook name.
Definition: ApiHook.php:24
static $MEMBERSHIPS_SERVICE_HOOK
Memberships service hook name.
Definition: ApiHook.php:29
static $USER_ID_HOOK
User Id hook name.
Definition: ApiHook.php:19
Trait to handle API hook registrations.
Definition: ApiHook.php:13
static registerApiHook($hookName, $familyCode, $className)
Register the availability of an API hook.
Definition: ApiHook.php:53
static $TOOL_SETTINGS_SERVICE_HOOK
Tool Settings service hook name.
Definition: ApiHook.php:39