argument('name'); if (! preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $name)) { $this->error("Invalid class name: [{$name}]. Must be a valid PHP class name."); return self::FAILURE; } $directory = app_path('Cart/Drivers'); $path = "{$directory}/{$name}.php"; if (file_exists($path)) { $this->error("Driver already exists: app/Cart/Drivers/{$name}.php"); return self::FAILURE; } if (! is_dir($directory)) { mkdir($directory, 0755, true); } if (file_put_contents($path, static::stub($name)) === false) { $this->error("Failed to write file: {$path}"); return self::FAILURE; } $this->info("Driver created: app/Cart/Drivers/{$name}.php"); $this->line(" Register it with Cart::extend() in a service provider's boot() method, then set 'driver' to its name in config/cart.php."); return self::SUCCESS; } public static function stub(string $className): string { return <<sessionKey = \$sessionKey; } public function getSessionKey(): string { return \$this->sessionKey; } public function setSessionKey(string \$sessionKey): void { \$this->sessionKey = \$sessionKey; } public function getDriverName(): string { return 'custom'; } public function getItems(): array { // TODO: retrieve items from your storage backend return []; } public function putItems(array \$items): void { // TODO: persist items to your storage backend } public function getConditions(): array { // TODO: retrieve conditions from your storage backend return []; } public function putConditions(array \$conditions): void { // TODO: persist conditions to your storage backend } public function clearItems(): void { // TODO: remove only items from your storage backend } public function flush(): void { // TODO: remove both items and conditions from your storage backend } public function getSessionModel(): mixed { return null; } } PHP; } }