Create a new stream from a string.

The stream SHOULD be created with a temporary resource.

@param string $content String content with which to populate the stream.

@return StreamInterface
17239
public function createStream(string $content = ''): StreamInterface
    {
        $resource = fopen('php://temp', 'rw+');
        $stream = new Stream($resource);
        $stream->write($content);

        return $stream;
    }
459805
public function simpleXmlLoadString(string $content)
    {
        $useErrors = libxml_use_internal_errors(true);

        $xml = simplexml_load_string($content);

        $error = null;

        if (false === $xml) {
            $errors = libxml_get_errors();

            $error = reset($errors);
        }

        libxml_clear_errors();
        libxml_use_internal_errors($useErrors);

        if ($error !== null) {
            throw new \Exception($this->formatXmlError($error, explode("\n", $content)));
        }

        return $xml;
    }
1163507
function setBody($content)
    {
        if (! $content instanceof iStreamable )
            ## Instead Of StreamInterface must convert to string
            $content = (string) $content;

        $this->body = $content;
        return $this;
    }
584896
public function visit(vfsStreamContent $content)
    {
        switch ($content->getType()) {
            case vfsStreamContent::TYPE_FILE:
                $this->visitFile($content);
                break;

            case vfsStreamContent::TYPE_DIR:
                $this->visitDirectory($content);
                break;

            default:
                throw new InvalidArgumentException('Unknown content type');
        }

        return $this;
    }
590598
public static function fromContents(string $contents): self
    {
        $handle = fopen('php://memory', 'r+');
        fwrite($handle, $contents);
        rewind($handle);
        return new static($handle);
    }
932054
public static function create($body = ''): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_string($body)) {
            $resource = \fopen('php://temp', 'rw+');
            \fwrite($resource, $body);
            $body = $resource;
        }

        if (\is_resource($body)) {
            $new = new self();
            $new->stream = $body;
            $meta = \stream_get_meta_data($new->stream);
            $new->seekable = $meta['seekable'];
            $new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
            $new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
            $new->uri = $new->getMetadata('uri');

            return $new;
        }

        throw new \InvalidArgumentException('First argument to Stream::create() must be a string, resource or StreamInterface.');
    }
173700
protected function createTemporaryFile($content)
    {
        $temporaryPath = $this->getTemporaryPath();

        if (false === $temporaryPath) {
            throw new RuntimeException("Unable to create temporary file in '{$temporaryPath}'.");
        }

        file_put_contents($temporaryPath, $content);

        // The file is automatically removed when closed, or when the script ends.
        register_shutdown_function(function () use ($temporaryPath) {
            unlink($temporaryPath);
        });

        return $temporaryPath;
    }
701516
public function setContent(string $content, ?StreamFactoryInterface $streamFactory = null): WebResourceInterface
    {
        $response = null;
        $contentType = $this->contentType;

        if ($this->response && empty($streamFactory)) {
            throw UnwritableContentException::create();
        }

        if ($this->response) {
            $responseBody = $streamFactory->createFromString($content);
            $response = $this->response->withBody($responseBody);
            $contentType = null;
        }

        return $this->createNewInstance([
            WebResourceProperties::ARG_CONTENT_TYPE => $contentType,
            WebResourceProperties::ARG_CONTENT => $content,
            WebResourceProperties::ARG_RESPONSE => $response,
        ]);
    }
284261
public function create($filename, $content)
    {
        $filename = str::path($filename);

        $this->createDirectory(dirname($filename));

        return file_put_contents($filename, $content);
    }
1316009
public function parse($content)
    {
        $content = $this->normalize($content);

        list($method, $path, $scheme) = $this->getStatus($content);

        // resolve uri path
        if ($this->baseUrl !== null) {
            $path = UriResolver::resolve($this->baseUrl, new Uri($path));
        } else {
            $path = new Uri($path);
        }

        $request = new Request($path, $method);
        $request->setProtocolVersion($scheme);

        list($header, $body) = $this->splitMessage($content);

        $this->headerToArray($request, $header);

        $request->setBody(new StringStream($body));

        return $request;
    }
668929
public function createStream($body = null)
    {
        if ($body instanceof StreamInterface)
        {
            return $body;
        }

        if (\is_resource($body))
        {
            return Stream::createFromResource($body);
        }

        return Stream::create($body ?? '');
    }
19921
public static function stream($body = null): StreamInterface
    {
        if ($body instanceof StreamInterface) {
            return $body;
        }

        if (\is_resource($body)) {
            return new Stream($body);
        }

        $resource = \fopen('php://temp', 'rw+b');
        $stream = new Stream($resource);
        if ($body) {
            $stream->write($body);
        }

        return $stream;
    }
456536
public static function create(string $contents)
    {
        $contextInst = new ContextFactory();

        $context = function (string $namespace) use ($contents, $contextInst) {
            return $contextInst->createForNamespace($namespace, $contents);
        };

        $phpdocInst = DocBlockFactory::createInstance();

        $phpdoc = function (string $doc, Context $context) use ($phpdocInst) {
            return $phpdocInst->create($doc, $context);
        };

        return new self($context, $phpdoc);
    }
740134
public function send($content = null)
    {


        //if not buffer sent
        if (!$this->buffered) {
            return $this->sendBuffer($content);
        }

        $this->sendContent($content);

        return $this;
    }
349118
public static function create($contentType, $content = '', $bodyStream = null)
    {
        /* @var ResponseInterface|MockInterface $response */
        $response = Mockery::mock(ResponseInterface::class);

        $response
            ->shouldReceive('getHeader')
            ->with('content-type')
            ->andReturn([
                $contentType,
            ]);

        $response
            ->shouldReceive('getHeaderLine')
            ->with('content-type')
            ->andReturn($contentType);

        if (empty($bodyStream)) {
            /* @var StreamInterface|Mock $bodyStream */
            $bodyStream = Mockery::mock(StreamInterface::class);
            $bodyStream
                ->shouldReceive('__toString')
                ->andReturn($content);
        }

        $response
            ->shouldReceive('getBody')
            ->andReturn($bodyStream);

        return $response;
    }
1018690
public static function create(array $content)
    {
        $access = static::arrayGet($content, 'access');
        $token = static::arrayGet($access, 'token');
        $tokenid = static::arrayGet($token, 'id');
        $expires = static::arrayGet($token, 'expires');

        try {
            $expireDate = new \DateTime($expires);
        } catch (\Exception $e) {
            throw new TokenException(sprintf('Invalid expiration date: %s', $e->getMessage()), null, $e);
        }

        $token = new static($tokenid, $expireDate);

        $catalogs = static::arrayGet($access, 'serviceCatalog');
        if (is_array($catalogs)) {
            foreach ($catalogs as $catalog) {
                $type = static::arrayGet($catalog, 'type');
                $name = static::arrayGet($catalog, 'name');
                $endpoints = static::arrayGet($catalog, 'endpoints');

                if (!is_array($endpoints)) {
                    throw new TokenException(sprintf('Invalid endpoints: %s', json_encode($endpoints)));
                }

                $token->addServiceCatalog($type, $name, $endpoints);
            }
        }

        return $token;
    }
1017343
private function prepareContent($content)
    {
        $this->content = $content;

        if (!($this->content instanceof StreamInterface)) {
            $this->content = Stream::factory($this->content);
        } elseif ($this->content instanceof MultipartBody) {
            if (!$this->hasHeader('Content-Disposition')) {
                $disposition = 'form-data; name="' . $this->name .'"';
                $this->headers['Content-Disposition'] = $disposition;
            }

            if (!$this->hasHeader('Content-Type')) {
                $this->headers['Content-Type'] = sprintf(
                    "multipart/form-data; boundary=%s",
                    $this->content->getBoundary()
                );
            }
        }
    }