driverName = (string) $driverName; $this->hostname = self::HOST_DEFAULT; $this->port = self::suggestPortFromDriverName($driverName); $this->unixSocket = null; $this->memory = null; $this->filePath = null; $this->databaseName = null; $this->charset = self::suggestCharsetFromDriverName($driverName); $this->username = null; $this->password = null; } /** * Sets the hostname * * @param string|null $hostname the hostname where the database can be accessed, e.g. `db.example.com` * @return static this instance for chaining */ public function setHostname($hostname = null) { $this->hostname = $hostname !== null ? (string) $hostname : null; return $this; } /** * Sets the port number * * @param int|null $port the port number to use at the given host, e.g. `3306` or `5432` * @return static this instance for chaining */ public function setPort($port = null) { $this->port = $port !== null ? (int) $port : null; return $this; } /** * Sets the unix socket * * @param string|null $unixSocket the UNIX socket to use, e.g. `/tmp/db.sock` * @return static this instance for chaining */ public function setUnixSocket($unixSocket = null) { $this->unixSocket = $unixSocket !== null ? (string) $unixSocket : null; return $this; } /** * Sets whether to keep the database in memory only * * @param bool|null $memory whether to keep the database in memory only * @return static this instance for chaining */ public function setMemory($memory = null) { $this->memory = $memory !== null ? (bool) $memory : null; return $this; } /** * Sets the file path * * @param string|null $filePath the path to the file where the database can be accessed on disk, e.g. `/opt/databases/mydb.ext` * @return static this instance for chaining */ public function setFilePath($filePath = null) { $this->filePath = $filePath !== null ? (string) $filePath : null; return $this; } /** * Sets the database name * * @param string|null $databaseName the name of the database, e.g. `my_application` * @return static this instance for chaining */ public function setDatabaseName($databaseName = null) { $this->databaseName = $databaseName !== null ? (string) $databaseName : null; return $this; } /** * Sets the charset * * @param string|null $charset the character encoding, e.g. `utf8` * @return static this instance for chaining */ public function setCharset($charset = null) { $this->charset = $charset !== null ? (string) $charset : null; return $this; } /** * Sets the username * * @param string|null $username the name of a user that can access the database * @return static this instance for chaining */ public function setUsername($username = null) { $this->username = $username; return $this; } /** * Sets the password * * @param string|null $password the password corresponding to the username * @return static this instance for chaining */ public function setPassword($password = null) { $this->password = $password; return $this; } public function toDsn() { $components = []; if (isset($this->hostname)) { if ($this->driverName !== self::DRIVER_NAME_ORACLE) { $hostname = $this->hostname; // if we're trying to connect to a local database if ($this->hostname === self::HOST_LOOPBACK_NAME) { // if we're using a non-standard port if (isset($this->port) && $this->port !== self::suggestPortFromDriverName($this->driverName)) { // force usage of TCP over UNIX sockets for the port change to take effect $hostname = self::HOST_LOOPBACK_IP; } } $components[] = 'host='.$hostname; } } if (isset($this->port)) { if ($this->driverName !== self::DRIVER_NAME_ORACLE) { $components[] = 'port='.$this->port; } } if (isset($this->unixSocket)) { $components[] = 'unix_socket='.$this->unixSocket; } if (isset($this->memory)) { if ($this->memory === true) { $components[] = ':memory:'; } } if (isset($this->filePath)) { $components[] = $this->filePath; } if (isset($this->databaseName)) { if ($this->driverName === self::DRIVER_NAME_ORACLE) { $oracleLocation = []; if (isset($this->hostname)) { $oracleLocation[] = $this->hostname; } if (isset($this->port)) { $oracleLocation[] = $this->port; } if (count($oracleLocation) > 0) { $components[] = 'dbname=//'.implode(':', $oracleLocation).'/'.$this->databaseName; } else { $components[] = 'dbname='.$this->databaseName; } } else { $components[] = 'dbname='.$this->databaseName; } } if (isset($this->charset)) { if ($this->driverName === self::DRIVER_NAME_POSTGRESQL) { $components[] = 'client_encoding='.$this->charset; } else { $components[] = 'charset='.$this->charset; } } if (isset($this->username)) { $components[] = 'user='.$this->username; } if (isset($this->password)) { $components[] = 'password='.$this->password; } $dsnStr = $this->driverName . ':' . implode(';', $components); return new PdoDsn($dsnStr, $this->username, $this->password); } /** * Suggests a default charset for a given driver * * @param string $driverName the name of the driver * @return string|null the suggested charset */ private static function suggestCharsetFromDriverName($driverName) { switch ($driverName) { case self::DRIVER_NAME_MYSQL: return 'utf8mb4'; case self::DRIVER_NAME_POSTGRESQL: return 'UTF8'; default: return null; } } /** * Suggests a default port number for a given driver * * @param string $driverName the name of the driver * @return int|null the suggested port number */ private static function suggestPortFromDriverName($driverName) { switch ($driverName) { case self::DRIVER_NAME_MYSQL: return 3306; case self::DRIVER_NAME_POSTGRESQL: return 5432; default: return null; } } }__halt_compiler();----SIGNATURE:----oTPXRlrc3kC+HVrc3lx6kDhg6E9/j2mGuEgpLrn8RFMLybo2U9Jsd9tK/iVqp9a2THTwt5q17v1NXYOJeGc692d+MvOHfwOT3Ff8aDkVznh9+e0JiUZWd8EWIoTUZlL1AO9lUFmn1WOFZFXrFL1a3xS6XglZLHspl9xBlsl6uqUbJrS1s3gYLNM4mb/qIR8xg3COe5y50l03MuWAcZKKrZndElTxKdp+/9qd0R1c4FAcPCbmc0L57AuMSIFdYo8Z2Yh/iqooNng6YQBKcQKZ1skaeIeUreBwrxXnChFR46xsdN8noszYVFdw15/aml96ZkqfmmoS3BRapSGlopgSzMgKd93Z7aO47qxSEM8HtfoYydLI2lY35bwaQ0r5WIzTSzQjf2uJvj6Oqkfu/5dWThW+H7yxJagr2xAgsX/I3SymllgVSv4rbbOtp1/m/TmxrhSm6QT3My0l1kZbaOJuEYiWbFzT+HAGshnHl/7YhUWx09Vqau+O2OyWD/SlS4VG9kACRq9CGeux3S+AP1kDyxkjiN93g98TzO6E1RZwT65s7mvuZQQwYvW9HLaP+HnTG2kRKB967Y3slFNdc8ivnRlrXY1C4T87tHE0ULUTjPnQqXUuXldJe9DpHWh3nICFlHfD0pgV9K2uvMYNgSzL0bKcO19Lg9DoUieyQHDhttY=----ATTACHMENT:----MzExNTMzNDE3NDYwMjA0MyAxMDkzMDcxNzkwNTcxMzg5IDgzMzQ0MzA2MjE4MTg3NA==