class FileExcludeFilter in Backup and Migrate 5.0.x
@package Drupal\backup_migrate\Core\Filter
Hierarchy
- class \Drupal\backup_migrate\Core\Plugin\PluginBase implements ConfigurableInterface, PluginInterface uses ConfigurableTrait
- class \Drupal\backup_migrate\Core\Filter\FileExcludeFilter
Expanded class hierarchy of FileExcludeFilter
2 files declare their use of FileExcludeFilter
- DrupalFilesSourcePlugin.php in src/
Plugin/ BackupMigrateSource/ DrupalFilesSourcePlugin.php - DrupalPublicFileExcludeFilter.php in src/
Drupal/ Filter/ DrupalPublicFileExcludeFilter.php
File
- src/
Core/ Filter/ FileExcludeFilter.php, line 13
Namespace
Drupal\backup_migrate\Core\FilterView source
class FileExcludeFilter extends PluginBase {
/**
* @var array
* A cache of compiled patterns.
*/
public $patterns;
/**
* The 'beforeDbTableBackup' plugin op.
*
* @param array $table
* @param array $params
*
* @return array $table
*/
public function beforeFileBackup($path, $params = []) {
$source = $this
->confGet('source');
if ($source && $source == $params['source']) {
$exclude = $this
->confGet('exclude_filepaths');
$exclude = $this
->compileExcludePatterns($exclude);
if ($this
->matchPath($path, $exclude, $params['base_path'])) {
return NULL;
}
}
return $path;
}
/**
* Get the default values for the plugin.
*
* @return \Drupal\backup_migrate\Core\Config\Config
*/
public function configDefaults() {
return new Config([
'source' => '',
'exclude_filepaths' => [],
]);
}
/**
* Convert an array of glob patterns to an array of regex patterns.
*
* Used for file name exclusion.
*
* @param array $exclude
* A list of patterns with glob wildcards.
*
* @return array
* A list of patterns as regular expressions
*/
private function compileExcludePatterns(array $exclude) {
if ($this->patterns !== NULL) {
return $this->patterns;
}
foreach ($exclude as $pattern) {
// Convert Glob wildcards to a regex.
// @see http://php.net/manual/en/function.fnmatch.php#71725
$this->patterns[] = "#^" . strtr(preg_quote($pattern, '#'), [
'\\*' => '.*',
'\\?' => '.',
'\\[' => '[',
'\\]' => ']',
]) . "\$#i";
}
return $this->patterns;
}
/**
* Match a path to the list of exclude patterns.
*
* @param string $path
* The path to match.
* @param array $exclude
* An array of regular expressions to match against.
* @param string $base_path
*
* @return bool
*/
private function matchPath($path, array $exclude, $base_path = '') {
$path = substr($path, strlen($base_path));
if ($exclude) {
foreach ($exclude as $pattern) {
if (preg_match($pattern, $path)) {
return TRUE;
}
}
}
return FALSE;
}
/**
* Get a definition for user-configurable settings.
*
* @param array $params
*
* @return array
*/
public function configSchema(array $params = []) {
$schema = [];
$source = $this
->confGet('source');
// Backup settings.
if (!empty($source) && $params['operation'] == 'backup') {
$schema['groups']['default'] = [
'title' => $this
->t('Exclude Files from %source', [
'%source' => $source
->confGet('name'),
]),
];
// Backup settings.
if ($params['operation'] == 'backup') {
$schema['fields']['exclude_filepaths'] = [
'type' => 'text',
'title' => $this
->t('Exclude these files'),
'multiple' => TRUE,
'group' => 'default',
];
}
}
return $schema;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableTrait:: |
protected | property | The object's configuration object. | |
ConfigurableTrait:: |
protected | property | The initial configuration. | |
ConfigurableTrait:: |
public | function | Get a specific value from the configuration. | |
ConfigurableTrait:: |
public | function | Get the configuration object for this item. | |
ConfigurableTrait:: |
public | function | Get any validation errors in the config. | |
ConfigurableTrait:: |
public | function | Set the configuration for all plugins. | 1 |
ConfigurableTrait:: |
public | function | 2 | |
FileExcludeFilter:: |
public | property | A cache of compiled patterns. | |
FileExcludeFilter:: |
public | function | The 'beforeDbTableBackup' plugin op. | |
FileExcludeFilter:: |
private | function | Convert an array of glob patterns to an array of regex patterns. | |
FileExcludeFilter:: |
public | function |
Get the default values for the plugin. Overrides ConfigurableTrait:: |
1 |
FileExcludeFilter:: |
public | function |
Get a definition for user-configurable settings. Overrides ConfigurableTrait:: |
|
FileExcludeFilter:: |
private | function | Match a path to the list of exclude patterns. | |
PluginBase:: |
public | function |
What is the weight of the given operation for this plugin. Overrides PluginInterface:: |
|
PluginBase:: |
public | function |
Get a list of supported operations and their weight. Overrides PluginInterface:: |
8 |
PluginBase:: |
public | function |
Does this plugin implement the given operation. Overrides PluginInterface:: |
|
TranslatableTrait:: |
protected | property | ||
TranslatableTrait:: |
public | function | ||
TranslatableTrait:: |
public | function | Translate the given string if there is a translator service available. |