|
...
|
...
|
@@ -3,7 +3,6 @@ |
|
|
|
namespace Lackoxygen\TiktokShop;
|
|
|
|
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Lackoxygen\TiktokShop\Attribute\Config\Config;
|
|
|
|
use Lackoxygen\TiktokShop\Attribute\Config\Option;
|
|
|
|
use Lackoxygen\TiktokShop\Exception\RequestNotFoundException;
|
|
|
|
use Lackoxygen\TiktokShop\Request\RequestProxy;
|
|
...
|
...
|
@@ -54,33 +53,49 @@ class Application |
|
|
|
*/
|
|
|
|
public function __construct($options = null)
|
|
|
|
{
|
|
|
|
if (!$options instanceof Config) {
|
|
|
|
if (is_array($options)) {
|
|
|
|
$config = static::newConfig($options);
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
$this->config = $this->loadConfig($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
$app = $options ?: 'default';
|
|
|
|
/**
|
|
|
|
* Read configuration
|
|
|
|
*
|
|
|
|
* @param $options
|
|
|
|
* @return Option
|
|
|
|
*/
|
|
|
|
protected function loadConfig($options): Option
|
|
|
|
{
|
|
|
|
if ($options instanceof Option) {
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
if (is_array($options)) {
|
|
|
|
return static::newConfigFormArray($options);
|
|
|
|
}
|
|
|
|
if (is_string($options)) {
|
|
|
|
return $this->configure($options);
|
|
|
|
}
|
|
|
|
return $this->configure();
|
|
|
|
}
|
|
|
|
|
|
|
|
$config = \config(ServiceProvider::$name . '.' . $app);
|
|
|
|
/**
|
|
|
|
* Load configuration
|
|
|
|
*
|
|
|
|
* @param string $app
|
|
|
|
* @return Option
|
|
|
|
*/
|
|
|
|
protected function configure(string $app = 'default'): Option
|
|
|
|
{
|
|
|
|
$configure = \config(ServiceProvider::$name . '.' . $app, []);
|
|
|
|
|
|
|
|
if (!is_array($config)) {
|
|
|
|
throw new \InvalidArgumentException('config file not found');
|
|
|
|
}
|
|
|
|
$config = static::newConfig($config);
|
|
|
|
} else {
|
|
|
|
$config = $options;
|
|
|
|
}
|
|
|
|
next:
|
|
|
|
$this->config = $config;
|
|
|
|
return static::newConfigFormArray($configure);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $options
|
|
|
|
* Load configuration to object Option
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @return Option
|
|
|
|
*/
|
|
|
|
public static function newConfig(array $options): Option
|
|
|
|
public static function newConfigFormArray(array $options): Option
|
|
|
|
{
|
|
|
|
return new Option(
|
|
|
|
Arr::get($options, 'app_key'),
|
|
...
|
...
|
@@ -102,8 +117,9 @@ class Application |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $accessToken
|
|
|
|
* Set access token
|
|
|
|
*
|
|
|
|
* @param string $accessToken
|
|
|
|
* @return Application
|
|
|
|
*/
|
|
|
|
public function setAccessToken(string $accessToken): Application
|
|
...
|
...
|
@@ -114,6 +130,8 @@ class Application |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Match object
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return RequestProxy|object
|
|
|
|
* @throws RequestNotFoundException
|
|
...
|
...
|
@@ -136,9 +154,10 @@ class Application |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call object
|
|
|
|
*
|
|
|
|
* @param $name
|
|
|
|
* @param array $arguments
|
|
|
|
*
|
|
|
|
* @return RequestProxy
|
|
|
|
* @throws RequestNotFoundException
|
|
|
|
*/
|
...
|
...
|
|