From 5eb6ae6d4795aed0e8140b35174c7311cd6054e3 Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Sun, 21 Sep 2014 00:19:21 +0200 Subject: [PATCH] adding token to service to allow it to be used at constructor time by Object_* class --- .gitignore | 3 +++ lib/Alternc/Api/Service.php | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 83c1a2fc..896a4846 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ debian/alternc-awstats debian/alternc-awstats.debhelper.log debian/alternc-awstats.postrm.debhelper debian/alternc-awstats.substvars +debian/alternc-api +debian/alternc-api.debhelper.log +debian/alternc-api.substvars debian/alternc-roundcube debian/alternc-roundcube.debhelper.log debian/alternc-roundcube.substvars diff --git a/lib/Alternc/Api/Service.php b/lib/Alternc/Api/Service.php index 4eb1f8e0..6a771649 100644 --- a/lib/Alternc/Api/Service.php +++ b/lib/Alternc/Api/Service.php @@ -130,11 +130,11 @@ class Alternc_Api_Service { if (!$request instanceof Alternc_Api_Request) throw new \Exception("request must be an Alternc_Api_Request object", self::ERR_INVALID_ARGUMENT); - - $token = Alternc_Api_Token::tokenGet($request->token_hash,$this->db); - if ($token instanceof Alternc_Api_Response) // bad token - return $token; - + // we set the token in the Service object, so that other classes can use it :) + $this->token = Alternc_Api_Token::tokenGet($request->token_hash,$this->db); + if ($this->token instanceof Alternc_Api_Response) // bad token + return $this->token; + $className = "Alternc_Api_Object_".ucfirst(strtolower($request->object)); if (!class_exists($className)) return new Alternc_Api_Response( array("code" => self::ERR_OBJECT_NOT_FOUND, "message" => "Object not found in this AlternC's instance") ); @@ -143,9 +143,9 @@ class Alternc_Api_Service { $action=$request->action; if (!method_exists($object, $action)) - return new Alternc_Api_Response( array("code" => self::ERR_ACTiON_NOT_FOUND, "message" => "Action not found for this object in this AlternC's instance") ); + return new Alternc_Api_Response( array("code" => self::ERR_ACTION_NOT_FOUND, "message" => "Action not found for this object in this AlternC's instance") ); - $request->token=$token; // we receive $request->token_hash as a STRING, but we transmit its object as an Alternc_Api_Token. + $request->token=$this->token; // we receive $request->token_hash as a STRING, but we transmit its object as an Alternc_Api_Token. // TODO: log this Api Call return $object->$action($request);