Alternc  latest
Alternc logiel libre pour l'hébergement
Request.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * Standard Request object for the AlternC API
5  *
6  * Helps streamlining the calls by checking parameters
7  */
9 
10  /**
11  *
12  * @var Alternc_Api_Token object
13  */
14  public $token;
15 
16  /**
17  *
18  * @var string a token hash (to be authenticated)
19  */
20  public $token_hash;
21 
22  /**
23  * must link to a Alternc_Api_Object_Interface
24  *
25  * @var string
26  */
27  public $object;
28 
29  /**
30  * must link to a Alternc_Api_Object_Interface method
31  *
32  * @var string
33  */
34  public $action;
35 
36  /**
37  * bag of data
38  *
39  * @var array
40  */
41  public $options;
42 
43  /**
44  *
45  * Bag of data
46  *
47  * @var array
48  */
49  public $metadata;
50 
51  const ERR_MISSING_PARAMETER = 111801;
52 
53  function __construct($options) {
54 
55 
56  // Attempts to retrieve object
57  if (isset($options["object"]) && is_string($options["object"])) {
58  $this->object = $options["object"];
59  } else {
60  throw new \Exception("Missing parameter object", self::ERR_MISSING_PARAMETER);
61  }
62 
63  // Attempts to retrieve action
64  if (isset($options["action"]) && is_string($options["action"])) {
65  $this->action = $options["action"];
66  } else {
67  throw new \Exception("Missing parameter action", self::ERR_MISSING_PARAMETER);
68  }
69 
70  // Attempts to retrieve options
71  if (isset($options["options"])) {
72  if (is_array($options)) {
73  $this->options = $options["options"];
74  } else {
75  throw new \Exception("Missing parameter options", self::ERR_MISSING_PARAMETER);
76  }
77  } else {
78  $this->options = array();
79  }
80 
81  // Attempts to retrieve token
82  if (isset($options["token"])) {
83  if (is_a($options["token"], Alternc_Api_Token)) {
84  $this->token = $options["token"];
85  } else {
86  throw new \Exception("Bad parameter token", self::ERR_MISSING_PARAMETER);
87  }
88  } else {
89  // Attempts to retrieve token_hash then
90  if (isset($options["token_hash"]) && is_string($options["token_hash"])) {
91  $this->token_hash = $options["token_hash"];
92  } else {
93  throw new \Exception("Missing parameter token OR token_hash", self::ERR_MISSING_PARAMETER);
94  }
95  }
96 
97  // Attempts to retrieve metadata (eg: API version)
98  if (isset($options["metadata"])) {
99  $this->metadata = $options["metadata"];
100  }
101  }
102 
103 }
Standard Request object for the AlternC API.
Definition: Request.php:8
__construct($options)
Definition: Request.php:53
const ERR_MISSING_PARAMETER
Definition: Request.php:51
Standard Token object for the AlternC API.
Definition: Token.php:7