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
@throws DomainException Provided object could not be encoded to valid JSON
359808
protected function _toJson($input)
    {
        $json = json_encode($input);

        if (JSON_ERROR_NONE !== json_last_error())
        {
            throw new InvalidArgumentException(
                'Error encoding JSON data: ' . json_last_error_msg()
            );
        }

        return $json;
    }
795061
private static function _prepareQuestionString($input)
    {
        $regex = '';
        if (is_array($input) === true) {
            $regex = '^';
            $start = true;
            foreach ($input as $row) {
                if ($start === false) {
                    $regex .= '|';
                }

                $start  = false;
                $regex .= '(';
                $one    = null;
                if (strlen($row) > 2) {
                    $one = true;
                }

                foreach (str_split($row, 1) as $char) {
                    $regex .= '[' . $char;
                    $regex .= strtoupper($char) . ']';
                    if ($one === true) {
                        $one    = false;
                        $regex .= '(';
                    }
                }

                if ($one === false) {
                    $regex .= ')';
                }

                $regex .= '?)';
            }
        }

        return $regex;
    }
670957
public function fromString($string, $object = true)
    {
        $data = array();

        if(!empty($string))
        {
            $data = eval($string);

            if($data === false) {
                throw new DomainException('Cannot evaluate data from PHP string');
            }
        }

        return $object ? $this->merge($data) : $data;
    }
310194
public static function build($input = null) : Response
    {
        //Is a response object already
        if ($input instanceof Response) {
            return $input;
        }

        $response = new Response();

        //View
        if ($input instanceof View) {
            $response->setBody($input->draw());
        }

        //Json
        if ($input instanceof ConvertsToJson) {
            self::createFromJsonable($response, $input);
        }

        //Array
        if (is_array($input)) {
            self::createFromArray($response, $input);
        }

        //String
        if (is_string($input)) {
            $response->setBody($input);
        }

        return $response;
    }
1234990
public static function describeType($input)
    {
        switch (gettype($input)) {
            case 'object':
                return 'object(' . get_class($input) . ')';
            case 'array':
                return 'array(' . count($input) . ')';
            default:
                ob_start();
                var_dump($input);
                // normalize float vs double
                return str_replace('double(', 'float(', rtrim(ob_get_clean()));
        }
    }
204062
public function convert($input)
    {
        if (is_string($input) === false) {
            throw new \InvalidArgumentException('Expected a string value at Parsedown converter.');
        }

        $converter = new \ParsedownExtra();

        return $converter->text($input);
    }
1179058
protected function encode(array $input)
	{
		// Detect the request content type, default to 'text/plain'
		$content_type = isset($this->headers['Content-Type']) ? $this->headers['Content-Type'] : $this->response_info('content_type', 'text/plain');

		// Get the correct format for the current content type
		$format = \Arr::key_exists(static::$auto_detect_formats, $content_type) ? static::$auto_detect_formats[$content_type] : null;

		switch($format)
		{
			// Format as XML
			case 'xml':
					/**
					 * If the input array has one item in the top level
					 * then use that item as the root XML element.
					 */
					if(count($input) === 1)
					{
						$base_node = key($input);
						return \Format::forge($input[$base_node])->to_xml(null, null, $base_node);
					}
					else
					{
						return \Format::forge($input)->to_xml();
					}
				break;

			// Format as JSON
			case 'json':
					return \Format::forge($input)->to_json();
				break;

			// Format as PHP Serialized Array
			case 'serialize':
					return \Format::forge($input)->to_serialize();
				break;

			// Format as PHP Array
			case 'php':
					return \Format::forge($input)->to_php();
				break;

			// Format as CSV
			case 'csv':
					return \Format::forge($input)->to_csv();
				break;

			// Format as Query String
			default:
					return http_build_query($input, null, '&');
				break;
		}
	}
565627
public static function encode($input)
    {
        $parts = explode('.', $input);

        foreach ($parts as &$part) {
            $part = static::encodePart($part);
        }

        return implode('.', $parts);
    }
1203156
public static String encode(String input)
    {
        try
        {
            return URLEncoder.encode(input, "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            // This never happens.
            return input;
        }
    }
920119
public function encode($input)
    {
        $parts = explode('.', $input);

        foreach ($parts as &$part) {
            $part = $this->_encodePart($part);
        }

        return implode('.', $parts);
    }
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;
	}
9947
protected function cleanString($input)
	{
		return htmlentities(
			$input,
			$this->parent->getConfig('htmlentities_flags', ENT_QUOTES),
			$this->parent->getConfig('htmlentities_encoding', 'UTF-8'),
			$this->parent->getConfig('htmlentities_double_encode', false)
		);
	}
854563
public static function convert(string $input, int $to) : string
    {
        $string = self::normalize($input);
        $parts = explode(' ', $string);
        array_walk($parts, function (&$part) {
            $part = ucfirst($part);
        });
        switch ($to) {
            case self::TYPE_NAMESPACE:
                return implode('\\', $parts);
            case self::TYPE_TABLE:
                return strtolower(implode('_', $parts));
            case self::TYPE_VARIABLE:
            case self::TYPE_ANGULAR_COMPONENT:
                return lcfirst(implode('', $parts));
            case self::TYPE_PATH:
                return implode('/', $parts);
            case self::TYPE_URL:
                return strtolower(implode('/', $parts));
            case self::TYPE_CSS_IDENTIFIER:
            case self::TYPE_ANGULAR_TAG:
                return strtolower(implode('-', $parts));
            case self::TYPE_ANGULAR_MODULE:
                return strtolower(implode('.', $parts));
            default:
                throw new DomainException("Please use one of the `TYPE_` constants on the `Codger\Generate\Language` class as 2nd parameter.");
        }
    }
1136956
public static function jsonEncode($input)
    {
        $json = json_encode($input);
        if (function_exists('json_last_error') && $errno = json_last_error()) {
            JWT::_handleJsonError($errno);
        } else if ($json === 'null' && $input !== null) {
            throw new \DomainException('Null result with non-null input');
        }
        return $json;
    }
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;
  }
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;
		}
1180386
public function inject($input)
    {
        Version::warn(__METHOD__ . ' is deprecated');
        $replace = array();
        foreach ($this->data as $key => $val) {
            $replace['{' . $key . '}'] = $val;
        }

        return strtr($input, $replace);
    }