JamesMoss\Flywheel\NestedRepository::delete PHP 메소드

delete() 공개 메소드

public delete ( $id )
    public function delete($id)
    {
        $result = parent::delete($id);
        if ($id instanceof DocumentInterface) {
            $id = $id->getId();
        }
        if (!$result || !$this->deleteEmptyDirs || !$this->isNestedId($id)) {
            return $result;
        }
        $path = $this->getPathForDocument($id);
        $dir = dirname($path);
        if (file_exists($dir) && count(glob($dir . '/*')) === 0) {
            rmdir($dir);
        }
        return $result;
    }

Usage Example

예제 #1
0
 public function testDeletingDocumentsAndEmptyDirs()
 {
     exec('rm -rf /tmp/flywheel/_pages');
     $config = new Config('/tmp/flywheel', array('delete_empty_dirs' => true));
     $repo = new NestedRepository('_pages', $config);
     $id = 'delete_test/within/a/nested/directory';
     $name = $id . '.json';
     $path = '/tmp/flywheel/_pages/' . $name;
     mkdir(dirname($path), 0777, true);
     file_put_contents($path, '');
     $this->assertTrue(is_file($path));
     $repo->delete($id);
     $this->assertFalse(is_file($path));
     $this->assertFalse(file_exists(dirname($path)));
 }