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:----Vr02XC3fwSUyJQU1O2hMbESh9L5nipGSaE4h3x8quObgKOVK935QzAz6qtaWilG0H3rEFeZ8OUUc7DJN6pmObepkg4Tn0ZPbQfNH4dVxcEQO+cxfee0Ty/rYnM9gN4whoHHwHerrb1R+9eZB4Bq6KmsSjnbokuQsnbEnD3L6xsOxaCB4StvILEP0k5Dsy7Jv+Wt3gePG6I4KQgfP6NV9XGKx0m+9jcRsbmS8jUBm9kkIr2TNvp+8hAjUIT76f2QiC4Fh1fuZLPaEPFmRj6XKGWDkcwR6T+KphxPZUQ720B7P15nYGd9FWq9DKG77FY9W2jwvCkVLpI4clsugIj0uJMmIH8aAURffJ+qin6HvL5VsU0PpSK8YOEoI5RZSjCqbVqNzoBbEYOk0GfpwXZKyj83CbbLtqBIgjRtPzelXrDrN0jnb0fAIqDM+6eSFN1JK7LeWm+EzT9hrYXAUzRDQAG8Wq2zbtfZGOg9Tzja1IgVulYIVKAarTqA02lBAuZBlGp6++COjsBQZQ/5CJDnlKSidDD+gHcMPPGkWa4LS8Ny/UYklEEMBagxiDVjI3b7LqpxvUHub8QHRm2lJNBUYjyoFZBaZwN6dX5AF+SDfxiFM7SS8y7zDFf0iYOdD64CBotSCCvQXx0rLqi3Uib0Y+Nx46zRce2wbodu99+uylx8=----ATTACHMENT:----NzA0MDQ3MjIzMjQ2MzcwMSAzNDYwODU1MzMwMjU2ODMwIDQ2NTYyMDI2NzAzNjg4NzI=