Skip to content
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

Add ConnectionDefinition, remove ConnectionOptions #21

Open
olvlvl opened this issue Nov 12, 2016 · 0 comments
Open

Add ConnectionDefinition, remove ConnectionOptions #21

olvlvl opened this issue Nov 12, 2016 · 0 comments

Comments

@olvlvl
Copy link
Member

olvlvl commented Nov 12, 2016

Currently PDO parameters are still defined using magic strings: dsn, username, and password. We should add a class to use proper constants, and include connection options too:

<?php

namespace ICanBoogie\ActiveRecord;

interface ConnectionDefinition
{
	/**
	 * The Data Source Name.
	 */
	const DSN = 'dsn';
	
	/**
	 * The user name for the DSN string. This parameter is optional for some PDO drivers. 
	 */
	const USERNAME = 'username';
	
	/**
	 * The password for the DSN string. This parameter is optional for some PDO drivers.
	 */
	const PASSWORD = 'password';
	
	/**
	 * A key=>value array of driver-specific connection options.
	 */
	const DRIVER_OPTIONS = 'driver_options';

	/**
	 * Connection identifier.
	 */
	const OPTION_ID = '#id';

	/**
	 * Charset and collate.
	 *
	 * Default: {@link DEFAULT_CHARSET_AND_COLLATE}.
	 */
	const OPTION_CHARSET_AND_COLLATE = '#charset_and_collate';

	/**
	 * Table name prefix.
	 */
	const OPTION_TABLE_NAME_PREFIX = '#table_name_prefix';

	/**
	 * Time zone offset used for the connection.
	 *
	 * Default: {@link DEFAULT_TIMEZONE}.
	 */
	const OPTION_TIMEZONE = '#timezone';
	
	/**
	 * Default user name.
	 */
	const DEFAULT_USERNAME = 'root';
	
	/**
	 * Default password.
	 */
	const DEFAULT_PASSWORD = null;
	
	/**
	 * Default driver options.
	 */
	const DEFAULT_DRIVER_OPTIONS = [];

	/**
	 * Default charset.
	 */
	const DEFAULT_OPTION_CHARSET = 'utf8';

	/**
	 * Default collate.
	 */
	const DEFAULT_OPTION_COLLATE = 'utf8_general_ci';

	/**
	 * Default value for {@link CHARSET_AND_COLLATE}.
	 */
	const DEFAULT_OPTION_CHARSET_AND_COLLATE = "utf8/general_ci";

	/**
	 * Default value for {@link DEFAULT_TABLE_NAME_PREFIX}.
	 */
	const DEFAULT_OPTION_TABLE_NAME_PREFIX = '';

	/**
	 * Default value for {@link TIMEZONE}.
	 */
	const DEFAULT_OPTION_TIMEZONE = '+00:00';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant