Класс, который у вас не находится, реализуется не в ларавелевском коннекторе, а в расширении, которое нужно устанавливать отдельно.
Проблема в вашем неумении читать документацию, всё остальное работает как должно.
{
"name": "laravel/laravel",
"type": "project",
"description": "The skeleton application for the Laravel framework.",
"keywords": ["laravel", "framework"],
"license": "MIT",
"require": {
"php": "^8.1",
"amphp/amp": "^3.0",
"amphp/http-client": "^5.0",
"guzzlehttp/guzzle": "^7.8",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"swooletw/laravel-swoole": "^2.13"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
<?php declare(strict_types=1);
namespace App\Models\Modules\Api\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Swoole\Runtime;
use Swoole\Coroutine\Http\Client;
class ApiGetter extends Model
{
protected string $apiUrl;
protected string $baseUrl = 'https://api.cargo.tech/v1/';
protected int $limit;
public function __construct($requestUrl, $limit)
{
$this->apiUrl = $this->baseUrl . $requestUrl;
$this->limit = $limit;
}
public function getItems(int $itemsCount, int $offset = 0): Collection
{
$url = $this->apiUrl;
$limit = $this->limit;
$data = new Collection();
Swoole\Runtime::enableCoroutine();
// Создаем массив для хранения корутин
$coroutines = [];
for ($page = $offset; $page < $offset + $itemsCount; $page++) {
$urlWithParams = $url . "?limit={$limit}&offset=$page";
// Создаем корутину для каждого запроса
$coroutines[] = go(function () use ($urlWithParams) {
$client = new Client($urlWithParams);
$client->get();
if ($client->statusCode === 200) {
$response = $client->body;
$responseData = json_decode($response, true);
$data->push(...$responseData['data']);
}
$client->close();
});
}
// Дожидаемся завершения всех корутин
foreach ($coroutines as $coroutine) {
$coroutine->join();
}
return $data;
}
setTimeout(await page.close, 10);
setTimeout(page.close, 10);
setTimeout(page.close(), 10);
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
^
TypeError: Cannot read private member from an object whose class did not declare it
at __classPrivateFieldGet (/Users/gera/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:19:94)
at Timeout.close [as _onTimeout] (/Users/gera/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:781:28)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
^
TypeError: Cannot read private member from an object whose class did not declare it
at __classPrivateFieldGet (/Users/gera/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:19:94)
at Timeout.close [as _onTimeout] (/Users/gera/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js:781:28)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)