<commit_before><?php
/**
 * User: <NAME> <<EMAIL>>
 */

namespace Praxigento\Core\App\Api\Web\Authenticator;

use Praxigento\Core\App\Api\Web\Request as ARequest;
use Praxigento\Core\App\Api\Web\Request\Dev as ADev;

/**
 * MOBI Authenticator for frontend (regular customer authentication),
 */
class Front
    implements \Praxigento\Core\App\Api\Web\IAuthenticator
{
    /** @var int|bool|null */
    private $cacheId = false;
    /** @var \Praxigento\Core\Helper\Config */
    private $hlpCfg;
    /** @var \Magento\Customer\Model\Session */
    private $session;

    public function __construct(
        \Magento\Customer\Model\Session $sessCustomer,
        \Praxigento\Core\Helper\Config $hlpCfg
    ) {
        $this->session = $sessCustomer;
        $this->hlpCfg = $hlpCfg;
    }

    public function getCurrentUserId(ARequest $request = null)
    {
        /* $cacheId can be equal to 'null' if no customer is anonymous */
        if ($this->cacheId === false) {
            $offeredId = null;
            if ($request) {
                $path = ARequest::PS . ARequest::DEV . ARequest::PS . ADev::CUST_ID;
                $offeredId = $request->get($path);
            }
            if (
                $this->hlpCfg->getApiAuthenticationEnabledDevMode() &&
                !is_null($offeredId)
            ) {
                /* use offered Customer ID if MOBI API DevMode is enabled */
                $this->cacheId = (int)$offeredId;
            } else {
                /* get currently logged in customer data */
                $customer = $this->session->getCustomer();
                if ($customer) {
                    $this->cacheId = $customer->getId();
                }
            }
        }
        return $this->cacheId;
    }
}<commit_msg>MOBI-1071 Change authenticator for services (session ID should be preferred)<commit_after><?php
/**
 * User: <NAME> <<EMAIL>>
 */

namespace Praxigento\Core\App\Api\Web\Authenticator;

use Praxigento\Core\App\Api\Web\Request as ARequest;
use Praxigento\Core\App\Api\Web\Request\Dev as ADev;

/**
 * MOBI Authenticator for frontend (regular customer authentication),
 */
class Front
    implements \Praxigento\Core\App\Api\Web\IAuthenticator
{
    /** @var int|bool|null */
    private $cacheId = false;
    /** @var \Praxigento\Core\Helper\Config */
    private $hlpCfg;
    /** @var \Magento\Customer\Model\Session */
    private $session;

    public function __construct(
        \Magento\Customer\Model\Session $sessCustomer,
        \Praxigento\Core\Helper\Config $hlpCfg
    ) {
        $this->session = $sessCustomer;
        $this->hlpCfg = $hlpCfg;
    }

    public function getCurrentUserId(ARequest $request = null)
    {
        /* $cacheId can be equal to 'null' if no customer is anonymous */
        if ($this->cacheId === false) {
            /* get currently logged in customer data */
            $customer = $this->session->getCustomer();
            if ($customer) {
                $this->cacheId = $customer->getId();
            }
            /* get ID from request if session is not established */
            if (!$this->cacheId) {
                $offeredId = null;
                if ($request) {
                    $path = ARequest::PS . ARequest::DEV . ARequest::PS . ADev::CUST_ID;
                    $offeredId = $request->get($path);
                }
                if (
                    $this->hlpCfg->getApiAuthenticationEnabledDevMode() &&
                    !is_null($offeredId)
                ) {
                    /* use offered Customer ID if MOBI API DevMode is enabled */
                    $this->cacheId = (int)$offeredId;
                }
            }
        }
        return $this->cacheId;
    }
}
{'fraction_non_alphanumeric': 0.1289198606271777, 'fraction_numerical': 0.0010720986330742428, 'mean_word_length': 1.8401826484018264, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3002674', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1090, 'n_words': 237}