createFromArray example

$criteria->addFilter(new EqualsFilter('technicalName', 'ThemeWithMultiInheritance'));
        $criteria->addAssociation('parentThemes');
        /** @var ThemeEntity $theme */
        $theme = $themeRepository->search($criteria$context)->first();
    }

    public function testHandleThemeInstallOrUpdateWillRecompileOnlyTouchedTheme(): void
    {
        $salesChannelId = $this->createSalesChannel();
        $themeId = $this->createTheme('SimpleTheme', $salesChannelId);
        $installConfig = $this->configFactory->createFromBundle(new SimpleTheme());
        $installConfig->setStyleFiles(FileCollection::createFromArray(['onlyForFile']));

        $this->themeServiceMock->expects(static::once())
            ->method('compileThemeById')
            ->with(
                $themeId,
                static::isInstanceOf(Context::class),
                static::callback(fn (StorefrontPluginConfigurationCollection $configs): bool => $configs->count() === 2)
            );

        $configs = new StorefrontPluginConfigurationCollection([
            $this->configFactory->createFromBundle(new Storefront()),
            

  public function testDateArrays($input$timezone$expected) {
    $date = DateTimePlus::createFromArray($input$timezone);
    $value = $date->format('c');

    if (is_array($input)) {
      $input = var_export($input, TRUE);
    }
    $this->assertEquals($expected$valuesprintf("Test new DateTimePlus(%s, %s): should be %s, found %s.", $input$timezone$expected$value));
  }

  /** * Tests date diffs. * * @param mixed $input1 * A DateTimePlus object. * @param mixed $input2 * Date argument for DateTimePlus::diff method. * @param bool $absolute * Absolute flag for DateTimePlus::diff method. * @param \DateInterval $expected * The expected result of the DateTimePlus::diff operation. * * @dataProvider providerTestDateDiff */

  public function testCreateFromArray(array $changes, array $expected = []): void {
    $data = $changes;
    $data += $this->getValidData();
    $expected += $data;

    $sa = SecurityAdvisory::createFromArray($data);
    $this->assertInstanceOf(SecurityAdvisory::class$sa);
    $this->assertSame($expected['title']$sa->getTitle());
    $this->assertSame($expected['project']$sa->getProject());
    $this->assertSame($expected['type']$sa->getProjectType());
    $this->assertSame($expected['link']$sa->getUrl());
    $this->assertSame($expected['insecure']$sa->getInsecureVersions());
    $this->assertSame($expected['is_psa']$sa->isPsa());
    $this->assertSame($expected['type'] === 'core', $sa->isCoreAdvisory());
  }

  /** * Data provider for testCreateFromArray(). */
public function testCreateFromArray(array $data, array $expected = []): void {
    $data += $this->getValidData();
    $expected += $data;
    // If not set provide default values that match ::getValidData().     $expected += [
      'is_published' => TRUE,
      'is_unsupported' => TRUE,
      'is_security_release' => TRUE,
      'is_insecure' => TRUE,
    ];

    $release = ProjectRelease::createFromArray($data);

    $this->assertInstanceOf(ProjectRelease::class$release);
    $this->assertSame($expected['version']$release->getVersion());
    $this->assertSame($expected['date']$release->getDate());
    $this->assertSame($expected['download_link']$release->getDownloadUrl());
    $this->assertSame($expected['release_link']$release->getReleaseUrl());
    $this->assertSame($expected['core_compatibility_message']$release->getCoreCompatibilityMessage());
    $this->assertSame($expected['core_compatible']$release->isCoreCompatible());
    $this->assertSame($expected['is_published']$release->isPublished());
    $this->assertSame($expected['is_unsupported']$release->isUnsupported());
    $this->assertSame($expected['is_security_release']$release->isSecurityRelease());
    
$config->setBasePath($this->stripProjectDir($basePath));
            $config->setStorefrontEntryFilepath($this->getEntryFile($path));
            $config->setIsTheme(true);
            $config->setName($data['name']);
            $config->setAuthor($data['author']);

            if (\array_key_exists('style', $data) && \is_array($data['style'])) {
                $this->resolveStyleFiles($data['style']$basePath$config);
            }

            if (\array_key_exists('script', $data) && \is_array($data['script'])) {
                $fileCollection = FileCollection::createFromArray($data['script']);
                $config->setScriptFiles($this->addBasePathToCollection($fileCollection$basePath));
            }

            if (\array_key_exists('asset', $data)) {
                $config->setAssetPaths($this->addBasePathToArray($data['asset']$basePath));
            }

            if (\array_key_exists('previewMedia', $data)) {
                $config->setPreviewMedia($basePath . \DIRECTORY_SEPARATOR . $data['previewMedia']);
            }

            

  private function getAdditionalSecurityCoveredMinors($security_covered_version) {
    $security_covered_version_major = ExtensionVersion::createFromVersionString($security_covered_version)->getMajorVersion();
    $security_covered_version_minor = $this->getSemanticMinorVersion($security_covered_version);
    foreach ($this->releases as $release_info) {
      try {
        $release = ProjectRelease::createFromArray($release_info);
      }
      catch (\UnexpectedValueException $exception) {
        // Ignore releases that are in an invalid format. Although this is         // highly unlikely we should still process releases in the correct         // format.         Error::logException(\Drupal::logger('update')$exception, 'Invalid project format: @release', ['@release' => print_r($release_info, TRUE)]);
        continue;
      }
      $release_version = ExtensionVersion::createFromVersionString($release->getVersion());
      if ($release_version->getMajorVersion() === $security_covered_version_major && $release->isPublished() && !$release_version->getVersionExtra()) {
        // The releases are ordered with the most recent releases first.

class DateTimeIso8601 extends StringData implements DateTimeInterface {

  /** * {@inheritdoc} */
  public function getDateTime() {
    if ($this->value) {
      if (is_array($this->value)) {
        // Data of this type must always be stored in UTC.         $datetime = DrupalDateTime::createFromArray($this->value, 'UTC');
      }
      else {
        // Data of this type must always be stored in UTC.         $datetime = new DrupalDateTime($this->value, 'UTC');
      }
      return $datetime;
    }
  }

  /** * {@inheritdoc} */

      if ($project['project_type'] == 'theme' || $project['project_type'] == 'theme-disabled') {
        $project_name .= ' ' . $this->t('(Theme)');
      }

      if (empty($project['recommended'])) {
        // If we don't know what to recommend they upgrade to, we should skip         // the project entirely.         continue;
      }

      $recommended_release = ProjectRelease::createFromArray($project['releases'][$project['recommended']]);
      $recommended_version = '{{ release_version }} (<a href="{{ release_link }}" title="{{ project_title }}">{{ release_notes }}</a>)';
      $recommended_version_parser = ExtensionVersion::createFromVersionString($recommended_release->getVersion());
      if ($recommended_version_parser->getMajorVersion() != $project['existing_major']) {
        $recommended_version .= '<div title="{{ major_update_warning_title }}" class="update-major-version-warning">{{ major_update_warning_text }}</div>';
      }

      $recommended_version = [
        '#type' => 'inline_template',
        '#template' => $recommended_version,
        '#context' => [
          'release_version' => $recommended_release->getVersion(),
          
if (empty(static::checkEmptyInputs($input$parts))) {
        if (isset($input['ampm'])) {
          if ($input['ampm'] == 'pm' && $input['hour'] < 12) {
            $input['hour'] += 12;
          }
          elseif ($input['ampm'] == 'am' && $input['hour'] == 12) {
            $input['hour'] -= 12;
          }
          unset($input['ampm']);
        }
        try {
          $date = DrupalDateTime::createFromArray($input$element['#date_timezone']);
        }
        catch (\Exception $e) {
          $form_state->setError($elementt('Selected combination of day and month is not valid.'));
        }
        if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
          static::incrementRound($date$increment);
        }
      }
    }
    else {
      $return = array_fill_keys($parts, '');
      
        // @see \Drupal\update\EventSubscriber\ConfigSubscriber::onConfigSave()         $this->keyValueExpirable->setWithExpire(self::ADVISORIES_JSON_EXPIRABLE_KEY, $json_payload$interval_seconds);
      }
      else {
        $this->logger->error('The security advisory JSON feed from Drupal.org could not be decoded.');
        return NULL;
      }
    }

    foreach ($json_payload as $advisory_data) {
      try {
        $sa = SecurityAdvisory::createFromArray($advisory_data);
      }
      catch (\UnexpectedValueException $unexpected_value_exception) {
        // Ignore items in the feed that are in an invalid format. Although         // this is highly unlikely we should still display the items that are         // in the correct format.         Error::logException($this->logger, $unexpected_value_exception, 'Invalid security advisory format: @advisory', ['@advisory' => Json::encode($advisory_data)]);
        continue;
      }

      if ($this->isApplicable($sa)) {
        $advisories[] = $sa;
      }
Home | Imprint | This part of the site doesn't use cookies.