HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
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/html/wpmuhibbah/wp-content/plugins/give/src/Framework/FieldsAPI/Concerns/HasOptions.php
<?php

namespace Give\Framework\FieldsAPI\Concerns;

use Give\Framework\FieldsAPI\Option;

trait HasOptions
{

    /** @var Option[] */
    protected $options = [];

    /**
     * Set the options
     *
     * Note that the keys of associative arrays are not supported for setting values or labels.
     * For setting labels either use `new FieldOption($value, $label)` or `[$value, $label]`.
     * In either case, the label is optional.
     *
     * @param Option|array|mixed ...$options
     *
     * @return $this
     */
    public function options(...$options)
    {
        // Reset options, since they are meant to be set immutably
        $this->options = [];

        // Loop through the options and transform them to the proper format.
        foreach ($options as $value) {
            if ($value instanceof Option) {
                // In this case, what is provided matches the proper format, so we can just append it.
                $this->options[] = $value;
            } elseif (is_array($value)) {
                // In this case, what has been provided in the value is an array with a value then a label.
                // This matches the constructor of `FieldOption`, so we can unpack it as arguments for a new instance.
                $this->options[] = new Option(...$value);
            } else {
                // In this case, we just have a value which is the bare minimum required for a `FieldOption`.
                $this->options[] = new Option($value);
            }
        }

        return $this;
    }

    /**
     * Access the options
     *
     * @return Option[]
     */
    public function getOptions()
    {
        return $this->options;
    }

    /**
     * Check whether options exist
     *
     * @since 2.15.0
     *
     * @return bool
     */
    public function hasOptions()
    {
        return (bool)count($this->options);
    }

    /**
     * Walk through the options
     *
     * @since 2.12.0
     *
     * @param callable $callback
     *
     * @return void
     */
    public function walkOptions(callable $callback)
    {
        foreach ($this->options as $option) {
            // Call the callback for each option.
            if ($callback($option) === false) {
                // Returning false breaks the loop.
                break;
            }
        }
    }
}