You are here

public function SessionStreamWrapper::__construct in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::__construct()

Constructor method.

Note this cannot take any arguments; PHP's stream wrapper users do not know how to supply them.

@todo Refactor helper injection after https://www.drupal.org/node/3048126

File

modules/stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php, line 155

Class

SessionStreamWrapper
Example stream wrapper class to handle session:// streams.

Namespace

Drupal\stream_wrapper_example\StreamWrapper

Code

public function __construct() {

  // Dependency injection will not work here, since PHP doesn't give us a
  // chance to perform the injection. PHP creates the stream wrapper objects
  // automatically when certain file functions are called. Therefore we'll use
  // the \Drupal service locator.
  // phpcs:ignore
  $this->sessionHelper = \Drupal::service('stream_wrapper_example.session_helper');
  $this->sessionHelper
    ->setPath('.isadir.txt', TRUE);
  $this->streamMode = FALSE;
}