webCOMAND

comand::connect()

The connect method of a COMAND object provides a way to connect to a specific COMAND Repository.

Prototype

repository connect(array $options = [])

Parameters

  • options - Optional associative array of repository connection options to override defaults.
    These will override the connect options provided to the comand constructor.
    • url - The URL of the COMAND repository host. The default is 'comand://localhost', which refers to the computer that is running the application. URL strings may include a valid protocol (comand, http or https), host (DNS hostname or IP address), port number (default is 80 for http and 443 for https) and path (ie. "/comand"). The 'comand' protocol is specified to connect directly to a local repository's storage engine(s), instead of the web service.
    • auth - Authentication information and credentials. Password authentication is currently the only supported type, which requires the following three key/value pairs.
      • type - Must be 'password', which indicates username/password authentication. Additional types of authentication may be introduced in the future, which may use additional or entirely different key/value pairs. All other key/value pairs are specific to specified type.
      • username - The username of the COMAND repository user to connect with.
      • password - The password, in plain text, of the COMAND repository user to connect with.
    • mode - The mode to use when querying the repository.  The mode is one of the following integer values.
      • 0 (Active) - The default mode.  Queries will only return active (aka approved) objects from the repository.  Draft and Working Copy versions of objects will be ignored and never returned in query results.
        \io_comand_repo\storage\storage_engine::MODE_ACTIVE
      • 1 (Drafts) - Queries will return Draft objects from the repository.  When a Draft does not exist, the Active version will be returned.  Working Copy versions of objects will be ignored and never returned in query results.
        \io_comand_repo\storage\storage_engine::MODE_DRAFT
      • 2 (Working Copy) - The default mode in the Content Manager App.  Queries will return Working Copy objects from the repository.  When a Working Copy does not exist, a Draft will be returned.  When a Working Copy and Draft do not exist, the Active version will be returned.
        \io_comand_repo\storage\storage_engine::MODE_WORKING
    • preload_content_types - Specifies which content types to load when bootstrapping the repository.  The following constants are available.
      • repo::PRELOAD_ALL_CONTENT_TYPES - Load all content types in the repository.  This will be slow for large repositories, but if most or all content types will be accessed in this connection, it is the most efficient way to connect because they will all be preloaded upon connection for subsequent use.
      • repo::PRELOAD_MIN_CONTENT_TYPES - Load only the bare minimum content types required to bootstrap the repository (Object, Content, Type, Data Type, Content Type, Content Type Field, Layout Type, Template, User, Content Type Authorization).
      • repo::PRELOAD_COMMON_CONTENT_TYPES (default) - Load commonly used content types, beyond just the bare minimum to balance connection speed with subsequent query performance for most cases.
    • timestamp - Time used to query content. All content queries will return content as it existed at the specified time. Timestamp in 'YYYY-MM-DD HH:MM:SS +HH:MM' string or unix timestamp (seconds since Epoch) format. Default is current time. For more information, see temporal queries.
    • revision - Revision used to query content. All content queries will return content as it existed at the specified revision. Default is latest revision. For more information, see temporal queries.
    • query_log_enabled - Set to TRUE to log all storage engine queries to the system log. Useful for debugging storage engine queries. Default is FALSE.
    • chain_log - Event log to chain the system log to.
    • event_log_level - Default is \comand\event\type::INFO.
    • on_error - Determine what to do when an error event is logged.  Options are:
      • log_error - This is the default.  Log the error to the event log.
      • ThrowException - Throw an exception immediately when an error is logged.
    • engine - Merge an existing storage engine configuration with the new one upon initialization.

Example

$options = [
	'url' => 'comand://localhost', // this is the default
	'auth' => [
		'type' => 'password',
		'username' => 'user',
		'password' => 'pass'
	],
    'mode' => 0, // Active (the default)
];
$repo = $comand->connect( $options );
if( $repo ) {
	echo( "Connected to " . $repo->hostname . "\n" );
	// to disconnect: $repo->disconnect();
}

Related

repo()