Displays Fedora and SPARQL endpoint URLs to the user and asks for confirmation.
@param bool $throwException should an exception be thrown on lack of confirmation?
@return bool
323397
static public function askForUserConfirmation(bool $throwException = false): bool {
		echo "\n######################################################\n\n";
		echo "Are you sure that you want to import data to the following instance?! \n\n ";
		echo "Type 'yes' to continue! \n\n";
		echo self::get('sparqlUrl') . "\n";
		echo self::get('fedoraApiUrl') . "\n";
		$handle = fopen ("php://stdin","r");
		$line = trim(fgets($handle));
		fclose($handle);
		if ($line !== 'yes' && $throwException) {
			throw new RuntimeException('Configuration revoked by the user');
		}
		return $line === 'yes';
	}
445968
public function requestCode()
    {
        if (!$this->notifyTries->isIntervalSatisfied()) {
            throw new PhoneConfirmationException('Minimum interval between confirmation code requests is not satisfied');
        }
        if (!$this->notifyTries->tries_left) {
            throw new PhoneConfirmationException('Tries are exceeded. Please, contact support.');
        }

        try {
            Contact::perform('notify-confirm-phone', [
                'id' => $this->model->id,
                'type' => $this->model->type,
            ]);
        } catch (ResponseErrorException $e) {
            throw new PhoneConfirmationException('Failed to request code confirmation', 0, $e);
        }

        return true;
    }
1009095
function getEndpoint()
    {
        $this->api->curl_header = array(
            'Authorization: OAuth '.$this->api->access_token,
        );
        $data = $this->api->get( $this->metadata_url );

        if ( ! isset( $data->api_endpoint ) ){
            throw new Exception( "Endpoint request failed! {$this->providerId} returned an invalid response.", 6 );
        }

        return $data->api_endpoint;
    }
513672
private function isAdminException(GetResponseForExceptionEvent $event): bool
    {
        $request = $event->getRequest();

        /** @var SiteAccess $siteAccess */
        $siteAccess = $request->get('siteaccess', new SiteAccess());

        return in_array($siteAccess->name, $this->siteAccessGroups[EzPlatformAdminUiBundle::ADMIN_GROUP_NAME]);
    }
33119
public static function isActiveRecord($object, $throwException=false)
	{
		if ($object instanceof \yii\db\ActiveRecord) return true;
		if ($throwException) {
			$msg = Yii::t('app', 'Object {obj} does not extend ActiveRecord', ['obj'=>get_class($object)]);
			throw new InvalidConfigException($msg);
		}

		return false;
	}
698039
public function index()
    {
        try {
            $uri = null;
            if ($this->hasRequestParameter("uri")) {
                $uri = $this->getRequestParameter("uri");
                if (!common_Utils::isUri($uri)) {
                    throw new common_exception_InvalidArgumentType();
                }
            }

            switch ($this->getRequestMethod()) {
                case "GET":
                    $response = $this->get($uri);
                    break;
                case "PUT":
                    $response = $this->put($uri);
                    break;
                case "POST":
                    $response = $this->post();
                    break;
                case "DELETE":
                    $response = $this->delete($uri);
                    break;
                default:
                    throw new common_exception_BadRequest($this->getRequestURI());
            }

            $this->returnSuccess($response);

        } catch (Exception $e) {
            if ($e instanceof \common_exception_ValidationFailed &&
                $alias = $this->reverseSearchAlias($e->getField())
            ) {
                $e = new \common_exception_ValidationFailed($alias, null, $e->getCode());
            }

            $this->returnFailure($e);
        }
    }
368779
public function handleException( \Throwable $e ) : bool
    {
        if ( $e instanceof HttpStatusException )
        {
            // Show HTTP error document
            $html = $this->provider->getErrorDocument( $e->getStatusCode() );
            
            // output html
            echo $html;

            return true;
        }

        return false;
    }
413794
public function getLanguage( $throwException = TRUE )
	{
		$tags	= $this->getMetaTags( TRUE );
		if( isset( $tags['content-language'] ) )
			return $tags['content-language'];
		if( $throwException )
			throw new RuntimeException( 'No Language Meta Tag set.' );
		return "";
	}
1177228
public function call(ActionInterface $action, $throwsException = true)
    {
        try {
            $this->checkSecurity();

            $result = call_user_func_array([$this->soapClient, $action->getMethod()], array_merge([$this->sessionId], $action->getArguments()));
            return $result;

        } catch (\Exception $e) {
            if ($throwsException) {
                throw $e;
            }

            return false;
        }
    }
481618
public function isRequestedUrlClean(Request\Web $request)
    {
        $server = $request->getServer();
        if (!isset($server['REQUEST_URI'])) {
            throw new Exception('REQUEST_URI is not set');
        }

        return strpos($server['REQUEST_URI'], $this->entryPoint) !== 0;
    }
608982
public function _curlPrep()
    {
        // Check for required stuff
        if (!isset($this->uri))
            throw new \Exception('Attempting to send a request before defining a URI endpoint.');

        if (isset($this->payload)) {
            $this->serialized_payload = $this->_serializePayload($this->payload);
        }

        if (isset($this->send_callback)) {
            call_user_func($this->send_callback, $this);
        }

        $ch = curl_init($this->uri);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
        if ($this->method === Http::HEAD) {
            curl_setopt($ch, CURLOPT_NOBODY, true);
        }

        if ($this->hasBasicAuth()) {
            curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
        }

        if ($this->hasClientSideCert()) {

            if (!file_exists($this->client_key))
                throw new \Exception('Could not read Client Key');

            if (!file_exists($this->client_cert))
                throw new \Exception('Could not read Client Certificate');

            curl_setopt($ch, CURLOPT_SSLCERTTYPE,   $this->client_encoding);
            curl_setopt($ch, CURLOPT_SSLKEYTYPE,    $this->client_encoding);
            curl_setopt($ch, CURLOPT_SSLCERT,       $this->client_cert);
            curl_setopt($ch, CURLOPT_SSLKEY,        $this->client_key);
            curl_setopt($ch, CURLOPT_SSLKEYPASSWD,  $this->client_passphrase);
            // curl_setopt($ch, CURLOPT_SSLCERTPASSWD,  $this->client_cert_passphrase);
        }

        if ($this->hasTimeout()) {
            if (defined('CURLOPT_TIMEOUT_MS')) {
                curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->timeout * 1000);
            } else {
                curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
            }
        }

        if ($this->follow_redirects) {
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects);
        }

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->strict_ssl);
        // zero is safe for all curl versions
        $verifyValue = $this->strict_ssl + 0;
        //Support for value 1 removed in cURL 7.28.1 value 2 valid in all versions
        if ($verifyValue > 0) $verifyValue++;
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifyValue);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        // https://github.com/nategood/httpful/issues/84
        // set Content-Length to the size of the payload if present
        if (isset($this->payload)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->serialized_payload);
            if (!$this->isUpload()) {
                $this->headers['Content-Length'] =
                    $this->_determineLength($this->serialized_payload);
            }
        }

        $headers = array();
        // https://github.com/nategood/httpful/issues/37
        // Except header removes any HTTP 1.1 Continue from response headers
        $headers[] = 'Expect:';

        if (!isset($this->headers['User-Agent'])) {
            $headers[] = $this->buildUserAgent();
        }

        $headers[] = "Content-Type: {$this->content_type}";

        // allow custom Accept header if set
        if (!isset($this->headers['Accept'])) {
            // http://pretty-rfc.herokuapp.com/RFC2616#header.accept
            $accept = 'Accept: */*; q=0.5, text/plain; q=0.8, text/html;level=3;';

            if (!empty($this->expected_type)) {
                $accept .= "q=0.9, {$this->expected_type}";
            }

            $headers[] = $accept;
        }

        // Solve a bug on squid proxy, NONE/411 when miss content length
        if (!isset($this->headers['Content-Length']) && !$this->isUpload()) {
            $this->headers['Content-Length'] = 0;
        }

        foreach ($this->headers as $header => $value) {
            $headers[] = "$header: $value";
        }

        $url = \parse_url($this->uri);
        $path = (isset($url['path']) ? $url['path'] : '/').(isset($url['query']) ? '?'.$url['query'] : '');
        $this->raw_headers = "{$this->method} $path HTTP/1.1\r\n";
        $host = (isset($url['host']) ? $url['host'] : 'localhost').(isset($url['port']) ? ':'.$url['port'] : '');
        $this->raw_headers .= "Host: $host\r\n";
        $this->raw_headers .= \implode("\r\n", $headers);
        $this->raw_headers .= "\r\n";

        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        if ($this->_debug) {
            curl_setopt($ch, CURLOPT_VERBOSE, true);
        }

        curl_setopt($ch, CURLOPT_HEADER, 1);

        // If there are some additional curl opts that the user wants
        // to set, we can tack them in here
        foreach ($this->additional_curl_opts as $curlopt => $curlval) {
            curl_setopt($ch, $curlopt, $curlval);
        }

        $this->_ch = $ch;

        return $this;
    }
652162
private static function handleRequestException (Throwable $ex) {
        ob_clean();
        $response = get_response();
        $response->clear();
        $errorRoutes = self::$errorRoutes->getRoutes();
        if (!empty($errorRoutes)) {
            foreach ($errorRoutes as $errorRoute) {
                $routeResult = self::executeAction($errorRoute->getAction(), array_merge($_REQUEST, $errorRoute->getParameters(), [Throwable::class => $ex, Exception::class => $ex]));
                if (!empty($routeResult)) {
                    $response->content($routeResult);
                }
            }
            $response->send();
        }
        else {
            throw $ex;
        }
    }
864800
private function _throwServerError(\Exception $e) {
		$uri = (string) $this->httpClient->getConfig('base_uri');

		throw new ServerErrorHttpException(get_class($e).': url='.$uri .' '. $e->getMessage(), 500);
	}
955890
public function getByName($name, $throwException = true)
    {
        foreach ($this as $element) {

            if (!$element instanceof Element\NamedElement) {
                throw new Exception\CollectionException();
            }

            if ($element->getName() === $name) {
                return $element;
            }
        }

        if ($throwException) {
            throw new Exception\NotFoundException();
        }

        return null;
    }
861243
protected function renderException(Throwable $exception)
    {
        $code = Response::HTTP_INTERNAL_SERVER_ERROR;
        if ($exception instanceof HttpExceptionInterface) {
            $code = $exception->getStatusCode();
        } elseif ($exception instanceof AccessDeniedException || $exception instanceof InvalidCsrfTokenException) {
            $code = Response::HTTP_FORBIDDEN;
        }

        return $this->template->render(sprintf($this->path, $code), [
            'exception' => $exception,
        ]);
    }
1272250
public function handleException( \Throwable $e ) : bool
    {
        if ( $e instanceof HttpStatusException )
        {
            static $error_messages = [
                // 10X  Information
                // 20X  Normaly Processed
                '200' => 'OK',
    
                // 30X  Moved Content
                '300' => 'Multiple Choices',
                '301' => 'Moved Permanently',
                '302' => 'Moved Temporarily',
                '303' => 'See Other',
                '304' => 'Not Modified',
                '305' => 'Use Proxy',
                '307' => 'Temporary Redirect',
    
                // 40X Failure
                '401' => 'Unauthorized',
                '402' => 'Payment Required',
                '403' => 'Forbidden',
                '404' => 'Not Found',
                '405' => 'Method Not Allowed',
                '406' => 'Not Acceptable',
                '407' => 'Proxy Authentication Required',
                '408' => 'Request Time-out',
                '409' => 'Conflict',
                '410' => 'Gone',
                '411' => 'Length Required',
                '412' => 'Precondition Failed',
                '413' => 'Request Entity Too Large',
                '414' => 'Request-URI Too Large',
                '415' => 'Unsupported Media Type',
                '416' => 'Requested range not satisfiable',
                '417' => 'Expectation Failed',
    
                // 50 Server Error
                '500' => 'Internal Server Error',
                '501' => 'Not Implemented',
                '502' => 'Bad Gateway',
                '503' => 'Service Unavailable',
                '504' => 'Gateway Time-out',
                '505' => 'HTTP Version not supported',
            ];

            $status = $e->getStatusCode();
            $header_msg = $error_messages[$status] ?? '';

            header( "HTTP/1.0 {$status} {$header_msg}", true, $status );
            
            return true;
        }

        return false;
    }
1353539
public static function checkGD($throwException = true): bool
    {
        $isGd = extension_loaded('gd');

        // Require GD library
        if ($throwException && !$isGd) {
            throw new Exception('Required extension GD is not loaded.'); // @codeCoverageIgnore
        }

        return $isGd;
    }