Created
March 29, 2011 17:31
-
-
Save simshaun/892824 to your computer and use it in GitHub Desktop.
Overload A1 to integrate Bonafide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') OR die('No direct access allowed.'); | |
abstract class A1 extends A1_Core { | |
/** | |
* @param Bonafide | |
*/ | |
protected $_bonafide; | |
/** | |
* Return a static instance of A1. | |
* | |
* @return object | |
*/ | |
public static function instance($_name = 'a1') | |
{ | |
static $_instances; | |
if ( ! isset($_instances[$_name])) | |
{ | |
$_config = Kohana::config($_name); | |
$_driver = isset($_config['driver']) ? $_config['driver'] : 'ORM'; | |
$_class = 'A1_' . ucfirst($_driver); | |
$_bonafide = Bonafide::instance(); | |
$_instances[$_name] = new $_class($_name, $_config, $_bonafide); | |
} | |
return $_instances[$_name]; | |
} | |
/** | |
* Loads Session and configuration options. | |
* | |
* @return void | |
*/ | |
protected function __construct($_name = 'a1', $_config, $_bonafide) | |
{ | |
$this->_bonafide = $_bonafide; | |
parent::__construct($_name, $_config); | |
} | |
/** | |
* Generates hash for input | |
* | |
* @param string value to hash | |
* @param string salt (optional, will be generated if missing) | |
* @param int cost (optional, will be read from config if missing) | |
* @return string hashed input value | |
*/ | |
public function hash($password, $salt = NULL, $cost = NULL) | |
{ | |
return $this->_bonafide->hash($password); | |
} | |
/** | |
* Checks if password matches hash | |
* | |
* @param string password | |
* @param string hashed password | |
* @return boolean password matches hashed password | |
*/ | |
public function check($password, $hash) | |
{ | |
return $this->_bonafide->check($password, $hash); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment