Beispiel #1
0
 /**
  * finds the main key on a Catapult
  * object
  *
  * @param obj: array or object
  */
 public static function Key($obj)
 {
     foreach (self::$keys as $k) {
         if (BaseUtilities::prop_or_arr($obj, $k)) {
             return $k;
         }
     }
     throw new \CatapultApiException("This object does not have a valid id, content field");
 }
Beispiel #2
0
 public static function find($headers, $id = true)
 {
     $header = parent::find($headers, "Location");
     if ($id) {
         $match = array();
         $pieces = explode("/", $header);
         return str_replace("\r", "", str_replace("\n", "", $pieces[sizeof($pieces) - 1]));
     }
     return $header;
 }
Beispiel #3
0
 /**
  * Verify the input is of the correct
  * type. Additionally delegate to Collection if needed
  *
  * @param data: EnsureInput as listed above
  */
 public static function Input($data)
 {
     /** handle a multiple ensure **/
     $args = func_get_args();
     if (count($args) > 1) {
         return EnsureResource::InputTwo($args);
     }
     if ($data instanceof DataPacket || $data instanceof DataPacketCollection) {
         return $data;
     }
     /** empty if not set **/
     if (!isset($data) || $data == null) {
         return new DataPacket(array());
     }
     if ($data instanceof Parameters) {
         return new DataPacket($data->data);
     }
     if (isset($data[0]) && $data[0] instanceof Parameters) {
         return new DataPacket($data[0]->data);
     }
     if ($data instanceof CollectionObject || is_string($data) || $data instanceof BaML || $data instanceof BaMLAttribute || $data instanceof BaMLVerb) {
         return new DataPacket($data);
     }
     if (isset($data[0]) && isset($data[1]) && !is_array($data[0]) && is_array($data[1])) {
         return new DataPacket(array_merge(array($data[0]), $data[1]));
     }
     if (isset($data[0]) && is_array($data) && BaseUtilities::is_multidimensional($data) && is_array($data[0]) && sizeof($data) == 1) {
         return new DataPacket($data[0]);
     }
     if (!(is_array($data) || $data instanceof \stdClass)) {
         throw new \CatapultApiException(EXCEPTIONS::WRONG_PARAMETERS);
     }
     if (!($data instanceof DataPacket && is_multidimensional($data))) {
         return new DataPacket($data);
     }
     if (!$data instanceof DataPacketCollection) {
         return new DataPacketCollection($data);
     }
 }
Beispiel #4
0
 /**
  * add one verb to another
  * unless unapplicable
  *
  *
  *
  * @param verb: BaMLVerb
  */
 public function addVerb($verb)
 {
     if (is_array($verb)) {
         $verb = BaMLVerbResource::Make($verb);
     }
     if (!$verb instanceof BaMLVerb) {
         throw new \CatapultApiException("You can only add type BaMLVerb..");
     }
     /** check for constraints **/
     if (isset($this->constraints['verbs']) && sizeof($this->verbs) >= $this->constraints['verbs']) {
         throw new \CatapultApiException($this->getName() . " verb can only take " . $this->constraints['verbs'] . " verbs");
     }
     /** avoid memory issues by cloning. if needed **/
     if (BaseUtilities::is_ref($verb, $this)) {
         $this->verbs[] = clone $verb;
     } else {
         $this->verbs[] = $verb;
     }
 }