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/Session/SessionDonation/DonationAccessor.php
<?php

namespace Give\Session\SessionDonation;

use DateTime;
use Give\Session\Accessor;
use Give\Session\SessionDonation\SessionObjects\Donation as DonationObject;
use Give\Session\SessionDonation\SessionObjects\FormEntry;

/**
 * Class Donation
 *
 * This class provide way to access donation session data.
 *
 * @package Give\Session\Access
 *
 * @method DonationObject get
 */
class DonationAccessor extends Accessor
{
    /**
     * Session Id
     *
     * @since 2.7.0
     * @var string
     */
    protected $sessionKey = 'give_purchase';

    /**
     * Donation object.
     *
     * Since 2.7.0
     *
     * @var DonationObject
     */
    protected $dataObj;

    /**
     * property vs session key array.
     * It is useful to map array keys to class properties.
     *
     * @var array
     */
    private $renameTo = [
        'user_email' => 'donorEmail',
        'user_info' => 'donorInfo',
        'post_data' => 'formEntry',
        'donation_id' => 'id',
        'price' => 'totalAmount',
        'gateway' => 'paymentGateway',
        'date' => 'createdAt',
    ];

    /**
     * Map array keys to class properties
     *
     * @since 2.7.0
     *
     * @param array $data
     *
     * @return DonationObject
     */
    protected function convertToObject($data)
    {
        if ( ! $data) {
            return null;
        }

        // Cast date string to DateTime object.
        $data['date'] = DateTime::createFromFormat('Y-m-d H:i:s', $data['date']);

        // Rename key if property name exist for them.
        foreach ($data as $key => $value) {
            if (array_key_exists($key, $this->renameTo)) {
                $data[$this->renameTo[$key]] = $value;
                unset($data[$key]);
            }
        }

        // Rename unknown keys.
        $data = $this->renameArrayKeysToPropertyNames($data);

        return DonationObject::fromArray($data);
    }

    /**
     * Get donation id.
     *
     * @since 2.7.0
     * @return int
     *
     */
    public function getDonationId()
    {
        if ($donationId = $this->getByKey('id')) {
            return absint($donationId);
        }

        return null;
    }

    /**
     * Get donation id.
     *
     * @since 2.7.0
     * @return int
     *
     */
    public function getFormId()
    {
        /* @var FormEntry $data */
        if ($data = $this->getByKey('formEntry')) {
            return absint($data->formId);
        }

        return null;
    }
}