validateName example


  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    foreach (['delete', 'create', 'update'] as $op) {
      foreach ($event->getConfigImporter()->getUnprocessedConfiguration($op) as $name) {
        try {
          Config::validateName($name);
        }
        catch (ConfigNameException $e) {
          $message = $this->t('The config name @config_name is invalid.', ['@config_name' => $name]);
          $event->getConfigImporter()->logError($message);
        }
      }
    }
    $config_importer = $event->getConfigImporter();
    if ($config_importer->getStorageComparer()->getSourceStorage()->exists('core.extension')) {
      $this->validateModules($config_importer);
      $this->validateThemes($config_importer);
      
/** * Creates an empty form configuration. * * @param string|null $name The form name * @param string|null $dataClass The class of the form's data * * @throws InvalidArgumentException if the data class is not a valid class or if * the name contains invalid characters */
    public function __construct(?string $name, ?string $dataClass, EventDispatcherInterface $dispatcher, array $options = [])
    {
        self::validateName($name);

        if (null !== $dataClass && !class_exists($dataClass) && !interface_exists($dataClass, false)) {
            throw new InvalidArgumentException(sprintf('Class "%s" not found. Is the "data_class" form option set correctly?', $dataClass));
        }

        $this->name = (string) $name;
        $this->dataClass = $dataClass;
        $this->dispatcher = $dispatcher;
        $this->options = $options;
    }

    

    public function setName(string $name)static
    {
        $this->validateName($name);

        $this->name = $name;

        return $this;
    }

    /** * Sets the process title of the command. * * This feature should be used only when creating a long process command, * like a daemon. * * @return $this */
$this->export('encrypt.public', $this->encryptionKey);
        $this->export('decrypt.private', $this->decryptionKey);

        $this->lastMessage = sprintf('Sodium keys have been generated at "%s*.public/private.php".', $this->getPrettyPath($this->pathPrefix));

        return true;
    }

    public function seal(string $name, string $value): void
    {
        $this->lastMessage = null;
        $this->validateName($name);
        $this->loadKeys();
        $filename = $this->getFilename($name);
        $this->export($filenamesodium_crypto_box_seal($value$this->encryptionKey ?? sodium_crypto_box_publickey($this->decryptionKey)));

        $list = $this->list();
        $list[$name] = null;
        uksort($list, 'strnatcmp');
        file_put_contents($this->pathPrefix.'list.php', sprintf("<?php\n\nreturn %s;\n", VarExporter::export($list)), \LOCK_EX);

        $this->lastMessage = sprintf('Secret "%s" encrypted in "%s"; you can commit it.', $name$this->getPrettyPath(\dirname($this->pathPrefix).\DIRECTORY_SEPARATOR));
    }

    

    public function setName(string $name)static
    {
        $this->validateName($name);

        $this->name = $name;

        return $this;
    }

    /** * Sets the process title of the command. * * This feature should be used only when creating a long process command, * like a daemon. * * @return $this */
if (isset($this->errorCache[$name])) {
            if (!$throw) {
                return null;
            }

            throw new LoaderError($this->errorCache[$name]);
        }

        try {
            list($namespace$shortname) = $this->parseName($name);

            $this->validateName($shortname);
        } catch (LoaderError $e) {
            if (!$throw) {
                return null;
            }

            throw $e;
        }

        if (!isset($this->paths[$namespace])) {
            $this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace);

            

  public function testSetName($name) {
    // Set the name.     $this->config->setName($name);

    // Check that the name has been set correctly.     $this->assertEquals($name$this->config->getName());

    // Check that the name validates.     // Should throw \Drupal\Core\Config\ConfigNameException if invalid.     $this->config->validateName($name);
  }

  /** * Provides config names to test. * * @see \Drupal\Tests\Core\Config\ConfigTest::testSetName() */
  public function setNameProvider() {
    return [
      // Valid name with dot.       [
        
        $prefix = ($options['prefix'] === '') ? self::$defaults['prefix'] : $options['prefix'];
        $path   = $options['path'] ?: self::$defaults['path'];
        $domain = $options['domain'] ?: self::$defaults['domain'];

        // empty string SameSite should use the default for browsers         $samesite = $options['samesite'] ?: self::$defaults['samesite'];

        $raw      = $options['raw'];
        $secure   = $options['secure'];
        $httponly = $options['httponly'];

        $this->validateName($name$raw);
        $this->validatePrefix($prefix$secure$path$domain);
        $this->validateSameSite($samesite$secure);

        $this->prefix   = $prefix;
        $this->name     = $name;
        $this->value    = $value;
        $this->expires  = static::convertExpiresTimestamp($options['expires']);
        $this->path     = $path;
        $this->domain   = $domain;
        $this->secure   = $secure;
        $this->httponly = $httponly;
        


        if (!isset($data['requiredPlugins']) || !\is_array($data['requiredPlugins'])) {
            $data['requiredPlugins'] = [];
        }

        $data['requiredPlugins'] = json_encode($data['requiredPlugins']);

        // slugify technical name of preset         $data['name'] = $this->slugService->slugify($data['name']);
        $preset->fromArray($data);
        $this->validateName($preset);

        $violations = $this->models->validate($preset);
        if ($violations->count() > 0) {
            throw new ValidationException($violations);
        }

        $this->models->persist($preset);
        $this->models->flush();

        return $preset;
    }

    

    public function __construct(?string $name, array $options = [])
    {
        if ('' === $name || null === $name) {
            throw new InvalidArgumentException('Buttons cannot have empty names.');
        }

        $this->name = $name;
        $this->options = $options;

        FormConfigBuilder::validateName($name);
    }

    /** * Unsupported method. * * @return never * * @throws BadMethodCallException */
    public function add(string|FormBuilderInterface $child, string $type = null, array $options = [])static
    {
        
public function clear($key) {
    parent::clear($key);
    $this->resetOverriddenData();
    return $this;
  }

  /** * {@inheritdoc} */
  public function save($has_trusted_data = FALSE) {
    // Validate the configuration object name before saving.     static::validateName($this->name);

    // If there is a schema for this configuration object, cast all values to     // conform to the schema.     if (!$has_trusted_data) {
      if ($this->typedConfigManager->hasConfigSchema($this->name)) {
        // Ensure that the schema wrapper has the latest data.         $this->schemaWrapper = NULL;
        $this->data = $this->castValue(NULL, $this->data);
      }
      else {
        foreach ($this->data as $key => $value) {
          
public function generateKeys(bool $override = false): bool
    {
        $this->lastMessage = 'The dotenv vault doesn\'t encrypt secrets thus doesn\'t need keys.';

        return false;
    }

    public function seal(string $name, string $value): void
    {
        $this->lastMessage = null;
        $this->validateName($name);
        $v = str_replace("'", "'\\''", $value);

        $content = is_file($this->dotenvFile) ? file_get_contents($this->dotenvFile) : '';
        $content = preg_replace("/^$name=((\\\\'|'[^']++')++|.*)/m", "$name='$v'", $content, -1, $count);

        if (!$count) {
            $content .= "$name='$v'\n";
        }

        file_put_contents($this->dotenvFile, $content);

        
Home | Imprint | This part of the site doesn't use cookies.