Skip to content

Pass credentials as parameters #753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/Jenssegers/Mongodb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ protected function createConnection($dsn, array $config, array $options)
$driverOptions = $config['driver_options'];
}

// Check if the credentials are not already set in the options
if (!isset($options['username']) && isset($config['username'])) {
$options['username'] = $config['username'];
}
if (!isset($options['password']) && isset($config['password'])) {
$options['password'] = $config['password'];
}

return new Client($dsn, $options, $driverOptions);
}

Expand Down Expand Up @@ -175,20 +183,7 @@ protected function getDsn(array $config)
}
}

// The database name needs to be in the connection string, otherwise it will
// authenticate to the admin database, which may result in permission errors.
$auth = '';
if (! empty($username)) {
$auth .= $username;
}
if (! empty($password)) {
$auth .= ':' . urlencode($password);
}
if ($auth) {
$auth .= '@';
}

return "mongodb://" . $auth . implode(',', $hosts) . "/{$database}";
return "mongodb://" . implode(',', $hosts) . "/{$database}";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Jenssegers/Mongodb/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function drop()
* @param array $parameters
* @return Blueprint
*/
protected function addColumn($type, $name, array $parameters = [])
public function addColumn($type, $name, array $parameters = [])
{
$this->fluent($name);

Expand Down