dre1080 / warden

More than just a user database auth package for FuelPHP
http://dre1080.github.com/warden
MIT License
46 stars 11 forks source link

has_access yields error when using array with roles to check for #24

Closed marcterhorst closed 11 years ago

marcterhorst commented 11 years ago

First of all: thanks for this great auth package. I found an incorrect behaviour when using has_access with an array of roles to check for.

Code: if (Warden::logged_in(array('y','x'))) [...]

will yield: ErrorException [ Notice ]: Trying to get property of non-object

This may have to do with array_udiff behaviour. PHP version 5.3.3

With this simplified use you'll notice the behaviour:

$a1 = array(1,2); $a2 = array(3,4);

        $res = array_udiff($a1, $a2, function ($x, $y) {

            // compare each given role against the user's roles
            echo "compare $x with $y<br />";
            return $x != $y;
        });

        print_r($res);

So, in the has_access method $ur will not always be an object, and thus $ur->name yields an error.

Additionally, the inline documentation states ' @param \Warden\Model_User $user The user to check against, if no user is given (null) * it will check against the currently logged in user'.

It doesn't.

Thanks again!

dre1080 commented 11 years ago

$ur is meant to always be a Model_Role object Have you tried dumping to see what $ur is when you run your Warden::logged_in(array('y','x'))?

dre1080 commented 11 years ago

closing as no response