<?php
namespace app\models\logics\commands\base;

use app\common\CurlApp;

class BaseCommandSpiderLogic
{

    protected ?CurlApp $curl = null;

    protected string $brandName = '';

    protected string $baseUrl = '';

    public function __construct()
    {
        ini_set('pcre.backtrack_limit', '-1');
        $this->curl = new CurlApp();
    }

    public function exec()
    {

        $url = rtrim($this->baseUrl, '/') . '/fashion-shows/designer/' . $this->brandName;
//        var_dump($url);
//        list($request, $httpCode) = $curl->setUrl($url)->exec();
        $request = $this->curl->setUrl($url)->exec();

        if ($request) {
            preg_match_all('/window.__PRELOADED_STATE__ = ([\s\S]*?);<\/script>/', $request, $matches);
            $val = json_decode(current(end($matches)), true);
            return $val['transformed']['runwayDesignerContent']['designerCollections'] ?? [];
        } else {
//            $this->logger->info('未找到数据.');
            return [];
        }
    }
}