解析FTP DSN
array Core_Ftp::parse_dsn( string $dsn )
参数列表
参数 类型 描述 默认值 $dsn
string
DSN string
array
protected static function parse_dsn($dsn)
{
$ftp = array
(
'username' => false,
'password' => false,
'hostname' => false,
'port' => false,
'passive' => false,
'path' => false,
);
// Get the protocol and arguments
list ($type, $connection) = explode('://', $dsn, 2);
if ($connection[0] === '/')
{
// Strip leading slash
$ftp['dir'] = substr($connection, 1);
}
else
{
$connection = parse_url('http://' . $connection);
if (isset($connection['user']))
{
$ftp['username'] = $connection['user'];
}
if (isset($connection['pass']))
{
$ftp['password'] = $connection['pass'];
}
if (isset($connection['port']))
{
$ftp['port'] = $connection['port'];
}
if (isset($connection['host']))
{
if ($connection['host'] === 'unix(')
{
list ($ftp['passive'], $connection['path']) = explode(')', $connection['path'], 2);
}
else
{
$ftp['hostname'] = $connection['host'];
}
}
if (isset($connection['path']) && $connection['path'])
{
$ftp['path'] = substr($connection['path'], 1);
}
}
return $ftp;
}