writeItem example

if (!empty($item)) {
      $uri = $this->fileSystem->tempnam('temporary://', 'po_');
      $header = $reader->getHeader();
      $header->setProjectName($this->config('system.site')->get('name'));
      $header->setLanguageName($language_name);

      $writer = new PoStreamWriter();
      $writer->setURI($uri);
      $writer->setHeader($header);

      $writer->open();
      $writer->writeItem($item);
      $writer->writeItems($reader);
      $writer->close();

      $response = new BinaryFileResponse($uri);
      $response->setContentDisposition('attachment', $filename);
      $form_state->setResponse($response);
    }
    else {
      $this->messenger()->addStatus($this->t('Nothing to export.'));
    }
  }

}


    // Limit the file system quota to make the write fail on long strings.     vfsStream::setQuota(10);

    $this->poWriter->setURI($this->poFile->url());
    $this->poWriter->open();

    $poItem = $this->prophesize(PoItem::class);
    $poItem->__toString()->willReturn($poContent);

    $this->poWriter->writeItem($poItem->reveal());
    $this->poWriter->close();
    $this->assertEquals(file_get_contents($this->poFile->url())$expected);
  }

  /** * @return array * - Content to write. * - Written content. * - Content longer than 10 bytes. */
  public function providerWriteData() {
    
public function set($cid$data$expire = Cache::PERMANENT, array $tags = []) {
    assert(Inspector::assertAllStrings($tags), 'Cache Tags must be strings.');

    $item = (object) [
      'cid' => $cid,
      'data' => $data,
      'created' => round(microtime(TRUE), 3),
      'expire' => $expire,
      'tags' => array_unique($tags),
      'checksum' => $this->checksumProvider->getCurrentChecksum($tags),
    ];
    $this->writeItem($this->normalizeCid($cid)$item);
  }

  /** * {@inheritdoc} */
  public function delete($cid) {
    $this->storage()->delete($this->normalizeCid($cid));
  }

  /** * {@inheritdoc} */

  public function writeItem(PoItem $item) {
    $this->write($item);
  }

  /** * {@inheritdoc} */
  public function writeItems(PoReaderInterface $reader$count = -1) {
    $forever = $count == -1;
    while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
      $this->writeItem($item);
    }
  }

  /** * Implements Drupal\Component\Gettext\PoStreamInterface::getURI(). * * @throws \Exception * If the URI is not set. */
  public function getURI() {
    if (empty($this->uri)) {
      
$this->cache = $this->getContainer()->get('cache.object');
    }

    public function testTraceSave(): void
    {
        $collection = $this->getContainer()->get(CacheTagCollection::class);

        $this->cache->deleteItem('some-key');

        $collection->reset();

        $this->writeItem('some-key', ['tag-a', 'tag-b']);

        static::assertEquals(['tag-a', 'tag-b']$collection->getTrace('all'));
    }

    public function testTraceRead(): void
    {
        $collection = $this->getContainer()->get(CacheTagCollection::class);

        $this->writeItem('some-key', ['tag-a', 'tag-b']);

        $collection->reset();
        

    $context = $item->getContext();
    $this->items[$context != NULL ? $context : ''][$item->getSource()] = $item->getTranslation();
  }

  /** * {@inheritdoc} */
  public function writeItems(PoReaderInterface $reader$count = -1) {
    $forever = $count == -1;
    while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
      $this->writeItem($item);
    }
  }

  /** * Get all stored PoItem's. * * @return array PoItem */
  public function getData() {
    return $this->items;
  }

  
$item->setTranslation(implode(PoItem::DELIMITER, $item->getTranslation()));
    }
    $this->importString($item);
  }

  /** * {@inheritdoc} */
  public function writeItems(PoReaderInterface $reader$count = -1) {
    $forever = $count == -1;
    while (($count-- > 0 || $forever) && ($item = $reader->readItem())) {
      $this->writeItem($item);
    }
  }

  /** * Imports one string into the database. * * @param \Drupal\Component\Gettext\PoItem $item * The item being imported. * * @return int * The string ID of the existing string modified or the new string added. */
Home | Imprint | This part of the site doesn't use cookies.