class SerializableClosureWrapper in X Autoload 7.5
A wrapper that allows serialization of closures from hook_libraries_info().
Hierarchy
- class \Drupal\xautoload\Libraries\SerializableClosureWrapper
Expanded class hierarchy of SerializableClosureWrapper
1 file declares its use of SerializableClosureWrapper
File
- src/
Libraries/ SerializableClosureWrapper.php, line 9
Namespace
Drupal\xautoload\LibrariesView source
class SerializableClosureWrapper {
/**
* The closure
*
* @var \Closure
*/
private $closure;
/**
* Module that implements hook_libraries_info()
*
* @var string
*/
private $moduleName;
/**
* Name of the library that has this closure for xautoload.
*
* @var string
*/
private $libraryName;
/**
* @param \Closure $closure
* @param string $moduleName
* @param string $libraryName
*/
public function __construct($closure, $moduleName, $libraryName) {
$this->closure = $closure;
$this->moduleName = $moduleName;
$this->libraryName = $libraryName;
}
public function __sleep() {
return array(
'moduleName',
'libraryName',
);
}
/**
* @param \Drupal\xautoload\Adapter\LocalDirectoryAdapter $adapter
*/
public function __invoke($adapter) {
$closure = $this
->lazyGetClosure();
if ($closure instanceof \Closure) {
$closure($adapter);
}
}
/**
* @return \Closure|FALSE
*/
private function lazyGetClosure() {
return isset($this->closure) ? $this->closure : ($this->closure = $this
->loadClosure());
}
/**
* @return \Closure|FALSE
*/
private function loadClosure() {
$source_function = $this->moduleName . '_libraries_info';
if (!function_exists($source_function)) {
return FALSE;
}
$module_libraries = $source_function();
if (!isset($module_libraries[$this->libraryName]['xautoload'])) {
return FALSE;
}
$closure_candidate = $module_libraries[$this->libraryName]['xautoload'];
if (!$closure_candidate instanceof \Closure) {
return FALSE;
}
return $closure_candidate;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SerializableClosureWrapper:: |
private | property | The closure | |
SerializableClosureWrapper:: |
private | property | Name of the library that has this closure for xautoload. | |
SerializableClosureWrapper:: |
private | property | Module that implements hook_libraries_info() | |
SerializableClosureWrapper:: |
private | function | ||
SerializableClosureWrapper:: |
private | function | ||
SerializableClosureWrapper:: |
public | function | ||
SerializableClosureWrapper:: |
public | function | ||
SerializableClosureWrapper:: |
public | function |