Вход Регистрация
Файл: concrete5.7.5.6/concrete/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php
Строк: 358
<?php
/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license. For more information, see
 * <http://www.doctrine-project.org>.
 */

namespace DoctrineDBAL;

use 
DoctrineDBALDriverDriverException;
use 
DoctrineDBALDriverExceptionConverterDriver;

class 
DBALException extends Exception
{
    
/**
     * @param string $method
     *
     * @return DoctrineDBALDBALException
     */
    
public static function notSupported($method)
    {
        return new 
self("Operation '$method' is not supported by platform.");
    }

    
/**
     * @return DoctrineDBALDBALException
     */
    
public static function invalidPlatformSpecified()
    {
        return new 
self(
            
"Invalid 'platform' option specified, need to give an instance of ".
            
"DoctrineDBALPlatformsAbstractPlatform.");
    }

    
/**
     * Returns a new instance for an invalid specified platform version.
     *
     * @param string $version        The invalid platform version given.
     * @param string $expectedFormat The expected platform version format.
     *
     * @return DBALException
     */
    
public static function invalidPlatformVersionSpecified($version$expectedFormat)
    {
        return new 
self(
            
sprintf(
                
'Invalid platform version "%s" specified. ' .
                
'The platform version has to be specified in the format: "%s".',
                
$version,
                
$expectedFormat
            
)
        );
    }

    
/**
     * @return DoctrineDBALDBALException
     */
    
public static function invalidPdoInstance()
    {
        return new 
self(
            
"The 'pdo' option was used in DriverManager::getConnection() but no ".
            
"instance of PDO was given."
        
);
    }

    
/**
     * @return DoctrineDBALDBALException
     */
    
public static function driverRequired()
    {
        return new 
self("The options 'driver' or 'driverClass' are mandatory if no PDO ".
            
"instance is given to DriverManager::getConnection().");
    }

    
/**
     * @param string $unknownDriverName
     * @param array  $knownDrivers
     *
     * @return DoctrineDBALDBALException
     */
    
public static function unknownDriver($unknownDriverName, array $knownDrivers)
    {
        return new 
self("The given 'driver' ".$unknownDriverName." is unknown, ".
            
"Doctrine currently supports only the following drivers: ".implode(", "$knownDrivers));
    }

    
/**
     * @param DoctrineDBALDriver     $driver
     * @param Exception $driverEx
     * @param string     $sql
     * @param array      $params
     *
     * @return DoctrineDBALDBALException
     */
    
public static function driverExceptionDuringQuery(Driver $driverException $driverEx$sql, array $params = array())
    {
        
$msg "An exception occurred while executing '".$sql."'";
        if (
$params) {
            
$msg .= " with params " self::formatParameters($params);
        }
        
$msg .= ":nn".$driverEx->getMessage();

        if (
$driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverException) {
            return 
$driver->convertException($msg$driverEx);
        }

        return new 
self($msg0$driverEx);
    }

    
/**
     * @param DoctrineDBALDriver     $driver
     * @param Exception $driverEx
     *
     * @return DoctrineDBALDBALException
     */
    
public static function driverException(Driver $driverException $driverEx)
    {
        
$msg "An exception occured in driver: " $driverEx->getMessage();

        if (
$driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverException) {
            return 
$driver->convertException($msg$driverEx);
        }

        return new 
self($msg0$driverEx);
    }

    
/**
     * Returns a human-readable representation of an array of parameters.
     * This properly handles binary data by returning a hex representation.
     *
     * @param array $params
     *
     * @return string
     */
    
private static function formatParameters(array $params)
    {
        return 
'[' implode(', 'array_map(function ($param) {
            
$json = @json_encode($param);

            if (! 
is_string($json) || $json == 'null' && is_string($param)) {
                
// JSON encoding failed, this is not a UTF-8 string.
                
return '"x' implode('x'str_split(bin2hex($param), 2)) . '"';
            }

            return 
$json;
        }, 
$params)) . ']';
    }

    
/**
     * @param string $wrapperClass
     *
     * @return DoctrineDBALDBALException
     */
    
public static function invalidWrapperClass($wrapperClass)
    {
        return new 
self("The given 'wrapperClass' ".$wrapperClass." has to be a ".
            
"subtype of DoctrineDBALConnection.");
    }

    
/**
     * @param string $driverClass
     *
     * @return DoctrineDBALDBALException
     */
    
public static function invalidDriverClass($driverClass)
    {
        return new 
self("The given 'driverClass' ".$driverClass." has to implement the ".
            
"DoctrineDBALDriver interface.");
    }

    
/**
     * @param string $tableName
     *
     * @return DoctrineDBALDBALException
     */
    
public static function invalidTableName($tableName)
    {
        return new 
self("Invalid table name specified: ".$tableName);
    }

    
/**
     * @param string $tableName
     *
     * @return DoctrineDBALDBALException
     */
    
public static function noColumnsSpecifiedForTable($tableName)
    {
        return new 
self("No columns specified for table ".$tableName);
    }

    
/**
     * @return DoctrineDBALDBALException
     */
    
public static function limitOffsetInvalid()
    {
        return new 
self("Invalid Offset in Limit Query, it has to be larger or equal to 0.");
    }

    
/**
     * @param string $name
     *
     * @return DoctrineDBALDBALException
     */
    
public static function typeExists($name)
    {
        return new 
self('Type '.$name.' already exists.');
    }

    
/**
     * @param string $name
     *
     * @return DoctrineDBALDBALException
     */
    
public static function unknownColumnType($name)
    {
        return new 
self('Unknown column type "'.$name.'" requested. Any Doctrine type that you use has ' .
            
'to be registered with DoctrineDBALTypesType::addType(). You can get a list of all the ' .
            
'known types with DoctrineDBALTypesType::getTypesMap(). If this error occurs during database ' .
            
'introspection then you might have forgot to register all database types for a Doctrine Type. Use ' .
            
'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' .
            
'Type#getMappedDatabaseTypes(). If the type name is empty you might ' .
            
'have a problem with the cache or forgot some mapping information.'
        
);
    }

    
/**
     * @param string $name
     *
     * @return DoctrineDBALDBALException
     */
    
public static function typeNotFound($name)
    {
        return new 
self('Type to be overwritten '.$name.' does not exist.');
    }
}
Онлайн: 1
Реклама