You are here

protected static function AuthcacheP13nObjectFactory::parseReference in Authenticated User Page Caching (Authcache) 7.2

Utility function: Parse a string value.

The string value either may contain a literal or a resource reference. References start with an @-sign, followed by the resource name, optionally followed by a processor definition. I.e.: The string <code>@my resource[my processor(processor arg)]</code> references the resource named "my resource". Upon resolving this resource a processor function will alter it before it is returned.

Return value

array An array with integer indexes containing the four values:

  • literal or NULL: The literal value if no ressource reference was found.
  • resource name or NULL: The name of a resource if a reference is present.
  • processor function name or NULL: (Optional) The name of a reference processor.
  • processor argument or NULL: (Optional) The argument for a reference processor.

Either literal or resource name is always set.

1 call to AuthcacheP13nObjectFactory::parseReference()
AuthcacheP13nObjectFactory::resolveReferences in modules/authcache_p13n/includes/AuthcacheP13nObjectFactory.inc
Substitute resource references with their actual values.

File

modules/authcache_p13n/includes/AuthcacheP13nObjectFactory.inc, line 272
Defines the class AuthcacheP13nObjectFactory.

Class

AuthcacheP13nObjectFactory
A utility class helping with dependency injection.

Code

protected static function parseReference($value) {
  $nobr = '[^\\[\\]\\(\\)]';
  $regex = "#^@({$nobr}+)(\\[({$nobr}+)(\\]|\\(({$nobr}*)\\)\\]))?\$#";
  $literal = NULL;
  $rname = NULL;
  $proc = NULL;
  $procarg = NULL;
  if (strpos($value, '@@') === 0) {
    $literal = substr($value, 1);
  }
  elseif (preg_match($regex, $value, $matches)) {
    $rname = $matches[1];
    if (isset($matches[3])) {
      $proc = $matches[3];
    }
    if (isset($matches[5])) {
      $procarg = $matches[5];
    }
  }
  else {
    $literal = $value;
  }
  return array(
    $literal,
    $rname,
    $proc,
    $procarg,
  );
}