Encode a PHP object into a JSON string.

@param object|array $input A PHP object or array

@return string JSON representation of the PHP object or array
336153
public static function jsonEncode($input)
    {
        $json = json_encode($input);

        if ($json === 'null' && $input !== null) {
            throw new DomainException('Null result with non-null input');
        }

        return $json;
    }
269334
protected function encryptMcrypt($input)
    {
        $ivlen = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
        $iv    = mcrypt_create_iv($ivlen, MCRYPT_RAND);
        $key   = $this->getEncryptionSaltKey();

        return $iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $input, MCRYPT_MODE_CBC, $iv);
    }
260430
protected static function Base64UrlEncode( $input ) {
			/**
			 * IMPORTANT NOTE:
			 * This is a hack suggested by @otto42 and @greenshady from
			 * the theme's review team. The usage of base64 for API
			 * signature encoding was approved in a Slack meeting
			 * held on Tue (10/25 2016).
			 *
			 * @todo Remove this hack once the base64 error is removed from the Theme Check.
			 *
			 * @since 1.2.2
			 * @author Vova Feldman (@svovaf)
			 */
			$fn = 'base64' . '_encode';
			$str = strtr( $fn( $input ), '+/', '-_' );
			$str = str_replace( '=', '', $str );

			return $str;
		}
609079
protected function generateRequestOptions( $input ) {
    $options = [
      'dataType' => 'json',
      'headers' => array_merge(self::$header, (array)$input['header']),
    ];
    $options = array_merge($options, ArrayUtils::array_pick($input, 'json', 'form', 'query'));
    return $options;
  }
37880
private function getOutput($input)
	{
		$return = Api::decrypt($this->createkey() , $input);
		if (!is_array($return)) {
			ob_start();
			$return = json_decode(trim(base64_decode($input)), true);
			ob_end_clean();
		}
		if (!is_array($return)) {
			$this->error[] = 'JfusionAPI: error output: ' . $input;
			return false;
		} else if (isset($return['PHPSESSID'])) {
			$this->sid = $return['PHPSESSID'];
		}

		if (isset($return['debug'])) {
			$this->debug = $return['debug'];
		}
		if (isset($return['error']) && !empty($return['error'])) {
			return false;
		} else if (isset($return['payload'])) {
			return $return['payload'];
		}
		return true;
	}
238539
protected function value($input)
    {
        $output = $input;

        if (is_string($input) === false) {
            switch (gettype($input)) {
                case 'boolean':
                    $output = ($input === true) ? 'true' : 'false';
                    break;
                case 'integer':
                case 'double':
                    $output = (string) $input;
                    break;
                case 'object':
                case 'array':
                case 'resource':
                case 'unknown type':
                    $output = serialize($input);
                    break;
                case 'NULL':
                default:
                    // intentionally omitted
                    break;
            }
        }

        return $output;
    }
1332027
public function formatString($input)
    {
        if (is_array($input)) {
            $input = join(', ', $input);
        }
        $output = strip_tags($input);
        $output = str_replace(array("\r", "\n"), array(' ', ' '), $output);
        
        $output = $this->filterCsvInjection($output);
        
        return $output;
    }
1333185
public static function toJson($input = false, $pretty = false) {

        if ($input) {

            switch (Data::type($input)) {
                case 'array':
                    $json = self::arrayToJson($input, $pretty);
                    break;
                case 'object':
                    $json = self::objectToJson($input, $pretty);
                    break;
                default:
                    $json = false;
                    break;
            }

            if (Validate::isJson($json)) {

                return $json;
            }
        }

        return false;
    }
36513
private function inputsArray($jsonInput)
    {
        if ($jsonInput) {
            $inputs = Input::json();
        } else {
            $inputs = Input::all();

            // Don't send the token back
            unset($inputs['_token']);

            foreach ($inputs as $key => $value) {
                if (Input::file($key)) {
                    unset($inputs[$key]);
                }
            }
        }

        return $inputs;
    }
1099713
function encrypt($input)
    {
        // Create a random IV. Not using mcrypt to generate one, as to not have a dependency on it.
        $iv = substr(uniqid("", true), 0, Cipher::IV_SIZE);
        // Encrypt the data
        $encrypted = openssl_encrypt($input, "AES-256-CBC", $this->secretKey, 0, $iv);
        // Encode the data with IV as prefix
        return base64_encode($iv . $encrypted);
    }
957944
protected function toBuffer($input)
    {
        if (is_string($input)) {
            if (strpos($input, '0x') === 0) {
                // hex string
                // $input = str_replace('0x', '', $input);
                return new Buffer($input, 'hex');
            }
            return new Buffer(str_split($input, 1));
        } elseif (is_numeric($input)) {
            if (!$input || $input < 0) {
                return new Buffer([]);
            }
            if (is_float($input)) {
                $input = number_format($input, 0, '', '');
                var_dump($input);
            }
            $gmpInput = gmp_init($input, 10);
            return new Buffer('0x' . gmp_strval($gmpInput, 16), 'hex');
        } elseif ($input === null) {
            return new Buffer([]);
        } elseif (is_array($input)) {
            return new Buffer($input);
        } elseif ($input instanceof Buffer) {
            return $input;
        }
        throw new InvalidArgumentException('The input type didn\'t support.');
    }
202701
public function encode($input)
    {
        $chars = [
            '&#x102;' => 'a',
            '&#x103;' => 'a',
            '&#xC2;' => 'A',
            '&#xE2;' => 'a',
            '&#xCE;' => 'I',
            '&#xEE;' => 'i',
            '&#x218;' => 'S',
            '&#x219;' => 's',
            '&#x15E;' => 'S',
            '&#x15F;' => 's',
            '&#x21A;' => 'T',
            '&#x21B;' => 't',
            '&#354;' => 'T',
            '&#355;' => 't'
        ];

        $change = $with = [];
        foreach ($chars as $i => $v) {
            $change[] = html_entity_decode($i, ENT_QUOTES, 'UTF-8');
            $with[] = $v;
        }
        $input = str_replace($change, $with, $input);

        preg_match_all("/[a-z0-9]+/i", $input, $sections);
        return strtolower(implode("-", $sections[0]));
    }
473411
public static function encode($input, $serialized = false)
    {
        // use Base64 encoding to workaround issues with invalid
        // or null characters in serialized string (#1489142)
        if ($serialized) {
            return base64_encode(serialize($input));
        }

        if (is_object($input)) {
            foreach (get_object_vars($input) as $idx => $value) {
                $input->$idx = self::encode($value);
            }
            return $input;
        }
        else if (is_array($input)) {
            foreach ($input as $idx => $value) {
                $input[$idx] = self::encode($value);
            }

            return $input;
        }

        return utf8_encode($input);
    }
1300340
public static function decode($input, $serialized = false)
    {
        // use Base64 encoding to workaround issues with invalid
        // or null characters in serialized string (#1489142)
        if ($serialized) {
            // Keep backward compatybility where base64 wasn't used
            if (strpos(substr($input, 0, 16), ':') !== false) {
                return self::decode(@unserialize($input));
            }

            return @unserialize(base64_decode($input));
        }

        if (is_object($input)) {
            foreach (get_object_vars($input) as $idx => $value) {
                $input->$idx = self::decode($value);
            }
            return $input;
        }
        else if (is_array($input)) {
            foreach ($input as $idx => $value) {
                $input[$idx] = self::decode($value);
            }
            return $input;
        }

        return utf8_decode($input);
    }
97107
public static function toKey($input)
    {
        // Remove spaces and dashes, then convert to lower case.
        $input = self::toUnderscoreSeparated($input);
        $input = strtolower($input);

        return $input;
    }
560484
public function serialise($input)
    {
        $writer = Writer::createFromString('');

        if (is_array(reset($input))) {
            $writer->insertOne(array_keys(reset($input)));
        } else {
            $writer->insertOne(array_keys($input));
        }

        if (is_array(reset($input))) {
            $writer->insertAll($input);
        } else {
            $writer->insertOne($input);
        }

        return $writer->__toString();
    }
1119711
public static function fromArray($input = null)
    {
        //====================================================================//
        // Safety Check
        if (is_null($input) || !self::isValid($input)) {
            return null;
        }
        //====================================================================//
        // return Encoded CheckSum
        return self::getEncoded($input);
    }