Permalink
Browse files

$components array is now used for settings

old: Configure::write('use_database', true);
new: public $components = array('Openid' => array('use_database' =>
true));

The same applies for 'database_config'.
  • Loading branch information...
1 parent ecd28ed commit fa6b4a3073588ec146209859a68422e43a070ad8 @cakebaker committed Aug 16, 2009
Showing with 23 additions and 14 deletions.
  1. +23 −14 controllers/components/openid.php
@@ -10,39 +10,51 @@
* To use the MySQLStore, the following steps are required:
* - get PEAR DB: http://pear.php.net/package/DB
* - run the openid.sql script to create the required tables
- * - add Configure::write('Openid.use_database', true); to the file which uses
- * the OpenID component (e.g. users_controller.php) or to app/config/bootstrap.php
- * - if you want to use a database configuration other than "default", also add
- * Configure::write('Openid.database_config', 'name_of_database_config');
+ * - use one of the following config settings when adding the component to the $components array of your controller(s):
+ * public $components = array('Openid' => array('use_database' => true)); // uses the "default" database configuration
+ * public $components = array('Openid' => array('database_config' => 'name_of_database_config'));
*
* Copyright (c) by Daniel Hofstetter (http://cakebaker.42dh.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class OpenidComponent extends Object {
private $controller = null;
private $importPrefix = '';
+ private $useDatabase = false;
+ private $databaseConfig = 'default';
public function __construct() {
parent::__construct();
$pathToVendorsFolder = $this->getPathToVendorsFolderWithOpenIDLibrary();
-
+
if ($pathToVendorsFolder == '') {
exit('Unable to find the PHP OpenID library');
}
-
+
if ($this->isPathWithinPlugin($pathToVendorsFolder)) {
$this->importPrefix = $this->getPluginName() . '.';
}
-
+
$this->addToIncludePath($pathToVendorsFolder);
$this->importCoreFilesFromOpenIDLibrary();
}
+ public function initialize($controller, $settings) {
+ if (isset($settings['use_database'])) {
+ $this->useDatabase = $settings['use_database'];
+ }
+
+ if (isset($settings['database_config'])) {
+ $this->databaseConfig = $settings['database_config'];
+ $this->useDatabase = true;
+ }
+ }
+
public function startUp($controller) {
$this->controller = $controller;
}
@@ -144,10 +156,7 @@ private function getFileStore() {
private function getMySQLStore() {
App::import('Vendor', $this->importPrefix.'mysqlstore', array('file' => 'Auth'.DS.'OpenID'.DS.'MySQLStore.php'));
-
- $databaseConfig = Configure::read('Openid.database_config');
- $databaseConfig = ($databaseConfig == null) ? 'default' : $databaseConfig;
- $dataSource = ConnectionManager::getDataSource($databaseConfig);
+ $dataSource = ConnectionManager::getDataSource($this->databaseConfig);
$dsn = array(
'phptype' => 'mysql',
@@ -210,7 +219,7 @@ private function getQuery() {
private function getStore() {
$store = null;
- if (Configure::read('Openid.use_database') === true) {
+ if ($this->useDatabase) {
$store = $this->getMySQLStore();
} else {
$store = $this->getFileStore();
@@ -239,4 +248,4 @@ private function transformEmailToOpenID($email) {
throw new InvalidArgumentException('Invalid OpenID');
}
-}
+}

0 comments on commit fa6b4a3

Please sign in to comment.