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/demo.sports-crowd.com/vendor/viewflex/zoap/src/Demo/DemoService.php
<?php

namespace Viewflex\Zoap\Demo;


use SoapFault;
use Viewflex\Zoap\Demo\DemoProvider as Provider;

/**
 * An example of a class that is used as a SOAP gateway to application functions.
 */
class DemoService
{
    /*
    |--------------------------------------------------------------------------
    | Public Methods
    |--------------------------------------------------------------------------
    */
    
    /**
     * Authenticates user/password, returning status of true with token, or throws SoapFault.
     *
     * @param string $user
     * @param string $password
     * @return array
     * @throws SoapFault
     */
    public function auth($user, $password)
    {

        if (Provider::validateUser($user, $password)) {
            return ['status' => 'true', 'token' => Provider::getToken($user)];
        } else {
            header("Status: 401");
            throw new SoapFault('SOAP-ENV:Client', 'Incorrect credentials.');

        }

    }

    /**
     * Returns boolean authentication result using given token or user/password.
     *
     * @param string $token
     * @param string $user
     * @param string $password
     * @return bool
     */
    public function ping($token = '', $user = '', $password = '')
    {
        return Provider::authenticate($token, $user, $password);
    }

    /**
     * Returns a product by id.
     *
     * @param int $productId
     * @param string $token
     * @param string $user
     * @param string $password
     * @return \Viewflex\Zoap\Demo\Types\Product
     * @throws SoapFault
     */
    public function getProduct($productId, $token = '', $user = '', $password = '')
    {

        if (! $productId) {
            header("Status: 400");
            throw new SoapFault('SOAP-ENV:Client', 'Please specify product id.');
        }

        if (! Provider::authenticate($token, $user, $password)) {
            header("Status: 401");
            throw new SoapFault('SOAP-ENV:Client', 'Incorrect credentials.');
        }

        return Provider::findProduct($productId);
    }

    /**
     * Returns an array of products by search criteria.
     *
     * @param \Viewflex\Zoap\Demo\Types\KeyValue[] $criteria
     * @param string $token
     * @param string $user
     * @param string $password
     * @return \Viewflex\Zoap\Demo\Types\Product[]
     * @throws SoapFault
     */
    public function getProducts($criteria = [], $token = '', $user = '', $password = '')
    {

        if (! Provider::authenticate($token, $user, $password)) {
            header("Status: 401");
            throw new SoapFault('SOAP-ENV:Client', 'Incorrect credentials.');
        }

        return Provider::findProductsBy(self::arrayOfKeyValueToArray($criteria));

    }

    /*
    |--------------------------------------------------------------------------
    | Utility
    |--------------------------------------------------------------------------
    */
    
    /**
     * Convert array of KeyValue objects to associative array, non-recursively.
     *
     * @param \Viewflex\Zoap\Demo\Types\KeyValue[] $objects
     * @return array
     */
    protected static function arrayOfKeyValueToArray($objects)
    {
        $return = array();
        foreach ($objects as $object) {
            $return[$object->key] = $object->value;
        }

        return $return;
    }

}