PHP code example of sholokhov / bitrix-option

1. Go to this page and download the library: Download sholokhov/bitrix-option library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sholokhov / bitrix-option example snippets

injectablephp
use Sholokhov\BitrixOption\StorageInterface;

class ConnectionDTO implements StorageInterface
{
    public int $port;
    public string $host;
    public string $login;
    
    public function __toString(): string
    {
        return $this->toString();
    }

    public function toString(): string
    {
        return json_encode([
            'port' => $this->port,
            'host' => $this->host, 
            'login' => $this->login
        ]);
    }

    public static function fromString(string $value): self
    {
        $data = json_decode($value, JSON_OBJECT_AS_ARRAY);

        $connection = new self();
        $connection->port = intval($data['port'] ?? 22);
        $connection->host = (string)($data['host'] ?? '');
        $connection->login = (string)($data['login'] ?? '');
        
        return $connection;
    }
}
injectablephp
$result = $manager->save();

if (!$result->isSuccess()) {
    your code ...
}