JamesMoss\Flywheel\Repository::store PHP Метод

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

Store a Document in the repository.
public store ( JamesMoss\Flywheel\DocumentInterface $document ) : boolean
$document JamesMoss\Flywheel\DocumentInterface The document to store
Результат boolean True if stored, otherwise false
    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;
    }

Usage Example

Пример #1
0
 public function testChangingDocumentIDChangesFilename()
 {
     if (!is_dir('/tmp/flywheel')) {
         mkdir('/tmp/flywheel');
     }
     $config = new Config('/tmp/flywheel');
     $repo = new Repository('_pages', $config);
     $doc = new Document(array('test' => '123'));
     $doc->setId('test1234');
     $repo->store($doc);
     $this->assertTrue(file_exists('/tmp/flywheel/_pages/test1234.json'));
     $doc->setId('9876test');
     $repo->update($doc);
     $this->assertFalse(file_exists('/tmp/flywheel/_pages/test1234.json'));
 }
All Usage Examples Of JamesMoss\Flywheel\Repository::store