作者 lackoxygen

feat:优化细节

@@ -283,8 +283,6 @@ class Main @@ -283,8 +283,6 @@ class Main
283 ) 283 )
284 ); 284 );
285 } 285 }
286 -  
287 - println('success!');  
288 } 286 }
289 287
290 /** 288 /**
@@ -422,9 +420,9 @@ class Main @@ -422,9 +420,9 @@ class Main
422 } 420 }
423 421
424 /** 422 /**
425 - * @return void 423 + * @return string[]
426 */ 424 */
427 - protected function refreshAnnotate() 425 + protected function refreshAnnotate(): array
428 { 426 {
429 $queue = $this->codeSpace->toQueue(); 427 $queue = $this->codeSpace->toQueue();
430 428
@@ -464,13 +462,81 @@ class Main @@ -464,13 +462,81 @@ class Main
464 $content = file_get_contents($metaFile); 462 $content = file_get_contents($metaFile);
465 463
466 file_put_contents($metaFile, str_replace($ref->getDocComment(), $metaAnnotate, $content)); 464 file_put_contents($metaFile, str_replace($ref->getDocComment(), $metaAnnotate, $content));
  465 +
  466 + return $metaMethods;
  467 + }
  468 +
  469 + /**
  470 + * @param array $metas
  471 + * @return void
  472 + */
  473 + protected function createFacade(array $metas)
  474 + {
  475 + $facade = <<<FACADE
  476 +<?php
  477 +
  478 +namespace Lackoxygen\TiktokShop\Facade;
  479 +
  480 +use Lackoxygen\TiktokShop\Passage;
  481 +use Illuminate\Support\Facades\Facade;
  482 +use Lackoxygen\TiktokShop\Passage\Verify;
  483 +use Lackoxygen\TiktokShop\TiktokShop as TiktokShopKernel;
  484 +
  485 +\${ANNOTATE}
  486 +
  487 +class TiktokShop extends Facade
  488 +{
  489 + /**
  490 + * @return string
  491 + */
  492 + protected static function getFacadeAccessor(): string
  493 + {
  494 + return TiktokShopKernel::class;
  495 + }
  496 +}
  497 +FACADE;
  498 +
  499 + $keyword = '@method';
  500 +
  501 + $metas = array_map(function ($meta) use ($keyword) {
  502 + $pos = strpos($meta, $keyword);
  503 +
  504 + $left = substr($meta, 0, $pos + strlen($keyword));
  505 +
  506 + $right = substr($meta, $pos + strlen($keyword));
  507 +
  508 + return $left . ' static' . $right;
  509 + }, $metas);
  510 +
  511 + array_unshift(
  512 + $metas,
  513 + ' * @method static TiktokShopKernel setAccessToken(string $accessToken)',
  514 + ' * @method static TiktokShopKernel use ($options)'
  515 + );
  516 +
  517 + $metaAnnotate = '/**' . "\n";
  518 + $metaAnnotate .= join("\n", $metas) . "\n";
  519 + $metaAnnotate .= ' */';
  520 +
  521 + $facadeContent = replaces(['${ANNOTATE}' => $metaAnnotate], $facade);
  522 +
  523 + global $src_path;
  524 +
  525 + file_put_contents(
  526 + $src_path . '/Facade/TiktokShop.php',
  527 + $facadeContent
  528 + );
467 } 529 }
468 530
469 public function __destruct() 531 public function __destruct()
470 { 532 {
471 $this->codeSpace->write(); 533 $this->codeSpace->write();
472 534
473 - $this->refreshAnnotate(); 535 + $metas = $this->refreshAnnotate();
  536 +
  537 + $this->createFacade($metas);
  538 +
  539 + println('success!');
474 } 540 }
475 } 541 }
476 542
@@ -2,25 +2,40 @@ @@ -2,25 +2,40 @@
2 2
3 namespace Lackoxygen\TiktokShop\Facade; 3 namespace Lackoxygen\TiktokShop\Facade;
4 4
  5 +use Lackoxygen\TiktokShop\Passage;
5 use Illuminate\Support\Facades\Facade; 6 use Illuminate\Support\Facades\Facade;
6 -use Lackoxygen\TiktokShop\Passage\Alliance\Alliance;  
7 -use Lackoxygen\TiktokShop\Passage\Authorize;  
8 -use Lackoxygen\TiktokShop\Passage\Order\OrderInterface;  
9 -use Lackoxygen\TiktokShop\Passage\Product\ProductInterface;  
10 -use Lackoxygen\TiktokShop\Passage\Shop\ShopInterface;  
11 use Lackoxygen\TiktokShop\Passage\Verify; 7 use Lackoxygen\TiktokShop\Passage\Verify;
12 use Lackoxygen\TiktokShop\TiktokShop as TiktokShopKernel; 8 use Lackoxygen\TiktokShop\TiktokShop as TiktokShopKernel;
13 9
14 /** 10 /**
15 - * @method static OrderInterface order()  
16 - * @method static ShopInterface shop()  
17 - * @method static ProductInterface product()  
18 - * @method static Authorize authorize()  
19 - * @method static Verify verify()  
20 - * @method static Alliance alliance()  
21 * @method static TiktokShopKernel setAccessToken(string $accessToken) 11 * @method static TiktokShopKernel setAccessToken(string $accessToken)
22 * @method static TiktokShopKernel use ($options) 12 * @method static TiktokShopKernel use ($options)
  13 + * @method static Verify verify()
  14 + * @method static Passage\Pigeon\PigeonInterface pigeon()
  15 + * @method static Passage\Sms\SmsInterface sms()
  16 + * @method static Passage\SupplyChain\SupplyChainInterface supplyChain()
  17 + * @method static Passage\Topup\TopupInterface topup()
  18 + * @method static Passage\OpenCloud\OpenCloudInterface openCloud()
  19 + * @method static Passage\Btas\BtasInterface btas()
  20 + * @method static Passage\Recycle\RecycleInterface recycle()
  21 + * @method static Passage\Member\MemberInterface member()
  22 + * @method static Passage\Buyin\BuyinInterface buyin()
  23 + * @method static Passage\Yunc\YuncInterface yunc()
  24 + * @method static Passage\OrderCode\OrderCodeInterface orderCode()
  25 + * @method static Passage\Coupons\CouponsInterface coupons()
  26 + * @method static Passage\Crossborder\CrossborderInterface crossborder()
  27 + * @method static Passage\Iop\IopInterface iop()
  28 + * @method static Passage\Antispam\AntispamInterface antispam()
  29 + * @method static Passage\Token\TokenInterface token()
  30 + * @method static Passage\Order\OrderInterface order()
  31 + * @method static Passage\AfterSale\AfterSaleInterface afterSale()
  32 + * @method static Passage\Logistics\LogisticsInterface logistics()
  33 + * @method static Passage\Warehouse\WarehouseInterface warehouse()
  34 + * @method static Passage\Product\ProductInterface product()
  35 + * @method static Passage\Material\MaterialInterface material()
  36 + * @method static Passage\Address\AddressInterface address()
23 */ 37 */
  38 +
24 class TiktokShop extends Facade 39 class TiktokShop extends Facade
25 { 40 {
26 /** 41 /**
@@ -8,7 +8,7 @@ use Lackoxygen\TiktokShop\Passage\PassageProxy; @@ -8,7 +8,7 @@ use Lackoxygen\TiktokShop\Passage\PassageProxy;
8 use Lackoxygen\TiktokShop\Passage\Verify; 8 use Lackoxygen\TiktokShop\Passage\Verify;
9 9
10 /** 10 /**
11 - *@method Verify verify() 11 + * @method Verify verify()
12 * @method Passage\Pigeon\PigeonInterface pigeon() 12 * @method Passage\Pigeon\PigeonInterface pigeon()
13 * @method Passage\Sms\SmsInterface sms() 13 * @method Passage\Sms\SmsInterface sms()
14 * @method Passage\SupplyChain\SupplyChainInterface supplyChain() 14 * @method Passage\SupplyChain\SupplyChainInterface supplyChain()