class SiteFilesExcluder

Excludes site files from stage operations.

@internal This is an internal part of Package Manager and may be changed or removed at any time without warning. External code should not interact with this class.

Hierarchy

  • class \Drupal\package_manager\PathExcluder\SiteFilesExcluder implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of SiteFilesExcluder

File

core/modules/package_manager/src/PathExcluder/SiteFilesExcluder.php, line 21

Namespace

Drupal\package_manager\PathExcluder
View source
final class SiteFilesExcluder implements EventSubscriberInterface {
    public function __construct(StreamWrapperManagerInterface $streamWrapperManager, Filesystem $fileSystem, array $wrappers) {
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        return [
            CollectPathsToExcludeEvent::class => 'excludeSiteFiles',
        ];
    }
    
    /**
     * Excludes public and private files from stage operations.
     *
     * @param \Drupal\package_manager\Event\CollectPathsToExcludeEvent $event
     *   The event object.
     */
    public function excludeSiteFiles(CollectPathsToExcludeEvent $event) : void {
        // Exclude files handled by the stream wrappers listed in $this->wrappers.
        // These paths could be either absolute or relative, depending on site
        // settings. If they are absolute, treat them as relative to the project
        // root. Otherwise, treat them as relative to the web root.
        foreach ($this->wrappers as $scheme) {
            $wrapper = $this->streamWrapperManager
                ->getViaScheme($scheme);
            if ($wrapper instanceof LocalStream) {
                $path = $wrapper->getDirectoryPath();
                if ($this->fileSystem
                    ->isAbsolutePath($path)) {
                    if ($path = realpath($path)) {
                        $event->addPathsRelativeToProjectRoot([
                            $path,
                        ]);
                    }
                }
                else {
                    $event->addPathsRelativeToWebRoot([
                        $path,
                    ]);
                }
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
SiteFilesExcluder::excludeSiteFiles public function Excludes public and private files from stage operations.
SiteFilesExcluder::getSubscribedEvents public static function
SiteFilesExcluder::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.