Skip to content

Commit

Permalink
move compare function into constructor, #116
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkez committed Jun 18, 2018
1 parent edc767a commit 707f010
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
Copyright (c) 2009-2017 F3::Factory/Bong Cosca, All rights reserved.
Copyright (c) 2009-2018 F3::Factory/Bong Cosca, All rights reserved.
This file is part of the Fat-Free Framework (http://fatfreeframework.com).
Expand Down Expand Up @@ -35,36 +35,37 @@ class Auth {
//! Mapper object
$mapper,
//! Storage options
$args;
$args,
//! Custom compare function
$func;

/**
* Jig storage handler
* @return bool
* @param $id string
* @param $pw string
* @param $realm string
* @param $func callable
**/
protected function _jig($id,$pw,$realm,$func) {
protected function _jig($id,$pw,$realm) {
$success = (bool)
call_user_func_array(
[$this->mapper,'load'],
[
array_merge(
[
'@'.$this->args['id'].'==?'.
($func?'':' AND @'.$this->args['pw'].'==?').
($this->func?'':' AND @'.$this->args['pw'].'==?').
(isset($this->args['realm'])?
(' AND @'.$this->args['realm'].'==?'):''),
$id
],
($func?[]:[$pw]),
($this->func?[]:[$pw]),
(isset($this->args['realm'])?[$realm]:[])
)
]
);
if ($success && $func)
$success = call_user_func($func,$pw,$this->mapper->get($this->args['pw']));
if ($success && $this->func)
$success = call_user_func($this->func,$pw,$this->mapper->get($this->args['pw']));
return $success;
}

Expand All @@ -74,18 +75,17 @@ protected function _jig($id,$pw,$realm,$func) {
* @param $id string
* @param $pw string
* @param $realm string
* @param $func callable
**/
protected function _mongo($id,$pw,$realm,$func) {
protected function _mongo($id,$pw,$realm) {
$success = (bool)
$this->mapper->load(
[$this->args['id']=>$id]+
($func?[]:[$this->args['pw']=>$pw])+
($this->func?[]:[$this->args['pw']=>$pw])+
(isset($this->args['realm'])?
[$this->args['realm']=>$realm]:[])
);
if ($success && $func)
$success = call_user_func($func,$pw,$this->mapper->get($this->args['pw']));
if ($success && $this->func)
$success = call_user_func($this->func,$pw,$this->mapper->get($this->args['pw']));
return $success;
}

Expand All @@ -95,28 +95,27 @@ protected function _mongo($id,$pw,$realm,$func) {
* @param $id string
* @param $pw string
* @param $realm string
* @param $func callable
**/
protected function _sql($id,$pw,$realm,$func) {
protected function _sql($id,$pw,$realm) {
$success = (bool)
call_user_func_array(
[$this->mapper,'load'],
[
array_merge(
[
$this->args['id'].'=?'.
($func?'':' AND '.$this->args['pw'].'=?').
($this->func?'':' AND '.$this->args['pw'].'=?').
(isset($this->args['realm'])?
(' AND '.$this->args['realm'].'=?'):''),
$id
],
($func?[]:[$pw]),
($this->func?[]:[$pw]),
(isset($this->args['realm'])?[$realm]:[])
)
]
);
if ($success && $func)
$success = call_user_func($func,$pw,$this->mapper->get($this->args['pw']));
if ($success && $this->func)
$success = call_user_func($this->func,$pw,$this->mapper->get($this->args['pw']));
return $success;
}

Expand Down Expand Up @@ -205,10 +204,9 @@ protected function _smtp($id,$pw) {
* @param $id string
* @param $pw string
* @param $realm string
* @param $func callable
**/
function login($id,$pw,$realm=NULL,$func=NULL) {
return $this->{'_'.$this->storage}($id,$pw,$realm,$func);
function login($id,$pw,$realm=NULL) {
return $this->{'_'.$this->storage}($id,$pw,$realm);
}

/**
Expand Down Expand Up @@ -247,8 +245,9 @@ function basic($func=NULL) {
* @return object
* @param $storage string|object
* @param $args array
* @param $func callback
**/
function __construct($storage,array $args=NULL) {
function __construct($storage,array $args=NULL,$func=NULL) {
if (is_object($storage) && is_a($storage,'DB\Cursor')) {
$this->storage=$storage->dbtype();
$this->mapper=$storage;
Expand All @@ -257,6 +256,7 @@ function __construct($storage,array $args=NULL) {
else
$this->storage=$storage;
$this->args=$args;
$this->func=$func;
}

}

0 comments on commit 707f010

Please sign in to comment.