作者 lackoxygen

feat:

@@ -3,7 +3,6 @@ @@ -3,7 +3,6 @@
3 namespace Lackoxygen\TiktokShop; 3 namespace Lackoxygen\TiktokShop;
4 4
5 use Illuminate\Support\Arr; 5 use Illuminate\Support\Arr;
6 -use Lackoxygen\TiktokShop\Attribute\Config\Config;  
7 use Lackoxygen\TiktokShop\Attribute\Config\Option; 6 use Lackoxygen\TiktokShop\Attribute\Config\Option;
8 use Lackoxygen\TiktokShop\Exception\RequestNotFoundException; 7 use Lackoxygen\TiktokShop\Exception\RequestNotFoundException;
9 use Lackoxygen\TiktokShop\Request\RequestProxy; 8 use Lackoxygen\TiktokShop\Request\RequestProxy;
@@ -54,33 +53,49 @@ class Application @@ -54,33 +53,49 @@ class Application
54 */ 53 */
55 public function __construct($options = null) 54 public function __construct($options = null)
56 { 55 {
57 - if (!$options instanceof Config) {  
58 - if (is_array($options)) {  
59 - $config = static::newConfig($options);  
60 - goto next;  
61 - } 56 + $this->config = $this->loadConfig($options);
  57 + }
62 58
63 - $app = $options ?: 'default'; 59 + /**
  60 + * Read configuration
  61 + *
  62 + * @param $options
  63 + * @return Option
  64 + */
  65 + protected function loadConfig($options): Option
  66 + {
  67 + if ($options instanceof Option) {
  68 + return $options;
  69 + }
  70 + if (is_array($options)) {
  71 + return static::newConfigFormArray($options);
  72 + }
  73 + if (is_string($options)) {
  74 + return $this->configure($options);
  75 + }
  76 + return $this->configure();
  77 + }
64 78
65 - $config = \config(ServiceProvider::$name . '.' . $app); 79 + /**
  80 + * Load configuration
  81 + *
  82 + * @param string $app
  83 + * @return Option
  84 + */
  85 + protected function configure(string $app = 'default'): Option
  86 + {
  87 + $configure = \config(ServiceProvider::$name . '.' . $app, []);
66 88
67 - if (!is_array($config)) {  
68 - throw new \InvalidArgumentException('config file not found');  
69 - }  
70 - $config = static::newConfig($config);  
71 - } else {  
72 - $config = $options;  
73 - }  
74 - next:  
75 - $this->config = $config; 89 + return static::newConfigFormArray($configure);
76 } 90 }
77 91
78 /** 92 /**
79 - * @param array $options 93 + * Load configuration to object Option
80 * 94 *
  95 + * @param array $options
81 * @return Option 96 * @return Option
82 */ 97 */
83 - public static function newConfig(array $options): Option 98 + public static function newConfigFormArray(array $options): Option
84 { 99 {
85 return new Option( 100 return new Option(
86 Arr::get($options, 'app_key'), 101 Arr::get($options, 'app_key'),
@@ -102,8 +117,9 @@ class Application @@ -102,8 +117,9 @@ class Application
102 } 117 }
103 118
104 /** 119 /**
105 - * @param string $accessToken 120 + * Set access token
106 * 121 *
  122 + * @param string $accessToken
107 * @return Application 123 * @return Application
108 */ 124 */
109 public function setAccessToken(string $accessToken): Application 125 public function setAccessToken(string $accessToken): Application
@@ -114,6 +130,8 @@ class Application @@ -114,6 +130,8 @@ class Application
114 } 130 }
115 131
116 /** 132 /**
  133 + * Match object
  134 + *
117 * @param string $name 135 * @param string $name
118 * @return RequestProxy|object 136 * @return RequestProxy|object
119 * @throws RequestNotFoundException 137 * @throws RequestNotFoundException
@@ -136,9 +154,10 @@ class Application @@ -136,9 +154,10 @@ class Application
136 } 154 }
137 155
138 /** 156 /**
  157 + * Call object
  158 + *
139 * @param $name 159 * @param $name
140 * @param array $arguments 160 * @param array $arguments
141 - *  
142 * @return RequestProxy 161 * @return RequestProxy
143 * @throws RequestNotFoundException 162 * @throws RequestNotFoundException
144 */ 163 */