作者 lackoxygen

feat:优化细节

... ... @@ -283,8 +283,6 @@ class Main
)
);
}
println('success!');
}
/**
... ... @@ -422,9 +420,9 @@ class Main
}
/**
* @return void
* @return string[]
*/
protected function refreshAnnotate()
protected function refreshAnnotate(): array
{
$queue = $this->codeSpace->toQueue();
... ... @@ -464,13 +462,81 @@ class Main
$content = file_get_contents($metaFile);
file_put_contents($metaFile, str_replace($ref->getDocComment(), $metaAnnotate, $content));
return $metaMethods;
}
/**
* @param array $metas
* @return void
*/
protected function createFacade(array $metas)
{
$facade = <<<FACADE
<?php
namespace Lackoxygen\TiktokShop\Facade;
use Lackoxygen\TiktokShop\Passage;
use Illuminate\Support\Facades\Facade;
use Lackoxygen\TiktokShop\Passage\Verify;
use Lackoxygen\TiktokShop\TiktokShop as TiktokShopKernel;
\${ANNOTATE}
class TiktokShop extends Facade
{
/**
* @return string
*/
protected static function getFacadeAccessor(): string
{
return TiktokShopKernel::class;
}
}
FACADE;
$keyword = '@method';
$metas = array_map(function ($meta) use ($keyword) {
$pos = strpos($meta, $keyword);
$left = substr($meta, 0, $pos + strlen($keyword));
$right = substr($meta, $pos + strlen($keyword));
return $left . ' static' . $right;
}, $metas);
array_unshift(
$metas,
' * @method static TiktokShopKernel setAccessToken(string $accessToken)',
' * @method static TiktokShopKernel use ($options)'
);
$metaAnnotate = '/**' . "\n";
$metaAnnotate .= join("\n", $metas) . "\n";
$metaAnnotate .= ' */';
$facadeContent = replaces(['${ANNOTATE}' => $metaAnnotate], $facade);
global $src_path;
file_put_contents(
$src_path . '/Facade/TiktokShop.php',
$facadeContent
);
}
public function __destruct()
{
$this->codeSpace->write();
$this->refreshAnnotate();
$metas = $this->refreshAnnotate();
$this->createFacade($metas);
println('success!');
}
}
... ...
... ... @@ -2,25 +2,40 @@
namespace Lackoxygen\TiktokShop\Facade;
use Lackoxygen\TiktokShop\Passage;
use Illuminate\Support\Facades\Facade;
use Lackoxygen\TiktokShop\Passage\Alliance\Alliance;
use Lackoxygen\TiktokShop\Passage\Authorize;
use Lackoxygen\TiktokShop\Passage\Order\OrderInterface;
use Lackoxygen\TiktokShop\Passage\Product\ProductInterface;
use Lackoxygen\TiktokShop\Passage\Shop\ShopInterface;
use Lackoxygen\TiktokShop\Passage\Verify;
use Lackoxygen\TiktokShop\TiktokShop as TiktokShopKernel;
/**
* @method static OrderInterface order()
* @method static ShopInterface shop()
* @method static ProductInterface product()
* @method static Authorize authorize()
* @method static Verify verify()
* @method static Alliance alliance()
* @method static TiktokShopKernel setAccessToken(string $accessToken)
* @method static TiktokShopKernel use ($options)
* @method static Verify verify()
* @method static Passage\Pigeon\PigeonInterface pigeon()
* @method static Passage\Sms\SmsInterface sms()
* @method static Passage\SupplyChain\SupplyChainInterface supplyChain()
* @method static Passage\Topup\TopupInterface topup()
* @method static Passage\OpenCloud\OpenCloudInterface openCloud()
* @method static Passage\Btas\BtasInterface btas()
* @method static Passage\Recycle\RecycleInterface recycle()
* @method static Passage\Member\MemberInterface member()
* @method static Passage\Buyin\BuyinInterface buyin()
* @method static Passage\Yunc\YuncInterface yunc()
* @method static Passage\OrderCode\OrderCodeInterface orderCode()
* @method static Passage\Coupons\CouponsInterface coupons()
* @method static Passage\Crossborder\CrossborderInterface crossborder()
* @method static Passage\Iop\IopInterface iop()
* @method static Passage\Antispam\AntispamInterface antispam()
* @method static Passage\Token\TokenInterface token()
* @method static Passage\Order\OrderInterface order()
* @method static Passage\AfterSale\AfterSaleInterface afterSale()
* @method static Passage\Logistics\LogisticsInterface logistics()
* @method static Passage\Warehouse\WarehouseInterface warehouse()
* @method static Passage\Product\ProductInterface product()
* @method static Passage\Material\MaterialInterface material()
* @method static Passage\Address\AddressInterface address()
*/
class TiktokShop extends Facade
{
/**
... ...
... ... @@ -8,7 +8,7 @@ use Lackoxygen\TiktokShop\Passage\PassageProxy;
use Lackoxygen\TiktokShop\Passage\Verify;
/**
*@method Verify verify()
* @method Verify verify()
* @method Passage\Pigeon\PigeonInterface pigeon()
* @method Passage\Sms\SmsInterface sms()
* @method Passage\SupplyChain\SupplyChainInterface supplyChain()
... ...