class AuthcacheP13nFragmentBuilder in Authenticated User Page Caching (Authcache) 7.2
Content builder for personalized content fragments.
Hierarchy
Expanded class hierarchy of AuthcacheP13nFragmentBuilder
2 string references to 'AuthcacheP13nFragmentBuilder'
- AuthcacheP13nTestRequestBuilder::testRequestResourcesNullFragments in modules/
authcache_p13n/ tests/ authcache_p13n.request-builder.test - Cover authcache_p13n_request_resources().
- authcache_p13n_authcache_p13n_request in modules/
authcache_p13n/ authcache_p13n.module - Implements hook_authcache_p13n_request().
File
- modules/
authcache_p13n/ includes/ AuthcacheP13nFragmentBuilder.inc, line 10 - Defines AuthcacheP13nFragmentBuilder
View source
class AuthcacheP13nFragmentBuilder implements AuthcacheP13nContentBuilderInterface, AuthcacheP13nRequestValidatorInterface {
/**
* @var AuthcacheP13nFragment
*/
protected $fragment;
/**
* @var AuthcacheP13nFragmentValidator
*/
protected $validator;
/**
* @var AuthcacheP13nFragmentLoader
*/
protected $loader;
/**
* @var AuthcacheP13nFragmentAccess
*/
protected $access;
/**
* Construct new instance.
*
* @param AuthcacheP13nFragment $fragment
* The fragment object to use.
* @param AuthcacheP13nFragmentValidator $validator
* (optional) The validator object.
* @param AuthcacheP13nFragmentLoader $loader
* The loader object.
* @param AuthcacheP13nFragmentAccess $access
* The access checker.
*/
public function __construct($fragment, $validator, $loader, $access) {
$this->fragment = $fragment;
$this->validator = $validator;
$this->loader = $loader;
$this->access = $access;
}
/**
* {@inheritdoc}
*/
public function validate($req) {
// Normalize request parameter.
$param = empty($req['a']) ? array() : array(
$req['a'] => $req['a'],
);
// Run validator.
if ($this->validator) {
$param = $this->validator
->validate($param);
}
$req['a'] = $param;
return $req;
}
/**
* {@inheritdoc}
*/
public function build($req, $context) {
global $user;
$params = $req['a'];
// Run loader.
if ($this->loader) {
$params = $this->loader
->load($params, $context);
}
$key = key($params);
$subject = current($params);
// Run access check.
if ($this->access && !$this->access
->check($user, $key, $subject, $context)) {
throw new AuthcacheP13nRequestAccessDenied();
}
else {
return $this->fragment
->render($key, $subject, $context);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AuthcacheP13nFragmentBuilder:: |
protected | property | ||
AuthcacheP13nFragmentBuilder:: |
protected | property | ||
AuthcacheP13nFragmentBuilder:: |
protected | property | ||
AuthcacheP13nFragmentBuilder:: |
protected | property | ||
AuthcacheP13nFragmentBuilder:: |
public | function |
Build and return the content defined by the input parameters. Overrides AuthcacheP13nContentBuilderInterface:: |
|
AuthcacheP13nFragmentBuilder:: |
public | function |
Validate and sanitize a request. Overrides AuthcacheP13nRequestValidatorInterface:: |
|
AuthcacheP13nFragmentBuilder:: |
public | function | Construct new instance. |