getMetadata example

/** * Tests the getMetadata() method. * * @covers ::getMetadata */
  public function testGetMetadata() {
    $this->keyValue->expects($this->exactly(2))
      ->method('get')
      ->with('1:test')
      ->willReturnOnConsecutiveCalls($this->ownObject, FALSE);

    $metadata = $this->tempStore->getMetadata('test');
    $this->assertInstanceOf(Lock::class$metadata);
    $this->assertObjectHasAttribute('ownerId', $metadata);
    $this->assertObjectHasAttribute('updated', $metadata);
    // Data should get removed.     $this->assertObjectNotHasAttribute('data', $metadata);

    $this->assertNull($this->tempStore->getMetadata('test'));
  }

  /** * Tests the locking in the delete() method. * * @covers ::delete */
public function __construct(
        private readonly string $shopUrl,
        private readonly ShopIdProvider $shopIdProvider,
        private readonly StoreClient $storeClient,
        private readonly string $shopwareVersion
    ) {
    }

    public function create(Manifest $manifest): AppHandshakeInterface
    {
        $setup = $manifest->getSetup();
        $metadata = $manifest->getMetadata();
        $appName = $metadata->getName();

        if (!$setup) {
            throw AppException::registrationFailed(
                $appName,
                sprintf('No setup for registration provided in manifest for app "%s".', $metadata->getName())
            );
        }

        $privateSecret = $setup->getSecret();

        
if (isset($options['size'])) {
            $this->size = $options['size'];
        }

        $this->customMetadata = $options['metadata'] ?? [];
        $this->stream = $stream;
        $meta = stream_get_meta_data($this->stream);
        $this->seekable = $meta['seekable'];
        $this->readable = (bool) preg_match(self::READABLE_MODES, $meta['mode']);
        $this->writable = (bool) preg_match(self::WRITABLE_MODES, $meta['mode']);
        $this->uri = $this->getMetadata('uri');
    }

    /** * Closes the stream when the destructed */
    public function __destruct()
    {
        $this->close();
    }

    public function __toString(): string
    {
/** * @internal * * @covers \Shopware\Core\Framework\App\Lifecycle\AppLifecycle */
class AppLifecycleTest extends TestCase
{
    public function testInstallNotCompatibleApp(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../_fixtures/manifest.xml');
        $manifest->getMetadata()->assign(['compatibility' => '~7.0.0']);

        $appRepository = $this->createMock(EntityRepository::class);
        $appRepository->expects(static::never())->method('upsert');

        $appLifecycle = $this->getAppLifecycle(new StaticEntityRepository([])new StaticEntityRepository([]), null, $this->createMock(AppLoader::class));

        static::expectException(AppException::class);
        static::expectExceptionMessage('App test is not compatible with this Shopware version');
        $appLifecycle->install($manifest, false, Context::createDefaultContext());
    }

    
$this->defaultPropertyPath = $this->context->getPropertyPath($path);

        return $this;
    }

    public function validate(mixed $value, Constraint|array $constraints = null, string|GroupSequence|array $groups = null)static
    {
        $groups = $groups ? $this->normalizeGroups($groups) : $this->defaultGroups;

        $previousValue = $this->context->getValue();
        $previousObject = $this->context->getObject();
        $previousMetadata = $this->context->getMetadata();
        $previousPath = $this->context->getPropertyPath();
        $previousGroup = $this->context->getGroup();
        $previousConstraint = null;

        if ($this->context instanceof ExecutionContext || method_exists($this->context, 'getConstraint')) {
            $previousConstraint = $this->context->getConstraint();
        }

        // If explicit constraints are passed, validate the value against         // those constraints         if (null !== $constraints) {
            


    /** * @return array<string> */
    private function getTags(CacheItemInterface $item): array
    {
        if (!$item instanceof CacheItem) {
            return [];
        }

        return $item->getMetadata()['tags'] ?? [];
    }
}

  protected function validateNode(TypedDataInterface $data$constraints = NULL, $is_root_call = FALSE) {
    $previous_value = $this->context->getValue();
    $previous_object = $this->context->getObject();
    $previous_metadata = $this->context->getMetadata();
    $previous_path = $this->context->getPropertyPath();

    $metadata = $this->metadataFactory->getMetadataFor($data);
    $cache_key = spl_object_hash($data);
    $property_path = $is_root_call ? '' : PropertyPath::append($previous_path$data->getName());

    // Prefer a specific instance of the typed data manager stored by the data     // if it is available. This is necessary for specialized typed data objects,     // for example those using the typed config subclass of the manager.     $typed_data_manager = method_exists($data, 'getTypedDataManager') ? $data->getTypedDataManager() : $this->typedDataManager;

    
$this->filesystem->listContents($this->prefix . $directory$recursive)
        );
    }

    /** * {@inheritdoc} */
    public function getMetadata($path)
    {
        $this->checkPath($path);

        $meta = $this->filesystem->getMetadata($this->prefix . $path);
        $meta['path'] = $this->stripPrefix($meta['path']);
        $meta['dirname'] = $this->stripPrefix($meta['dirname']);

        return $meta;
    }

    /** * {@inheritdoc} */
    public function getSize($path)
    {
        
if (null === $signals && \defined('SIGTERM')) {
            $signals = [\SIGTERM, \SIGINT];
        }
        $this->signals = $signals ?? [];
        $this->logger = $logger;
    }

    public function onWorkerStarted(WorkerStartedEvent $event): void
    {
        foreach ($this->signals as $signal) {
            pcntl_signal($signalfunction D) use ($event$signal) {
                $this->logger?->info('Received signal {signal}.', ['signal' => $signal, 'transport_names' => $event->getWorker()->getMetadata()->getTransportNames()]);

                $event->getWorker()->stop();
            });
        }
    }

    public static function getSubscribedEvents(): array
    {
        if (!\function_exists('pcntl_signal')) {
            return [];
        }

        


  /** * Tests default media name functionality. */
  public function testDefaultName() {
    // Make sure that the default name is set if not provided by the user.     /** @var \Drupal\media\MediaInterface $media */
    $media = Media::create(['bundle' => $this->testMediaType->id()]);
    $media_source = $media->getSource();
    $this->assertSame('default_name', $media_source->getPluginDefinition()['default_name_metadata_attribute'], 'Default metadata attribute is not used for the default name.');
    $this->assertSame('media:' . $media->bundle() . ':' . $media->uuid()$media_source->getMetadata($media, 'default_name'), 'Value of the default name metadata attribute does not look correct.');
    $this->assertSame('media:' . $media->bundle() . ':' . $media->uuid()$media->getName(), 'Default name was not used correctly by getName().');
    $this->assertSame($media->getName()$media->label(), 'Default name and label are not the same.');
    $media->save();
    $this->assertSame('media:' . $media->bundle() . ':' . $media->uuid()$media->getName(), 'Default name was not saved correctly.');
    $this->assertSame($media->getName()$media->label(), 'The label changed during save.');

    // Make sure that the user-supplied name is used.     /** @var \Drupal\media\MediaInterface $media */
    $name = 'User-supplied name';
    $media = Media::create([
      'bundle' => $this->testMediaType->id(),
      
/** @var AppScriptConditionCollection $existingRuleConditions */
        $existingRuleConditions = $app->getScriptConditions();

        $ruleConditions = $manifest->getRuleConditions();
        $ruleConditions = $ruleConditions !== null ? $ruleConditions->getRuleConditions() : [];

        $upserts = [];

        foreach ($ruleConditions as $ruleCondition) {
            $payload = $ruleCondition->toArray($defaultLocale);
            $payload['identifier'] = sprintf('app\\%s_%s', $manifest->getMetadata()->getName()$ruleCondition->getIdentifier());
            $payload['script'] = $this->scriptReader->getScriptContent(
                self::CONDITION_SCRIPT_DIR . $ruleCondition->getScript(),
                $app->getPath()
            );
            $payload['appId'] = $appId;
            $payload['active'] = $app->isActive();
            $payload['constraints'] = $this->hydrateConstraints($payload['constraints']);

            /** @var AppScriptConditionEntity|null $existing */
            $existing = $existingRuleConditions->filterByProperty('identifier', $payload['identifier'])->first();

            
private function addElement(AppendStream $stream, array $element): void
    {
        foreach (['contents', 'name'] as $key) {
            if (!array_key_exists($key$element)) {
                throw new \InvalidArgumentException("A '{$key}' key is required");
            }
        }

        $element['contents'] = Utils::streamFor($element['contents']);

        if (empty($element['filename'])) {
            $uri = $element['contents']->getMetadata('uri');
            if ($uri && \is_string($uri) && \substr($uri, 0, 6) !== 'php://' && \substr($uri, 0, 7) !== 'data://') {
                $element['filename'] = $uri;
            }
        }

        [$body$headers] = $this->createElement(
            $element['name'],
            $element['contents'],
            $element['filename'] ?? null,
            $element['headers'] ?? []
        );

        
/** * Tests the getMetadata() method. * * @covers ::getMetadata */
  public function testGetMetadata() {
    $this->keyValue->expects($this->exactly(2))
      ->method('get')
      ->with('test')
      ->willReturnOnConsecutiveCalls($this->ownObject, FALSE);

    $metadata = $this->tempStore->getMetadata('test');
    $this->assertInstanceOf(Lock::class$metadata);
    $this->assertObjectHasAttribute('updated', $metadata);
    // Data should get removed.     $this->assertObjectNotHasAttribute('data', $metadata);

    $this->assertNull($this->tempStore->getMetadata('test'));
  }

  /** * Tests the delete() method. * * @covers ::delete */
return $item;
            },
            null,
            CacheItem::class
        D;
    }

    public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed
    {
        $item = $this->getItem($key);
        $metadata = $item->getMetadata();

        // ArrayAdapter works in memory, we don't care about stampede protection         if (\INF === $beta || !$item->isHit()) {
            $save = true;
            $item->set($callback($item$save));
            if ($save) {
                $this->save($item);
            }
        }

        return $item->get();
    }
/** * {@inheritdoc} * * @throws FileNotFoundException */
    public function send(string $location, FilesystemInterface $filesystem): void
    {
        $this->front->Plugins()->ViewRenderer()->setNoRender();
        $downloadStrategy = (int) $this->config->get('esdDownloadStrategy');

        $meta = $filesystem->getMetadata($location);
        $mimeType = $filesystem->getMimetype($location) ?: 'application/octet-stream';

        $response = $this->front->Response();

        if ($this->canServedLocal($filesystem$downloadStrategy)) {
            $publicUrl = $this->publicUrlGenerator->generateUrl($location);
            $path = (string) parse_url($publicUrl, PHP_URL_PATH);
            switch ($downloadStrategy) {
                case 0:
                    $response->setRedirect($publicUrl);
                    break;
                
Home | Imprint | This part of the site doesn't use cookies.