public function store(DocumentInterface $document)
    {
        $id = $document->getId();

        // Generate an id if none has been defined
        if (is_null($id)) {
            $id = $document->setId($this->generateId());
        }

        if (!$this->validateId($id)) {
            throw new \Exception(sprintf('`%s` is not a valid document ID.', $id));
        }

        $path = $this->getPathForDocument($id);
        $data = get_object_vars($document);
        $data = $this->formatter->encode($data);

        if(!$this->write($path, $data)) {
            return false;
        }

        return $id;
    }
public function store(DocumentInterface $document)
    {
        $id = $document->getId();

        // Generate an id if none has been defined
        if (is_null($id)) {
            $id = $document->setId($this->generateId());
        }

        if (!$this->validateId($id)) {
            throw new \Exception(sprintf('`%s` is not a valid document ID.', $id));
        }

        $path = $this->getPathForDocument($id);
        $data = get_object_vars($document);
        $data = $this->formatter->encode($data);

        if(!$this->write($path, $data)) {
            return false;
        }

        return $id;
    }
public function store ( DocumentInterface $ document ) { $ id = $ document -> getId ( ) ; // Generate an id if none has been defined if ( is_null ( $ id ) ) { $ id = $ document -> setId ( $ this -> generateId ( ) ) ; } if ( ! $ this -> validateId ( $ id ) ) { throw new \ Exception ( sprintf ( '`%s` is not a valid document ID.' , $ id ) ) ; } $ path = $ this -> getPathForDocument ( $ id ) ; $ data = get_object_vars ( $ document ) ; $ data = $ this -> formatter -> encode ( $ data ) ; if ( ! $ this -> write ( $ path , $ data ) ) { return false ; } return $ id ; }
Store a Document in the repository.

@param Document $document The document to store

@return bool True if stored, otherwise false
Store a Document in the repository .