44
55use GuzzleHttp \Client ;
66use EasyPush \Exception \Exception ;
7+ use EasyPush \Exception \ClassNotFound ;
8+ use EasyPush \Interfaces \PushInterface ;
79use ReflectionClass ;
810
911class Pusher
@@ -14,21 +16,22 @@ class Pusher
1416
1517 public function __callStatic ($ name , $ arguments )
1618 {
17- $ handle = "\\EasyPush \\Handles \\{$ name }" ;
19+ $ className = "\\EasyPush \\Handles \\{$ name }" ;
1820
19- if (false === class_exists ($ handle )) {
20- throw new Exception ("{$ handle } Not Found! " );
21+ if (false === class_exists ($ className )) {
22+ throw new ClassNotFound (
23+ sprintf ('Class "%s" Not Found ' , $ className )
24+ );
2125 }
2226
23- $ reflectionClass = new ReflectionClass ($ handle );
24- $ interfaces = $ reflectionClass ->getInterfaceNames ();
25-
26- if (empty ($ interfaces ) || !in_array ('EasyPush \\Interfaces \\PushInterface ' , $ interfaces )) {
27- throw new Exception ("{$ handle } 没有继承相关接口类 " );
27+ $ reflectionClass = new ReflectionClass ($ className );
28+ $ handle = $ reflectionClass ->newInstanceArgs ($ arguments );
29+ if (false === $ handle instanceof PushInterface) {
30+ throw new Exception ("{$ className } is not instanceof PushInterface " );
2831 }
2932
3033 $ instance = new static ();
31- $ instance ->handle = new $ handle( $ arguments ) ;
34+ $ instance ->handle = $ handle ;
3235 $ instance ->client = new Client ([
3336 'base_uri ' => $ instance ->handle ->getUri ()
3437 ]);
@@ -50,12 +53,9 @@ public function __call($method, $argc)
5053 'body ' => $ body
5154 ]);
5255 } catch (\GuzzleHttp \Exception \RequestException $ e ) {
53-
54- } catch (\Excpetion $ e ) {
55-
56+ return ['code ' => $ e ->getResponse ()->getStatusCode (), 'result ' => null ];
5657 }
5758
58-
59- return $ response ->getBody ()->getContents ();
59+ return ['code ' => 200 , 'result ' => $ response ->getBody ()->getContents ()];
6060 }
6161}
0 commit comments