JamesMoss\Flywheel\Repository::findById PHP Method

findById() public method

Returns a single document based on it's ID
public findById ( string $id ) : Document | boolean
$id string The ID of the document to find
return Document | boolean The document if it exists, false if not.
    public function findById($id)
    {
        if (!file_exists($path = $this->getPathForDocument($id))) {
            return false;
        }
        $fp = fopen($path, 'r');
        $contents = fread($fp, filesize($path));
        fclose($fp);
        $data = $this->formatter->decode($contents);
        if ($data === null) {
            return false;
        }
        $ext = $this->formatter->getFileExtension();
        $doc = new $this->documentClass((array) $data);
        $doc->setId($this->getIdFromPath($path, $ext));
        return $doc;
    }