Jackalope\Property::getBinary PHP Метод

getBinary() публичный Метод

{@inheritDoc}
public getBinary ( )
    public function getBinary()
    {
        $this->checkState();
        if ($this->type !== PropertyType::BINARY) {
            return $this->valueConverter->convertType($this->value, PropertyType::BINARY, $this->type);
        }
        if (!$this->wrapBinaryStreams && null === $this->value) {
            // no caching the stream. we need to fetch the stream and then copy
            // it into a memory stream so it can be accessed more than once.
            $this->value = $this->objectManager->getBinaryStream($this->path);
        }
        if ($this->value !== null) {
            // we have the stream locally: no wrapping or new or updated property
            // copy the stream so the original stream stays usable for storing, fetching again...
            $val = is_array($this->value) ? $this->value : array($this->value);
            $ret = array();
            foreach ($val as $s) {
                $stream = fopen('php://memory', 'rwb+');
                $pos = ftell($s);
                stream_copy_to_stream($s, $stream);
                rewind($stream);
                fseek($s, $pos);
                //go back to previous position
                $ret[] = $stream;
            }
            return is_array($this->value) ? $ret : $ret[0];
        }
        if (!$this->wrapBinaryStreams) {
            throw new LogicException("Attempting to create 'jackalope' stream instances but stream wrapper is not activated");
        }
        // return wrapped stream
        if ($this->isMultiple()) {
            $results = array();
            // identifies all streams loaded by one backend call
            $token = md5(uniqid(mt_rand(), true));
            // start with part = 1 since 0 will not be parsed properly by parse_url
            for ($i = 1; $i <= count($this->length); $i++) {
                $this->streams[] = $results[] = fopen('jackalope://' . $token . '@' . $this->session->getRegistryKey() . ':' . $i . $this->path, 'rwb+');
            }
            return $results;
        }
        // single property case
        $result = fopen('jackalope://' . $this->session->getRegistryKey() . $this->path, 'rwb+');
        $this->streams[] = $result;
        return $result;
    }