setURI example

      $filename = 'drupal.pot';
    }

    $item = $reader->readItem();
    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);
    }
    

  public static function filesToArray($langcode, array $files) {
    $writer = new PoMemoryWriter();
    $writer->setLangcode($langcode);
    foreach ($files as $file) {
      $reader = new PoStreamReader();
      $reader->setURI($file->uri);
      $reader->setLangcode($langcode);
      $reader->open();
      $writer->writeItems($reader, -1);
    }
    return $writer->getData();
  }

}

  public function testWriteItem($poContent$expected$long) {
    if ($long) {
      $this->expectException(\Exception::class);
      $this->expectExceptionMessage('Unable to write data:');
    }

    // 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. */


    /** * Sets the correct settings based on the options array * passed in. * * @return void */
    protected function parseOptions(array $options)
    {
        if (array_key_exists('baseURI', $options)) {
            $this->baseURI = $this->baseURI->setURI($options['baseURI']);
            unset($options['baseURI']);
        }

        if (array_key_exists('headers', $options) && is_array($options['headers'])) {
            foreach ($options['headers'] as $name => $value) {
                $this->setHeader($name$value);
            }

            unset($options['headers']);
        }

        

    public function __construct(?string $uri = null)
    {
        if ($uri !== null) {
            $this->setURI($uri);
        }
    }

    /** * If $silent == true, then will not throw exceptions and will * attempt to continue gracefully. * * @deprecated 4.4.0 Method not in PSR-7 * * @return URI */
    
public static function fileToDatabase($file$options) {
    // Add the default values to the options array.     $options += [
      'overwrite_options' => [],
      'customized' => LOCALE_NOT_CUSTOMIZED,
      'items' => -1,
      'seek' => 0,
    ];
    // Instantiate and initialize the stream reader for this file.     $reader = new PoStreamReader();
    $reader->setLangcode($file->langcode);
    $reader->setURI($file->uri);

    try {
      $reader->open();
    }
    catch (\Exception $exception) {
      throw $exception;
    }

    $header = $reader->getHeader();
    if (!$header) {
      throw new \Exception('Missing or malformed header.');
    }
Home | Imprint | This part of the site doesn't use cookies.