Calls certain method
@param string $methodName Method name, without transport extension (i.e. .xml or .json)
@param array $data Method data
@return mixed Parsed data from method
@throws Exception Exception with error response from the method
11640
public function method($methodName, array $data = array())
    {
        $curl = new CURL();
        $url = $this->url . $methodName . '.json';
        $result = $curl->getURL($url, $data);
        $json = json_decode($result);
        if (!$result) {
            throw new Exception('No response retrieved');
        } elseif (!$json) {
            throw new Exception('Cannot parse JSON');
        } elseif ($json->error) {
            throw new Exception($result);
        }
        return $json;
    }
1356294
protected function encode($name, $data)
    {
        if (is_string($data)) {
            return $data;
        }

        $data = json_encode($data);

        if (json_last_error()) {
            throw new Exception(
                "Erro json encode [ {$name} ] - " . $this->lastJsonErrorMessage(json_last_error()), 500
            );
        }

        return $data;
    }
1271758
public static function parseClassMethod($fullClassName, $methodName)
    {
        $class      = self::parseClass($fullClassName);
        $classNodes = $class->stmts;

        foreach ($classNodes as $classLevelNode) {
            if ($classLevelNode instanceof ClassMethod && $classLevelNode->name->toString() == $methodName) {
                return $classLevelNode;
            }
        }

        throw new \InvalidArgumentException("Method $methodName was not found in the $fullClassName");
    }
344707
public static function validateByCallback($paramName, array $data,
                                              array $params)
    {
        if (isset($params['callback'])) {
            return $params['callback']($paramName, $data);
        } else {
            throw new \Exception('Callback parameter is required');
        }
    }
785161
private function checkMethodExists($className, $methodName)
    {
        if (!$this->isMethodAvailable($className, $methodName)) {
            throw new Exception(Piwik::translate('General_ExceptionMethodNotFound', array($methodName, $className)));
        }
    }
275025
protected function invokeService($service,$method,$data) {

            if (is_callable($this->onInvokeService)) {
                return call_user_func_array($this->onInvokeService,array($service,$method,$data));
            } else {
                throw new Exception('onInvokeService is not defined or not callable');
            }

        }
993946
public static function parse($data, $format = 'json')
    {
        if (!array_key_exists($format, self::$decoders)) {
            throw new Exception('Invalid decoder.');
        }
        $decoder = self::$decoders[$format];

        $input = file_put_contents('/tmp/input', $data);
        $params = "drafter -f {$format} /tmp/input";

        $results = shell_exec($params);
        return call_user_func([$decoder, 'decode'], $results);
    }
898040
public function dispatch(string $name, $data = [])
    {
        if (!isset($this->events[$name])) {
            throw new \Exception("Event '$name' not found in ".__CLASS__.' in stack!');
        }

        foreach ($this->events[$name] as $callback) {
            switch ($callback) {
                case is_object($callback) && ($callback instanceof Closure):
                    return $callback($name, $data);
                    break;
                case string_has($callback, '@'):
                    return $this->callFunction($callback, $data);
                    break;
                case string_has($callback, '::'):
                    return $this->callUserFunctionEvent($callback);
                    break;
                case is_string($callback) && !string_has($callback, '@'):
                    call_user_func($callback, $data);
                    break;
            }
        }
    }
466711
public static function convert($methodName)
    {
        if (!in_array($methodName, SymfonyIdRouteLoader::$VALID_CRUD_METHODS)) {
            throw new MethodNotValidException($methodName);
        }

        switch ($methodName) {
            case SymfonyIdRouteLoader::METHOD_NEW:
            case SymfonyIdRouteLoader::METHOD_EDIT:
                return new Method(array(
                    'methods' => array('GET', 'POST'),
                ));
                break;
            case SymfonyIdRouteLoader::METHOD_SHOW:
            case SymfonyIdRouteLoader::METHOD_DOWNLOAD:
            case SymfonyIdRouteLoader::METHOD_LIST:
                return new Method(array(
                    'methods' => array('GET'),
                ));
                break;
            case SymfonyIdRouteLoader::METHOD_BULK_DELETE:
            case SymfonyIdRouteLoader::METHOD_DELETE:
                return new Method(array(
                    'methods' => array('DELETE'),
                ));
                break;
            case SymfonyIdRouteLoader::METHOD_BULK_NEW:
                return new Method(array(
                    'methods' => array('POST'),
                ));
                break;
        }

        return new Method(array(
            'methods' => array(),
        ));
    }
553986
private function getCall(string $methodName): DICallWrapper
    {
        if (array_key_exists($this::CALLS_SECTION, $this->serviceArray)) {
            foreach ($this->serviceArray[$this::CALLS_SECTION] as $callArray) {
                $call = new DICallWrapper($callArray);
                if ($call->getMethodName() === $methodName) {
                    return $call;
                }
            }
        }
        throw new MissingUpdateCallException();
    }
800361
public static function json_encode(array $data)
    {
        $json = @json_encode($data);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(
                sprintf('An error occurred while trying to encode data to JSON [code "%s"]!', json_last_error())
            );
        } else {
            $data = $json;
        }
        return $data;
    }
575433
private function callMethod($methodName, $datas)
    {
        if (method_exists($this, $methodName)) {
            $call = [$this, $methodName];
        } elseif (isset($this->extends[$methodName])) {
            $call = $this->extends[$methodName];
        } else {
            throw new MethodNotExistsException(sprintf('%s method is not exists in Validation class', $methodName));
        }

        if ($methodName !== 'runRequired') {
            $return = call_user_func_array([$this, 'runRequired'], count($datas) === 4 ? array_slice($datas, 1, 4) : $datas);
        }

        call_user_func_array($call, $datas);

        return $return;
    }
941082
protected function extractSingleItemData(array $data) {
        if ($this->singleResponseKey && !array_key_exists($this->singleResponseKey, $data)) {
            throw new Exception('Invalid response, missing field ' . $this->singleResponseKey);
        }

        return ($this->singleResponseKey) ? $data[$this->singleResponseKey] : $data;
    }
414256
protected function parse($data = null, $filename = null)
    {
        if (!$data) {
            $error = error_get_last();

            // Parse functions may return NULL but set no error if the string contains no parsable data
            if (!is_array($error)) {
                $error["message"] = "No parsable content in data.";
            }

            $error["file"] = $filename;

            // if string contains no parsable data, no error is set, resulting in any previous error
            // persisting in error_get_last(). in php 7 this can be addressed with error_clear_last()
            if (function_exists("error_clear_last")) {
                error_clear_last();
            }

            throw new ParseException($error);
        }

        return $this->expandDottedKey($data);
    }
511716
public function doRequest($apiName, array $data, $answerFormat = self::ANSWER_FORMAT_ARRAY, $try_number = 1)
    {
        $requestId = $this->getNextId();
        $requestData = [
            'jsonrpc' => '2.0',
            'id'     => $requestId,
            'method' => 'call',
            'params' => [
                $apiName,
                $data['method'],
                $data['params']
            ]
        ];
        try {
            $connection = $this->getConnection();
            $connection->send(json_encode($requestData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
            $answerRaw = $connection->receive();
            $answer = json_decode($answerRaw, self::ANSWER_FORMAT_ARRAY === $answerFormat);

            if (
                (self::ANSWER_FORMAT_ARRAY === $answerFormat && isset($answer['error']))
                || (self::ANSWER_FORMAT_OBJECT === $answerFormat && isset($answer->error))
            ) {
                throw new ConnectionException('got error in answer: ' . $answer['error']['code'] . ' ' . $answer['error']['message']);
            }
            //check that answer has the same id or id from previous tries, else it is answer from other request
            if (self::ANSWER_FORMAT_ARRAY === $answerFormat) {
                $answerId = $answer['id'];
            } elseif (self::ANSWER_FORMAT_OBJECT === $answerFormat) {
                $answerId = $answer->id;
            }
            if ($requestId - $answerId > ($try_number - 1)) {
                throw new ConnectionException('got answer from old request');
            }


        } catch (ConnectionException $e) {

            if ($try_number < $this->maxNumberOfTriesToCallApi) {
                //if got WS Exception, try to get answer again
                $answer = $this->doRequest($apiName, $data, $answerFormat, $try_number + 1);
            } elseif ($this->isExistReserveNodeUrl()) {
                //if got WS Exception after few ties, connect to reserve node
                $this->connectToReserveNode();
                $answer = $this->doRequest($apiName, $data, $answerFormat);
            } else {
                //if nothing helps
                throw $e;
            }
        }

        return $answer;
    }
259309
public function getMetadataFor($tableName, array $parentName = array())
    {
        $avaibleData = array();
        foreach ($this->getAllMetadata() as $metadata) {
            $avaibleData[] = $metadata->getName();
            if ($metadata->getName() === $tableName) {
                return $metadata;
            }
        }

        throw new \Exception(sprintf('"%s" not found in "%s"', $tableName, implode(', ', $avaibleData)));
    }
912632
protected function parse($data = null, $filename = null)
    {
        if (json_last_error() !== JSON_ERROR_NONE) {
            $error_message  = 'Syntax error';
            if (function_exists('json_last_error_msg')) {
                $error_message = json_last_error_msg();
            }

            $error = [
                'message' => $error_message,
                'type'    => json_last_error(),
                'file'    => $filename,
            ];

            throw new ParseException($error);
        }

        return $data;
    }