/** * Read the configuration or access the connections you have set up. * * Usage: * {{{ * // Gets the names of all available configurations * $configurations = Connections::get(); * * // Gets the configuration array for the connection named 'db' * $config = Connections::get('db', array('config' => true)); * * // Gets the instance of the connection object, configured with the settings defined for * // this object in Connections::add() * $dbConnection = Connection::get('db'); * * // Gets the connection object, but only if it has already been built. * // Otherwise returns null. * $dbConnection = Connection::get('db', array('autoCreate' => false)); * }}} * * @param string $name The name of the connection to get, as defined in the first parameter of * `add()`, when the connection was initially created. * @param array $options Options to use when returning the connection: * - `'autoCreate'`: If `false`, the connection object is only returned if it has * already been instantiated by a previous call. * - `'config'`: If `true`, returns an array representing the connection's internal * configuration, instead of the connection itself. * @return mixed A configured instance of the connection, or an array of the configuration used. */ public static function get($name = null, $options = array()) { $defaults = array('config' => false, 'autoCreate' => true); $options += $defaults; if (empty($name)) { return static::$_configurations->keys(); } if (!isset(static::$_configurations[$name])) { return null; } if ($options['config']) { return static::_config($name); } $settings = static::$_configurations[$name]; if (!isset($settings[0]['adapter']) || !is_object($settings[0]['adapter'])) { if (!$options['autoCreate']) { return null; } } return static::adapter($name); }
/** * Tests getting the index of the internal array. * * @return void */ public function testInternalKeys() { $collection = new Collection(array('data' => array('foo', 'bar', 'baz' => 'dib'))); $this->assertEqual(array(0, 1, 'baz'), $collection->keys()); }
/** * Returns the item keys. * * @return array The keys of the items. */ public function keys() { $this->offsetGet(null); return parent::keys(); }