Creates an exception for a duplicate option.

@param string    $name  The option name.
@param Exception $cause The exception that caused this exception.

@return static The created exception.
961554
public static function existsAlready($name, Exception $cause = null)
    {
        return new static(sprintf(
            'An option named "%s%s" exists already.',
            strlen($name) > 1 ? '--' : '-',
            $name
        ), 0, $cause);
    }
241544
public function getField($name, $throw = false)
    {
        $name = $this->convertToPrimaryKeyName($name);
        if (false === self::getMeta()->hasField($name)) {
            if ($throw) {
                throw new Exception('Unknown field');
            }

            return;
        }

        $field = self::getMeta()->getField($name);
        $field->setModel($this);

        return $field;
    }
169437
public function getConnection($name = null)
    {
        if ($name === null) {
            reset($this->config);
            $name = key($this->config);
        }

        if (!isset($this->config[$name])) {
            throw new \Exception('Configuration name does not exists !');
        }

        if (!isset($this->config[$name]['engine'])) {
            throw new \Exception('Engine not specified in configuration !');
        }

        $engine = $this->config[$name]['engine'];

        if (!isset($this->connections[$engine][$name])) {
            $method = 'get' . $engine;
            if (!method_exists($this, $method)) {
                throw new \Exception('Engine does not exists ! (engine: ' . $engine . ')');
            }

            $this->connections[$engine][$name] = $this->$method($name);
        }

        return $this->connections[$engine][$name];
    }
893759
public static RedisConnectionException create(Throwable cause) {

        if (cause instanceof RedisConnectionException) {
            return new RedisConnectionException(cause.getMessage(), cause.getCause());
        }

        return new RedisConnectionException("Unable to connect", cause);
    }
1021720
public static Application create(final String name) throws Exception{
    	final Map<String, Object> params = new HashMap<String, Object>();
    	params.put("name", name);
    	
    	return create(params);
    }
203703
public static function create(array $config, $name = 'default')
    {
        // Make sure a connection with same name doesn't exist
        if (array_key_exists($name, static::$connections)) {
            throw new Exception("Database connection {$name} already exists.");
        }

        // Set the class name, with the namespace
        $className = '\Radium\Database\\'. $config['driver'];

        // Connect to the database and return the object
        static::$connections[$name] = new $className($config, $name);
        return static::$connections[$name];
    }
798615
public function selectIssuerByKeyword($name)
    {
        if (!isset($this->_paymentMethodsArray))
            throw new Exception("No data loaded");
        foreach ($this->_paymentMethodsArray as $paymentMethod) {
            foreach ($paymentMethod["Issuers"] as $issuer) {
                if ($issuer["IssuerKeyword"] == strtoupper($name)) {
                    $this->_methodData = $paymentMethod;
                    $this->_issuerData = $issuer;
                    break;
                }
            }
        }
        return $this;
    }
344437
public function createAlias($name, $config){
        $handle = fopen(vibius_BASEPATH.$this->aliasCache.$name.'.php','w+');
        if(!$handle){
            throw new Exception('Unable to create alias, fopen not successful');
        }
        $template = $this->getAliasTemplate();
        $template = str_replace('{$className}', $name, $template);
        $template = str_replace('{$providerName}', $config['provider'], $template);
        
        fwrite($handle, $template);
        fclose($handle);
        $this->aliases[$name] = true;
        return true;
    }
673532
public function createException(NativeError $error, Exception $original=null)
    {
        switch ($error->code) {
            case self::PERM:
            case self::READONLY:
            case self::AUTH:
            case self::CANTOPEN:
                return new SQLDeniedException($error->message, $error, 0, $original);
//             case self::ABORT: Cannot reproduce this
                // Canceled
//                 echo "\nABORT ERROR $error->code";
//                 break;
            case self::BUSY:
            case self::LOCKED:
            case self::PROTOCOL:
            case self::ROW:
                return new SQLLockException($error->message, $error, 0, $original);
            case self::IOERR:
            case self::CORRUPT:
            case self::NO_DB:
                return new SQLIOException($error->message, $error, 0, $original);
            case self::NOMEM:
            case self::FULL:
            case self::TOOBIG:
                // Cannot reproduce this in ci
                // @codeCoverageIgnoreStart
                return new SQLExceededException($error->message, $error, 0, $original);
                // @codeCoverageIgnoreEnd
            case self::CONSTRAINT:
            case self::MISMATCH:
            case self::MISUSE:
                return new SQLConstraintException($error->message, $error, 0, $original);

        }

        return $this->exceptionByMessage($error, $original);
    }
880902
private function createCustomException(ClientException $exception): Exception
    {
        $errorId = '';
        $response = $exception->getResponse();
        if ($response) {
            $data = guzzle_json_decode((string) $response->getBody(), true);
            $errorId = (string) $data['sys']['id'] ?? '';
        }

        $exceptionClass = $this->getExceptionClass($errorId);

        return new $exceptionClass($exception);
    }
632225
protected static function createFreshMockInstance($name)
    {
        static::$instance[$name] = $mock = static::createMockByName($name);

        if (isset(static::$container)) {
            static::$container->instance($name, $mock);
        }

        return $mock;
    }
495117
public function field($name)
    {
        if (!isset($this->keyMap[$name])) {
            throw new Exception(sprintf('Unable to find %s named field.', $name));
        }
        return $this->controls[$this->keyMap[$name]];
    }
1240926
public function create(string $name, array $configuration, ActionConfiguration $actionConfiguration): FieldInterface
    {
        $resolver = new OptionsResolver();
        $configuration = $this->resolveConfiguration($configuration, $actionConfiguration);

        // Dispatch an event to allow dynamic changes on the form type
        $event = new FieldEvent(
            $actionConfiguration->getAdminName(),
            $actionConfiguration->getActionName(),
            $name,
            $actionConfiguration->getAdminConfiguration()->get('entity'),
            $configuration['type']
        );
        $this->eventDispatcher->dispatch(Events::FIELD_PRE_CREATE, $event);

        if (null === $event->getType()) {
            throw new FieldTypeNotFoundException($event->getAdminName(), $event->getActionName(), $name);
        }
        $type = $event->getType();
        $options = array_merge($configuration['options'], $event->getOptions());

        if (!key_exists($type, $this->fieldsMapping)) {
            $type = 'auto';
        }
        $field = $this->instanciateField($name, $type);
        $field->configureOptions($resolver, $actionConfiguration);

        try {
            $field->setOptions($resolver->resolve($options));
        } catch (\Exception $exception) {
            throw new Exception(
                'An error has occurred when resolving the options for the field "'.$name.'": '.$exception->getMessage(),
                $exception->getCode(),
                $exception
            );
        }
        $event = new FieldEvent(
            $actionConfiguration->getAdminName(),
            $actionConfiguration->getActionName(),
            $name,
            $actionConfiguration->getAdminConfiguration()->get('entity'),
            $type,
            $field
        );
        $this->eventDispatcher->dispatch(Events::FIELD_POST_CREATE, $event);

        return $field;
    }
952939
public static function forArgumentName($name, $code = 0, Exception $cause = null)
    {
        return new static(sprintf(
            'The argument "%s" does not exist.',
            $name
        ), $code, $cause);
    }
1242096
public static function initPdoDatabase($config, $name)
    {
        try {
            $pdo = static::createPdoConnectionByConfig($config);
        } catch (PDOException $e) {
            throw new Exception('Cannon instantiate database connection: ' . $e->getMessage());
        }

        $pdo->uniqueName = $config['host'] . "-" . $config['db'];

        static::checkDebugBar($pdo, $name);

        return new RepositoryPDO($pdo, $name);
    }
896271
public static function create($name)
    {
        if (!isset(self::$_pool[$name])) {
            $classname = self::__getClassName($name);
            $path = self::__getDriverPath($name);

            if (!is_file($path)) {
                $errMsg = __('Could not find extension %s at location %s.', array(
                    '<code>' . $name . '</code>',
                    '<code>' . str_replace(DOCROOT . '/', '', $path) . '</code>'
                ));
                try {
                    Symphony::Engine()->throwCustomError(
                        $errMsg,
                        __('Symphony Extension Missing Error'),
                        Page::HTTP_STATUS_ERROR,
                        'missing_extension',
                        array(
                            'name' => $name,
                            'path' => $path
                        )
                    );
                } catch (Exception $ex) {
                    throw new Exception($errMsg, 0, $ex);
                }
            }

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

            // Create the extension object
            self::$_pool[$name] = new $classname(array());
        }

        return self::$_pool[$name];
    }
22142
public function getOption($name, $default = null)
    {
        if (!isset($this->options[$name])) {
            if (is_callable($default)) {
                $default = call_user_func($default);
            } if ($default instanceof \Exception) {
                throw $default;
            }
            return $default;
        }
        return $this->options[$name];
    }