HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/csharpru/vault-php/src/BaseObject.php
<?php

namespace Vault;

use RuntimeException;
use Vault\Helpers\ArrayHelper;

/**
 * Class Object
 *
 * @package Vault
 */
class BaseObject
{
    /**
     * Object constructor.
     *
     * @param array $config
     */
    public function __construct(array $config = [])
    {
        if (!empty($config)) {
            foreach ($config as $name => $value) {
                if (!$this->canSetProperty($name)) {
                    continue;
                }

                $this->$name = $value;
            }
        }
    }

    /**
     * @param string $name
     * @param bool $checkVars
     *
     * @return bool
     */
    public function canSetProperty($name, $checkVars = true): bool
    {
        return method_exists($this, 'set' . $name) || ($checkVars && property_exists($this, $name));
    }

    /**
     * @param $name
     *
     * @return mixed
     *
     * @throws RuntimeException
     */
    public function __get($name)
    {
        $getter = 'get' . $name;

        if (method_exists($this, $getter)) {
            return $this->$getter();
        }

        if (method_exists($this, 'set' . $name)) {
            throw new RuntimeException('Getting write-only property: ' . get_class($this) . '::' . $name);
        }

        throw new RuntimeException('Getting unknown property: ' . get_class($this) . '::' . $name);
    }

    /**
     * @param string $name
     * @param mixed $value
     *
     * @throws RuntimeException
     */
    public function __set($name, $value)
    {
        $setter = 'set' . $name;

        if (method_exists($this, $setter)) {
            $this->$setter($value);
        } elseif (method_exists($this, 'get' . $name)) {
            throw new RuntimeException('Setting read-only property: ' . get_class($this) . '::' . $name);
        } else {
            throw new RuntimeException('Setting unknown property: ' . get_class($this) . '::' . $name);
        }
    }

    /**
     * @param string $name
     *
     * @return bool
     */
    public function __isset($name)
    {
        $getter = 'get' . $name;

        if (method_exists($this, $getter)) {
            return $this->$getter() !== null;
        }

        return false;
    }

    /**
     * @param string $name
     *
     * @throws RuntimeException
     */
    public function __unset($name)
    {
        $setter = 'set' . $name;

        if (method_exists($this, $setter)) {
            $this->$setter(null);
        } elseif (method_exists($this, 'get' . $name)) {
            throw new RuntimeException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
        }
    }

    /**
     * @param string $name
     * @param array $params
     *
     * @throws RuntimeException
     */
    public function __call($name, $params)
    {
        throw new RuntimeException('Unknown method: ' . get_class($this) . "::$name()");
    }

    /**
     * @param string $name
     * @param bool $checkVars
     *
     * @return bool
     */
    public function hasProperty($name, $checkVars = true): bool
    {
        return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
    }

    /**
     * @param string $name
     * @param bool $checkVars
     *
     * @return bool
     */
    public function canGetProperty($name, $checkVars = true): bool
    {
        return method_exists($this, 'get' . $name) || ($checkVars && property_exists($this, $name));
    }

    /**
     * @param string $name
     *
     * @return bool
     */
    public function hasMethod($name): bool
    {
        return method_exists($this, $name);
    }

    /**
     * @param bool $recursive
     *
     * @return array
     */
    public function toArray($recursive = true): array
    {
        $data = [];

        foreach ($this->getFields() as $field => $definition) {
            $data[$field] = is_string($definition) ? $this->$definition : $definition($this, $field);
        }

        return $recursive ? ArrayHelper::toArray($data, $recursive) : $data;
    }

    /**
     * @return array
     */
    public function getFields(): array
    {
        $result = [];

        $fields = array_keys(get_object_vars($this));
        $fields = array_combine($fields, $fields);

        foreach ($fields as $field => $definition) {
            if (is_int($field)) {
                $field = $definition;
            }

            $result[$field] = $definition;
        }

        return $result;
    }
}