Get a precondition given its handle.

@param string $handle the precondition handle

@throws Exception

@return PreconditionInterface
12274
public function getPreconditionByHandle($handle)
    {
        $list = $this->config->get('install.preconditions');
        if (!isset($list[$handle])) {
            throw new Exception(sprintf('Unable to find an install precondition with handle %s', $handle));
        }
        if (!$list[$handle]) {
            throw new Exception(sprintf('The precondition with handle %s is disabled', $handle));
        }
        $className = $list[$handle];
        $instance = $this->getPreconditionByClassName($className);

        return $instance;
    }
1039882
public function renderChild( $handle )
    {
        if (!$this->childComponents[ $handle ]) {
            $message = "Attempted to render nonexistent child component with handle '{$handle}'";
            $this->log( $message, LogLevel::CRITICAL );
            throw new \Exception( $message );
        }
        return $this->childComponents[ $handle ]->render()->content;
    }
1051820
public function addExceptionHandler($handler) {
        if ( ! $handler instanceof IExceptionHandler && ! is_callable($handler)) {
            throw new InvalidHandlerType(
                s('Exception handler must be a callable or an instance of %s.',
                    IExceptionHandler::class)
            );
        }

        if (is_callable($handler)) {
            $handler = $this->createExceptionHandler($handler);
        }

        $this->exceptionHandlers[] = $handler;
    }
758303
public function handleException($exception)
    {
        #$this->system->startOutputBuffering();
        #$willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit();
        #$output = $this->system->cleanOutputBuffer();
        /*
        if ($this->writeToOutput()) {
            if ($willQuit) {
                while ($this->system->getOutputBufferLevel() > 0) {
                    $this->system->endOutputBuffering();
                }
                if (Misc::canSendHeaders() && $handlerContentType) {
                    header("Content-Type: {$handlerContentType}");
                }
            }
            $this->writeToOutputNow($output);
        }
        if ($willQuit) {
            $this->system->flushOutputBuffer();
            $this->system->stopExecution(1);
        }
        */
        $log = $exception->getMessage() . "\n" . $exception->getTraceAsString() . LINEBREAK;
        if ( ini_get('log_errors') ) {
            error_log($log, 0);
        }
        $output = get_class($exception).":".$log;
        //return $output;
        if(method_exists($exception, 'getSeverity')) {
            $severityCode = $exception->getSeverity();
            switch($severityCode) {
			case E_ERROR: // 1 //
				$severity = 'E_ERROR';
				break;
			case E_WARNING: // 2 //
				$severity = 'E_WARNING';
				break;
			case E_PARSE: // 4 //
				$severity = 'E_PARSE';
				break;
			case E_NOTICE: // 8 //
				$severity = 'E_NOTICE';
				break;
			case E_CORE_ERROR: // 16 //
				$severity = 'E_CORE_ERROR';
				break;
			case E_CORE_WARNING: // 32 //
				$severity = 'E_CORE_WARNING';
				break;
			case E_COMPILE_ERROR: // 64 //
				$severity = 'E_COMPILE_ERROR';
				break;
			case E_COMPILE_WARNING: // 128 //
				$severity = 'E_COMPILE_WARNING';
				break;
			case E_USER_ERROR: // 256 //
				$severity = 'E_USER_ERROR';
				break;
			case E_USER_WARNING: // 512 //
				$severity = 'E_USER_WARNING';
				break;
			case E_USER_NOTICE: // 1024 //
				$severity = 'E_USER_NOTICE';
				break;
			case E_STRICT: // 2048 //
				$severity = 'E_STRICT';
				break;
			case E_RECOVERABLE_ERROR: // 4096 //
				$severity = 'E_RECOVERABLE_ERROR';
				break;
			case E_DEPRECATED: // 8192 //
				$severity = 'E_DEPRECATED';
				break;
			case E_USER_DEPRECATED: // 16384 //
				$severity = 'E_USER_DEPRECATED';
				break;
			case E_ALL: // 32767 //
				$severity = 'E_ALL';
				break;
			default:
				$severity = 'UNKOWN';
				break;
		}
        }
    	if ( env('APP_DEBUG') === true ) {
        	print '
				<!DOCTYPE html>
				<html lang="en">
					<head>
						<meta charset="utf-8">
						<meta http-equiv="X-UA-Compatible" content="IE=edge">
						<meta name="viewport" content="width=device-width, initial-scale=1">
						<title>Error</title>
						<!-- Fonts -->
						<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
						<style>html, body {background-color: #fff;color: #636b6f;font-family: \'Nunito\', sans-serif;font-weight: 100;height: 100vh;margin: 0;}.full-height {height: 90vh;}.flex-center {align-items: center;display: flex;justify-content: center;}.content {text-align: center;}.title {font-size: 36px;padding: 20px;}</style>
					</head>
					<body>
						<div class="flex-center position-ref full-height">
							<div class="content">
								<h2 class="title" style="color: rgb(190, 50, 50)">Exception Occured</h2>
        						<table style="width: 800px; display: inline-block;text-align:left">
        							<tr style="background-color:rgb(230,230,230)">
										<th style="width: 80px">Type</th>
										<td>'. get_class($exception) .'</td>
									</tr>
        							<tr style="background-color:rgb(240,240,240)">
										<th>Code</th>
										<td>'. $exception->getCode() .'</td>
									</tr>
        							<tr style="background-color:rgb(240,240,240)">
										<th>Trace</th>
										<td>'. trim(str_replace('#', '<br>#', $exception->getTraceAsString()),'<br>') .'</td>
									</tr>'. 
                                        (isset($severityCode) ? '
        							<tr style="background-color:rgb(240,240,240)">
										<th>Severity</th>
										<td>'.  $severityCode .' - '.$severity.'</td>
									</tr>.'
                                          : '').'
        							<tr style="background-color:rgb(240,240,240)">
										<th>Message</th>
										<td>'. $exception->getMessage() .'</td>
									</tr>
        							<tr style="background-color:rgb(230,230,230)">
										<th>File</th>
										<td>'. $exception->getFile() .'</td>
									</tr>
        							<tr style="background-color:rgb(240,240,240)">
										<th>Line</th>
										<td>'. $exception->getLine() .'</td>
									</tr>
        						</table>
							</div>
						</div>
					</body>
				</html>
			';
    	}
    	else {
        	$message = "Type: " . get_class($exception) . "; Message: {$exception->getMessage()}; File: {$exception->getFile()}; Line: {$exception->getLine()};";
        	if(!file_exists(LOGS . "/debug.log") || !is_file(LOGS . "/debug.log")) {
				file_put_contents( LOGS . "/debug.log", '');
			}
        	error_log("[".date('Y-y-d H:i:s')."] " . $message . PHP_EOL . PHP_EOL, 3, LOGS . "/debug.log");
			//header( "Location: {$config["error_page"]}" );
			echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Error</title><!-- Fonts --><link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
<style>html, body {background-color: #fff;color: #636b6f;font-family: \'Nunito\', sans-serif;font-weight: 100;height: 100vh;margin: 0;}.full-height {height: 90vh;}.flex-center {align-items: center;display: flex;justify-content: center;}.content {text-align: center;}.title {font-size: 36px;padding: 20px;}</style><body><div class="flex-center position-ref full-height"><div class="content"><div class="title">It looks like something went wrong.</div></div></div></body></html>';
    	}
    	exit();
    }
1346610
private function getHandle()
    {
        // make sure to clean up old handles
        if ($this->handle !== null && feof($this->handle)) {
            $this->resetHandle();
        }

        // provision new handle
        if ($this->handle == null) {
            $params = $this->params;
            if (!empty($this->getResourceVersion())) {
                $params['resourceVersion'] = $this->getResourceVersion();
            }
            $query = http_build_query($params);
            $base = $this->getClient()->getConfig()->getServer().$this->endpoint;
            $url = $base;

            if (!empty($query)) {
                $parsed = parse_url($base);
                if (key_exists('query', $parsed) || substr($base, -1) == "?") {
                    $url .= '&'.$query;
                } else {
                    $url .= '?'.$query;
                }
            }
            $handle = @fopen($url, 'r', false, $this->getClient()->getStreamContext());
            if ($handle === false) {
                $e = error_get_last();
                throw new \Exception($e['message'], $e['type']);
            }
            stream_set_timeout($handle, 0, $this->getStreamTimeout());
            $this->handle = $handle;
        }

        return $this->handle;
    }
610223
public function window($handle)
    {
        $params = ['name' => (string) $handle];
        $this->executor->execute(DriverCommand::SWITCH_TO_WINDOW, $params);

        return $this->driver;
    }
994861
public static function getByHandle($atHandle)
    {
        $db = Loader::db();
        $row = $db->GetRow('SELECT * FROM AuthenticationTypes WHERE authTypeHandle=?', [$atHandle]);
        if (!$row) {
            throw new Exception(t('Invalid Authentication Type Handle'));
        }
        $at = self::load($row);

        return $at;
    }
1289514
public function executeHandler($handler, $params, $prevOutput = null)
    {
        // a function(-ish) thing which can be called
        if (is_callable($handler)) {
            return $handler($this, $params, $prevOutput);
        }

        // aliased handler
        if ($actualHandler = @$this->handlerAlias[$handler]) {
            return $this->executeHandler($actualHandler, $params, $prevOutput);
        }

        // only callable and controller/method pair (`:` seprated string) can be accepted
        if (!is_string($handler)) {
            $type = gettype($handler);
            throw new \Exception("'{$type}' can not be used as handler, should be a callable or controller/method pair!");
        }

        if (false === $pos = strpos($handler, ':')) {
            throw new \Exception("Can not parse '{$handler}' for corresponding controller/method!");
        }

        // controller/method pair
        list($class, $method) = explode(':', $handler, 2);
        $class = $this->handlerClassPrefix ? "{$this->handlerClassPrefix}{$class}" : $class;
        $controller = new $class;
        return $controller->$method($this, $params, $prevOutput);
    }
1343539
public static function create($handle)
    {
        if (!isset(self::$_pool[$handle])) {
            $classname = self::__getClassName($handle);
            $path = self::__getDriverPath($handle);

            if (!is_file($path)) {
                throw new Exception(
                    __('Could not find Text Formatter %s.', array('<code>' . $classname . '</code>'))
                    . ' ' . __('If it was provided by an Extension, ensure that it is installed, and enabled.')
                );
            }

            if (!class_exists($classname)) {
                require_once $path;
            }

            self::$_pool[$handle] = new $classname;
        }

        return self::$_pool[$handle];
    }
779648
protected function getHandler($handler)
    {
        if ($handler instanceof HandlerInterface) {
            return [$handler, 'handleEvent'];
        }

        if (is_callable($handler)) {
            return $handler;
        }

        throw new InvalidArgumentException(
            sprintf('Invalid handler "%s".', is_string($handler) ? $handler : gettype($handler))
        );
    }
108448
public function setHandler(callable $handler = null)
    {
        $old = $this->handler;
        $this->handler = $handler;

        return $old;
    }
134135
public function write($handle = null)
	{
		if ($handle === null) {
			$handle = fopen('php://output', 'wb');
		} elseif (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
			throw new Exception('Argument must be stream resource.');
		}

		$tables = $views = [];

		$res = $this->connection->query('SHOW FULL TABLES');
		while ($row = $res->fetch_row()) {
			if ($row[1] === 'VIEW') {
				$views[] = $row[0];
			} else {
				$tables[] = $row[0];
			}
		}
		$res->close();

		$tables = array_merge($tables, $views); // views must be last

		$this->connection->query('LOCK TABLES `' . implode('` READ, `', $tables) . '` READ');

		$db = $this->connection->query('SELECT DATABASE()')->fetch_row();
		fwrite($handle, '-- Created at ' . date('j.n.Y G:i') . " using David Grudl MySQL Dump Utility\n"
			. (isset($_SERVER['HTTP_HOST']) ? "-- Host: $_SERVER[HTTP_HOST]\n" : '')
			. '-- MySQL Server: ' . $this->connection->server_info . "\n"
			. '-- Database: ' . $db[0] . "\n"
			. "\n"
			. "SET NAMES utf8;\n"
			. "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO';\n"
			. "SET FOREIGN_KEY_CHECKS=0;\n"
			. "SET UNIQUE_CHECKS=0;\n"
			. "SET AUTOCOMMIT=0;\n"
		);

		foreach ($tables as $table) {
			$this->dumpTable($handle, $table);
		}

		fwrite($handle, "COMMIT;\n");
		fwrite($handle, "-- THE END\n");

		$this->connection->query('UNLOCK TABLES');
	}
1278907
public function read($handle)
	{
		if (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
			throw new Exception('Argument must be stream resource.');
		}

		$stat = fstat($handle);

		$sql = '';
		$delimiter = ';';
		$count = $size = 0;

		while (!feof($handle)) {
			$s = fgets($handle);
			$size += strlen($s);
			if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') {
				$delimiter = trim(substr($s, 10));

			} elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) {
				$sql .= substr($ts, 0, -strlen($delimiter));
				if (!$this->connection->query($sql)) {
					throw new Exception($this->connection->error . ': ' . $sql);
				}
				$sql = '';
				$count++;
				if ($this->onProgress) {
					call_user_func($this->onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : null);
				}

			} else {
				$sql .= $s;
			}
		}

		if (rtrim($sql) !== '') {
			$count++;
			if (!$this->connection->query($sql)) {
				throw new Exception($this->connection->error . ': ' . $sql);
			}
			if ($this->onProgress) {
				call_user_func($this->onProgress, $count, isset($stat['size']) ? 100 : null);
			}
		}

		return $count;
	}
272071
private function getHandler($handler): FormHandlerInterface
    {
        if (is_string($handler)) {
            if (!isset($this->handlers[$handler])) {
                $handler = new $handler();
            } else {
                $handler = $this->handlers[$handler];
            }
        }

        if (!$handler instanceof FormHandlerInterface) {
            throw new InvalidHandlerException(FormHandlerInterface::class, $handler);
        }

        return $handler;
    }
13441
public InstructionHandle getPredecessorOf(InstructionHandle handle) {
        if (VERIFY_INTEGRITY && !containsInstruction(handle)) {
            throw new IllegalStateException();
        }
        return handle == firstInstruction ? null : handle.getPrev();
    }
1154443
public function getByHandle($handle)
    {
        $handle = (string) $handle;

        return $handle === '' ? null : $this->repo->findOneBy(['glHandle' => $handle]);
    }
243624
public function handle(
    Handler $handler, $sendResponse = true, $catchExceptions = true, $flushHeaders = true, $throwEventExceptions = false
  )
  {
    $this->_eventChannel->setShouldThrowExceptions($throwEventExceptions);
    $c = $this->getContext();
    if($handler instanceof ContextAware)
    {
      $handler->setContext($c);
    }

    try
    {
      $this->_eventChannel->trigger(PreExecuteEvent::i($c, $handler));
      $r = $handler->handle($c);
      $this->_eventChannel->trigger(ResponsePrepareEvent::i($c, $handler, $r));
      $r->prepare($c->request());
      $this->_eventChannel->trigger(ResponsePreparedEvent::i($c, $handler, $r));
    }
    catch(\Throwable $e)
    {
      if(!$catchExceptions)
      {
        throw $e;
      }
      $this->getLogger()->error($e->getMessage());
      $r = (new ExceptionHandler($e))->handle($c);
      $r->prepare($c->request());
    }
    try
    {
      if($sendResponse)
      {
        $this->_eventChannel->trigger(ResponsePreSendHeadersEvent::i($c, $handler, $r));
        $r->sendHeaders();
        if($flushHeaders)
        {
          flush();
        }
        $this->_eventChannel->trigger(ResponsePreSendContentEvent::i($c, $handler, $r));
        $r->send();
      }
      $this->_eventChannel->trigger(HandleCompleteEvent::i($c, $handler, $r));
    }
    catch(\Throwable $e)
    {
      if(!$catchExceptions)
      {
        throw $e;
      }
      $this->getLogger()->error($e->getMessage());
    }
    return $r;
  }