Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"phpunit/phpunit": "^4.7"
},
"scripts": {
"test": "vendor/bin/phpunit --colors=always",
"test:acceptance": "vendor/bin/phpunit --colors=always --testsuite acceptance",
"test:functional": "vendor/bin/phpunit --colors=always --testsuite functional",
"test:unit": "vendor/bin/phpunit --colors=always --testsuite unit",
"test": "vendor/bin/phpunit -v --colors=always",
"test:acceptance": "vendor/bin/phpunit -v --colors=always --testsuite acceptance",
"test:functional": "vendor/bin/phpunit -v --colors=always --testsuite functional",
"test:unit": "vendor/bin/phpunit -v --colors=always --testsuite unit",
"lint:fix": [
"vendor/bin/php-cs-fixer fix src --level=psr2",
"vendor/bin/php-cs-fixer fix test --level=psr2"
Expand Down
104 changes: 104 additions & 0 deletions src/Node/DirectoryLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/*
* This file is part of VFS
*
* Copyright (c) 2015 Andrew Lawson <http://adlawson.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Vfs\Node;

use DateTime;

class DirectoryLink implements NodeContainerInterface, LinkInterface
{
protected $dateAccessed;
protected $dateCreated;
protected $dateModified;
protected $file;
protected $mode;

/**
* @param NodeContainerInterface $directory
*/
public function __construct(NodeContainerInterface $directory)
{
$this->directory = $directory;
$this->mode = self::TYPE_LINK;

$this->dateAccessed = new DateTime();
$this->dateCreated = clone $this->dateAccessed;
$this->dateModified = clone $this->dateAccessed;
}

public function add($name, NodeInterface $node)
{
$this->directory->add($name, $node);
}

public function get($name)
{
return $this->directory->get($name);
}

public function has($name)
{
return $this->directory->has($name);
}

public function remove($name)
{
$this->directory->remove($name);
}

public function set($name, NodeInterface $node)
{
$this->directory->set($name, $node);
}

public function getDateAccessed()
{
return $this->dateAccessed;
}

public function setDateAccessed(DateTime $dateTime)
{
$this->dateAccessed = $dateTime;
}

public function getDateCreated()
{
return $this->dateCreated;
}

public function getDateModified()
{
return $this->dateModified;
}

public function setDateModified(DateTime $dateTime)
{
$this->dateModified = $dateTime;
}

public function getIterator()
{
return $this->directory->getIterator();
}

public function getMode()
{
return $this->mode;
}

public function getSize()
{
return $this->directory->getSize();
}

public function getTarget()
{
return $this->directory;
}
}
13 changes: 10 additions & 3 deletions src/Node/Factory/NodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

use LogicException;
use Vfs\Node\Directory;
use Vfs\Node\DirectoryLink;
use Vfs\Node\File;
use Vfs\Node\FileLink;
use Vfs\Node\FileInterface;
use Vfs\Node\NodeContainerInterface;
use Vfs\Node\NodeInterface;

class NodeFactory implements NodeFactoryInterface
{
Expand All @@ -22,14 +24,19 @@ public function buildDirectory(array $children = [])
return new Directory($children);
}

public function buildDirectoryLink(NodeContainerInterface $target)
{
return new DirectoryLink($target);
}

public function buildFile($content = '')
{
return new File($content);
}

public function buildLink($content = '')
public function buildFileLink(FileInterface $target)
{
throw new LogicException('Symlinks aren\'t supported yet.');
return new FileLink($target);
}

public function buildTree(array $tree)
Expand Down
14 changes: 11 additions & 3 deletions src/Node/Factory/NodeFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
namespace Vfs\Node\Factory;

use Vfs\Node\FileInterface;
use Vfs\Node\LinkInterface;
use Vfs\Node\NodeContainerInterface;
use Vfs\Node\NodeInterface;

Expand All @@ -20,17 +22,23 @@ interface NodeFactoryInterface
*/
public function buildDirectory(array $children = []);

/**
* @param NodeContainerInterface $target
* @return LinkInterface
*/
public function buildDirectoryLink(NodeContainerInterface $target);

/**
* @param string $content
* @return NodeInterface
*/
public function buildFile($content = '');

/**
* @param string $content
* @return NodeInterface
* @param FileInterface $file
* @return LinkInterface
*/
public function buildLink($content = '');
public function buildFileLink(FileInterface $target);

/**
* @param array $tree
Expand Down
84 changes: 84 additions & 0 deletions src/Node/FileLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
* This file is part of VFS
*
* Copyright (c) 2015 Andrew Lawson <http://adlawson.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Vfs\Node;

use DateTime;

class FileLink implements FileInterface, LinkInterface
{
protected $dateAccessed;
protected $dateCreated;
protected $dateModified;
protected $file;
protected $mode;

/**
* @param FileInterface $file
*/
public function __construct(FileInterface $file)
{
$this->file = $file;
$this->mode = self::TYPE_LINK;

$this->dateAccessed = new DateTime();
$this->dateCreated = clone $this->dateAccessed;
$this->dateModified = clone $this->dateAccessed;
}

public function getContent()
{
return $this->file->getContent();
}

public function setContent($content)
{
$this->file->setContent($content);
}

public function getDateAccessed()
{
return $this->dateAccessed;
}

public function setDateAccessed(DateTime $dateTime)
{
$this->dateAccessed = $dateTime;
}

public function getDateCreated()
{
return $this->dateCreated;
}

public function getDateModified()
{
return $this->dateModified;
}

public function setDateModified(DateTime $dateTime)
{
$this->dateModified = $dateTime;
}

public function getMode()
{
return $this->mode;
}

public function getSize()
{
return $this->file->getSize();
}

public function getTarget()
{
return $this->file;
}
}
10 changes: 10 additions & 0 deletions src/Node/LinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
*/
namespace Vfs\Node;

/**
* Link node type
*
* This is an implementation of a hard link rather than a symbolic link; the
* key difference being it links directly to a node and not a path. If the
* target node is moved or renamed the link remains intact.
*
* The implementation is a simple proxy, whereby most other method calls should
* proxy through to the target where suitable.
*/
interface LinkInterface extends NodeInterface
{
/**
Expand Down
1 change: 1 addition & 0 deletions src/Node/StatInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface StatInterface
const S_IWOTH = 0000002;
const S_IXOTH = 0000001;

const TYPE_MASK = self::S_IFMT;
const TYPE_SOCKET = self::S_IFSOCK;
const TYPE_LINK = self::S_IFLNK;
const TYPE_FILE = self::S_IFREG;
Expand Down
41 changes: 41 additions & 0 deletions test/acceptance/Stream/StreamWrapper/SymlinkAcceptanceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace Vfs\Stream\StreamWrapper;

use Vfs\Test\AcceptanceTestCase;

class SymlinkAcceptanceTest extends AcceptanceTestCase
{
protected $tree = [
'foo' => [
'bar' => 'baz'
]
];

public function testIsLink()
{
$factory = $this->fs->getNodeFactory();

$file = $this->fs->get('/foo/bar');
$this->fs->get('/')->add('symlink', $factory->buildFileLink($file));

$this->assertTrue(is_link("$this->scheme:///symlink"));
}

public function testDirectoryLink()
{
$this->markTestSkipped('`symlink()` isn\'t supported by PHP Stream Wrappers');

symlink("$this->scheme:///foo/bar", "$this->scheme:///symlink");

$this->assertTrue(is_link("$this->scheme:///symlink"));
}

public function testFileLink()
{
$this->markTestSkipped('`symlink()` isn\'t supported by PHP Stream Wrappers');

symlink("$this->scheme:///foo", "$this->scheme:///symlink");

$this->assertTrue(is_link("$this->scheme:///symlink"));
}
}
Loading