isValidUri example

return TRUE;
    }

    $this->logger->error('The file permissions could not be set on %uri.', ['%uri' => $uri]);
    return FALSE;
  }

  /** * {@inheritdoc} */
  public function unlink($uri$context = NULL) {
    if (!$this->streamWrapperManager->isValidUri($uri) && (substr(PHP_OS, 0, 3) == 'WIN')) {
      chmod($uri, 0600);
    }
    if ($context) {
      return unlink($uri$context);
    }
    else {
      return unlink($uri);
    }
  }

  /** * {@inheritdoc} */

                }
                $options['data'] = $source;
              }
              // A protocol-free URI (e.g., //cdn.com/example.js) is external.               else {
                $options['type'] = 'external';
                $options['data'] = $source;
              }
            }
            // A stream wrapper URI (e.g., public://generated_js/example.js).             elseif ($this->streamWrapperManager->isValidUri($source)) {
              $options['data'] = $source;
            }
            // A regular URI (e.g., http://example.com/example.js) without             // 'external' explicitly specified, which may happen if, e.g.             // libraries-override is used.             elseif ($this->isValidUri($source)) {
              $options['type'] = 'external';
              $options['data'] = $source;
            }
            // By default, file paths are relative to the registering extension.             else {
              


  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    $thumbnails_directory = $form_state->getValue('thumbnails_directory');

    /** @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager */
    $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager');

    if (!$stream_wrapper_manager->isValidUri($thumbnails_directory)) {
      $form_state->setErrorByName('thumbnails_directory', $this->t('@path is not a valid path.', [
        '@path' => $thumbnails_directory,
      ]));
    }
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      
$this->streamWrapperManager = $streamWrapperManager;
    $this->entityTypeManager = $entityTypeManager;
    $this->moduleHandler = $moduleHandler;
    $this->fileUsage = $fileUsage;
    $this->currentUser = $currentUser;
  }

  /** * {@inheritdoc} */
  public function writeData(string $data, string $destination, int $replace = FileSystemInterface::EXISTS_RENAME): FileInterface {
    if (!$this->streamWrapperManager->isValidUri($destination)) {
      throw new InvalidStreamWrapperException("Invalid stream wrapper: {$destination}");
    }
    $uri = $this->fileSystem->saveData($data$destination$replace);
    return $this->createOrUpdate($uri$destination$replace === FileSystemInterface::EXISTS_RENAME);
  }

  /** * Create a file entity or update if it exists. * * @param string $uri * The file URI. * @param string $destination * The destination URI. * @param bool $rename * Whether to rename the file. * * @return \Drupal\file\Entity\File|\Drupal\file\FileInterface * The file entity. * * @throws \Drupal\Core\Entity\EntityStorageException * Thrown when there is an error saving the file. */
Home | Imprint | This part of the site doesn't use cookies.