Created
August 17, 2012 07:50
-
-
Save notomato/3376825 to your computer and use it in GitHub Desktop.
Example li3_access configuration and use
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 | |
// config/bootstrap/access.php | |
Access::config(array( | |
'asset' => array( | |
'adapter' => 'Rules', | |
'allowAny' => true, | |
'default' => array('isPublic', 'isOwner', 'isParticipant'), | |
'user' => function() { return Accounts::current(); }, | |
'rules' => array( | |
'isPublic' => function($user, $asset, $options) { | |
//... | |
}, | |
'isOwner' => function($user, $asset, $options) { | |
//... | |
}, | |
'isParticipant' => function($user, $asset, $options) { | |
//... | |
} | |
) | |
) | |
//... | |
)); | |
Access::config(array( | |
//... | |
'action' => array( | |
'adapter' => 'Rules', | |
'default' => array('isPublic', 'isAuthenticated'), | |
'allowAny' => true, | |
'user' => function() { return Accounts::current(); }, | |
'rules' => array( | |
'isPublic' => function($user, $request, array $options) { | |
//... | |
}, | |
'isAuthenticated' => function($user, $request, array $options) { | |
//... | |
}, | |
'isAdmin' => function($user, $asset, $options) { | |
//... | |
} | |
) | |
) | |
)); | |
Dispatcher::applyFilter('_call', function($self, $params, $chain) { | |
$opts = $params['params']; | |
$request = $params['request']; | |
$ctrl = $params['callable']; | |
if ($access = Access::check('action', null, $ctrl, $opts)) { | |
// Reject | |
} | |
if ($access = Access::check('action', null, $ctrl, array('rules' => 'isAdmin') + $opts)) { | |
// Reject | |
} | |
return $chain->next($self, $params, $chain); | |
}); | |
// app/controllers/PostsController.php | |
class PostsController extends Base { | |
public $publicActions = array('index', 'view'); | |
} | |
// source: http://www.slideshare.net/nateabele/the-state-of-lithium |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment