Create a new report from a PHP throwable.

@param \Bugsnag\Configuration $config         the config instance
@param \Throwable             $throwable      the throwable instance

@return static
332851
public static function fromPHPThrowable(Configuration $config, $throwable)
    {
        $report = new static($config);

        $report->setPHPThrowable($throwable)
               ->setUnhandled(false)
               ->setSeverityReason(['type' => 'handledException']);

        return $report;
    }
1059800
protected static function createFromCallable(callable $config, $instanceOf = null)
    {
        $object = call_user_func($config);

        if (!is_object($object)) {
            throw new InvalidConfigurationException(
                "Unable to create object class."
            );
        }

        if (!$object instanceof $instanceOf) {
            static::throwInvalidInstanceException(
                get_class($object),
                $instanceOf
            );
        }

        return $object;
    }
44764
private static function serializeThrowableObject($throwable): string
    {
        $message = \sprintf(
            '[GraphQL] %s: %s[%d] (caught throwable) at %s line %s.',
            \get_class($throwable),
            $throwable->getMessage(),
            $throwable->getCode(),
            $throwable->getFile(),
            $throwable->getLine()
        );

        return $message;
    }
644133
protected function renderThrowableAsText($throwable)
    {
        $text = sprintf('Type: %s' . PHP_EOL, get_class($throwable));

        if ($code = $throwable->getCode()) {
            $text .= sprintf('Code: %s' . PHP_EOL, $code);
        }

        if ($message = $throwable->getMessage()) {
            $text .= sprintf('Message: %s' . PHP_EOL, htmlentities($message));
        }

        if ($file = $throwable->getFile()) {
            $text .= sprintf('File: %s' . PHP_EOL, $file);
        }

        if ($line = $throwable->getLine()) {
            $text .= sprintf('Line: %s' . PHP_EOL, $line);
        }

        if ($trace = $throwable->getTraceAsString()) {
            $text .= sprintf('Trace: %s', $trace);
        }

        return $text;
    }
600817
public static function wrapException(\Throwable $exception): \Throwable
    {
        if ($exception instanceof ExceptionInterface) {
            return $exception;
        }

        if ($exception instanceof ConnectionException) {
            if ($exception instanceof ConnectionPDOException) {
                return new DatabaseException($exception->getMessage(), $exception->getCode(), $exception);
            }
            if ($exception instanceof ConnectionInvalidArgumentException) {
                return new InvalidArgumentException($exception->getMessage(), $exception->getCode(), $exception);
            }
            if ($exception instanceof ConnectionFileException) {
                return new FileException($exception->getMessage(), $exception->getCode(), $exception);
            }
        }

        if ($exception instanceof QueryScribeException) {
            if ($exception instanceof QueryScribeInvalidArgumentException) {
                return new InvalidArgumentException($exception->getMessage(), $exception->getCode(), $exception);
            }
            if ($exception instanceof QueryScribeInvalidReturnValueException) {
                return new InvalidReturnValueException($exception->getMessage(), $exception->getCode(), $exception);
            }
            if ($exception instanceof QueryScribeInvalidQueryException) {
                return new IncorrectQueryException($exception->getMessage(), $exception->getCode(), $exception);
            }
        }

        return $exception;
    }
37118
public function newInstance(array $config)
    {
        $new_config = array_merge($this->default_config, $config);

        return new static($this->config_handler, $this->url, $new_config);
    }
444420
public function make($config = null)
    {
        try {
            return $this->_invokeCallable($this->_getFactoryCallback($config), [$config]);
        } catch (InvocationExceptionInterface $invocationException) {
            throw $this->_createCouldNotMakeException(
                $this->__('Could not make subject instance'),
                null,
                $invocationException,
                $this,
                $config
            );
        } catch (RootException $exception) {
            throw $this->_createFactoryException(
                $this->__('An error occurred while trying to make the subject instance'),
                null,
                $exception,
                $this
            );
        }
    }
910771
public function handle(\Throwable $throwable)
    {
        try {
            $response = $this->doHandler($throwable);
        } catch (\Throwable $e) {
            $response = $this->handleThrowtable($e);
        }

        return $response;
    }
193351
public static function getInstance(Configuration $config = null)
    {
        if (!self::$instance) {
            self::$instance = new self($config);
        }

        return self::$instance;
    }
1269581
public function setThrowIfEmptyId($throwOnEmptyId)
    {
        if (empty($this->mappingOptions)) $this->resetMappingOptions();

        $this->mappingOptions->throwOnEmptyId = $throwOnEmptyId;

        return $this;
    }
1081956
public static function createFromConfig(array $config)
    {
        $fields = [];
        foreach ($config as $name => $field) {
            $fields[$name] = Fields::create($name, $field);
        }
        return new static($fields);
    }
642978
public function create_lock_instance(array $config) {
        global $CFG;
        if (!array_key_exists('name', $config) || !array_key_exists('type', $config)) {
            throw new coding_exception('Invalid cache lock instance provided');
        }
        $name = $config['name'];
        $type = $config['type'];
        unset($config['name']);
        unset($config['type']);

        if (!isset($this->lockplugins[$type])) {
            $pluginname = substr($type, 10);
            $file = $CFG->dirroot."/cache/locks/{$pluginname}/lib.php";
            if (file_exists($file) && is_readable($file)) {
                require_once($file);
            }
            if (!class_exists($type)) {
                throw new coding_exception('Invalid lock plugin requested.');
            }
            $this->lockplugins[$type] = $type;
        }
        if (!array_key_exists($type, $this->lockplugins)) {
            throw new coding_exception('Invalid cache lock type.');
        }
        $class = $this->lockplugins[$type];
        return new $class($name, $config);
    }
1372614
public static function fromThrowable($throwable)
    {
        if ($throwable instanceof \Error) {
            $throwable = ErrorException::fromError($throwable);
        }

        if (!$throwable instanceof \Exception) {
            throw new \InvalidArgumentException('throw-up can only throw Exceptions and Errors');
        }

        return new self($throwable);
    }
489520
protected function setPrevious($throwable)
    {
        if ($throwable) {
            $this->previous = static::fromPHPThrowable($this->config, $throwable);
        }

        return $this;
    }
6894
public function log(\Throwable $throwable): void
    {
        $date = (new \DateTime())->format('Y-m-d H:i:s');
        $log = "[$date] {$throwable->getMessage()} at line {$throwable->getLine()} in {$throwable->getFile()}" . PHP_EOL;
        $dirname = dirname($this->logPath);

        if (!is_dir($dirname)) {
            mkdir($dirname, 0755);
        }

        $handle = fopen($this->logPath, 'a');
        fwrite($handle, $log);
        fclose($handle);
    }
1142485
public function setConfig(array $config)
    {
        if (!isset($config['thumbnailer'])) {
            $this->_thumbnailer = new Thumbnailer();
        } elseif (class_exists($config['thumbnailer'])) {
            $this->_thumbnailer = new $config['thumbnailer'];
        } else {
            throw new ConfigurationException('Class ' . $config['thumbnailer'] . ' does not exist.');
        }

        if (!($this->_thumbnailer instanceof ThumbnailerInterface)) {
            throw new ConfigurationException('Class ' . get_class($this->_thumbnailer) . ' must implement the interface \ysaroka\autothumb\ThumbnailerInterface.');
        }

        if (!isset($config['document_root'])) {
            throw new ConfigurationException('"document_root" key is required.');
        }

        if (!is_dir(realpath($config['document_root']))) {
            throw new ConfigurationException('"document_root": directory "' . $config['document_root'] . '" does not exist.');
        }

        if (!isset($config['types']) || count($config['types']) == 0) {
            throw new ConfigurationException('"types" key is required and should not be empty.');
        }

        foreach ($config['types'] as $type => $params) {
            if (!preg_match('#^[\w\d]+$#', $type)) {
                throw new ConfigurationException('"type": type name "' . $type . '" must contain only words and numbers.');
            }

            if (!isset($params['width'])) {
                $config['types'][$type]['width'] = 100;
            }

            if (!isset($params['height'])) {
                $config['types'][$type]['height'] = 100;
            }

            if (!isset($params['crop'])) {
                $config['types'][$type]['crop'] = true;
            }

            if (!isset($params['stretch'])) {
                $config['types'][$type]['stretch'] = false;
            }

            if (!isset($params['watermark'])) {
                $config['types'][$type]['watermark'] = false;
            } elseif (file_exists($params['watermark']) && !is_dir($params['watermark'])) {
                $config['types'][$type]['watermark'] = realpath($params['watermark']);
                if (isset($params['watermark_pos']) && defined('\ysaroka\autothumb\ThumbnailerInterface::POS_' . strtoupper($params['watermark_pos']))) {
                    $config['types'][$type]['watermark_pos'] = constant('\ysaroka\autothumb\ThumbnailerInterface::POS_' . strtoupper($params['watermark_pos']));
                } else {
                    $config['types'][$type]['watermark_pos'] = ThumbnailerInterface::POS_BOTTOM_RIGHT;
                }
            } else {
                throw new ConfigurationException('Image file "watermark": "' . $params['watermark'] . '" for type "' . $type . '" does not exist.');
            }
        }

        if (isset($config['allowed_extensions']) && is_array($config['allowed_extensions']) && count($config['allowed_extensions']) > 0) {
            $this->_allowedExtensions = $config['allowed_extensions'];
        }

        $this->_documentRoot = realpath($config['document_root']);
        $this->_types = $config['types'];

        return $this;
    }
430696
public static function create($name, array $config = array())
    {
        if (!isset(self::$config->generators[$name])) {
            throw new Exception("Unknown generator '$name'.");
        }

        $generator = \Yii::createComponent(\CMap::mergeArray(self::$config->generators[$name], $config));
        $generator->init();

        foreach (self::$config->attributes as $attribute => $value) {
            if (property_exists($generator, $attribute)) {
                $generator->$attribute = $value;
            }
        }

        return $generator;
    }