HEX
Server: Apache
System: Linux p3plzcpnl506847.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: slfopp7cb1df (5698090)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //home/slfopp7cb1df/public_html/home/wp-content/plugins/mailoptin/src/authifly/src/Data/Parser.php
<?php
/*!
* Authifly
* https://hybridauth.github.io | https://github.com/mailoptin/authifly
*  (c) 2017 Hybridauth authors | https://hybridauth.github.io/license.html
*/

namespace Authifly\Data;

/**
 * Parser
 *
 * This class is used to parse plain text into objects. It's used by hybriauth adapters to converts
 * providers api responses to a more 'manageable' format.
 */
final class Parser
{
    /**
    * Decodes a string into an object.
    *
    * This method will first attempt to parse data as a JSON string (since most providers use this format)
    * then parse_str.
    *
    * @param string $raw
    *
    * @return mixed
    */
    public function parse($raw = null)
    {
        $data = $this->parseJson($raw);

        if (! $data) {
            $data = $this->parseQueryString($raw);
        }

        return $data;
    }

    /**
    * Decodes a JSON string
    *
    * @param $result
    *
    * @return mixed
    */
    public function parseJson($result)
    {
        return json_decode($result);
    }

    /**
    * Parses a string into variables
    *
    * @param $result
    *
    * @return \StdClass
    */
    public function parseQueryString($result)
    {
        parse_str($result, $output);

        if (! is_array($output)) {
            return $result;
        }

        $result = new \StdClass();

        foreach ($output as $k => $v) {
            $result->$k = $v;
        }

        return $result;
    }

    /**
    * needs to be improved
    */
    public function parseBirthday($birthday, $seperator)
    {
        $birthday = date_parse($birthday);

        return [ $birthday['year'], $birthday['month'], $birthday['day'] ];
    }
}