PHP Classes

File: src/Traits/XrCurlTrait.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   XR PHP Debugger Online   src/Traits/XrCurlTrait.php   Download  
File: src/Traits/XrCurlTrait.php
Role: Class source
Content type: text/plain
Description: Class source
Class: XR PHP Debugger Online
Debug PHP code using a Web interface
Author: By
Last change:
Date: 1 year ago
Size: 1,065 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <rodolfo@chevere.org>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Chevere\Xr\Traits;

use
CurlHandle;

trait
XrCurlTrait
{
    private ?
CurlHandle $handle = null;

    public function
__construct(string $url = null)
    {
       
$this->handle = curl_init($url);
    }

    public function
handle(): ?CurlHandle
   
{
        return
$this->handle;
    }

    public function
error(): string
   
{
        return
curl_error($this->handle);
    }

    public function
exec(): string|bool
   
{
        return
curl_exec($this->handle);
    }

    public function
setOptArray(array $options): bool
   
{
        return
curl_setopt_array($this->handle, $options);
    }

    public function
close(): void
   
{
       
curl_close($this->handle);
    }

    public function
__destruct()
    {
        if (isset(
$this->handle)) {
           
$this->close();
        }
    }
}