Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mount identifier, for MountManager of FlySystem library, into prefixes #325

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ public function __construct(FilesystemOperator $source, FilesystemOperator $cach
$this->tempDir = sys_get_temp_dir();
}

private function trimPrefix(string $prefix): string
ElGigi marked this conversation as resolved.
Show resolved Hide resolved
{
if ('//' == substr($prefix, -2)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check for '://' === substr($prefix, -3) instead of having a separate check for :?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you respond to above query please.

if (':' == substr(rtrim($prefix, '/'), -1)) {
return rtrim($prefix, '/') . '/';
}
}

return trim($prefix, '/');
}

/**
* Set source file system.
*
Expand Down Expand Up @@ -142,7 +153,7 @@ public function getSource()
*/
public function setSourcePathPrefix($sourcePathPrefix)
{
$this->sourcePathPrefix = trim($sourcePathPrefix, '/');
$this->sourcePathPrefix = $this->trimPrefix($sourcePathPrefix);
}

/**
Expand Down Expand Up @@ -254,7 +265,7 @@ public function getCache()
*/
public function setCachePathPrefix($cachePathPrefix)
{
$this->cachePathPrefix = trim($cachePathPrefix, '/');
$this->cachePathPrefix = $this->trimPrefix($cachePathPrefix);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public function testSetSourcePathPrefix()
$this->assertEquals('img', $this->server->getSourcePathPrefix());
}

public function testSetSourcePathPrefixWithMonthIdentifier()
{
$this->server->setSourcePathPrefix('img://');
$this->assertEquals('img:/', $this->server->getSourcePathPrefix());

$this->server->setSourcePathPrefix('img:///');
$this->assertEquals('img:/', $this->server->getSourcePathPrefix());
}

public function testGetSourcePathPrefix()
{
$this->assertEquals('', $this->server->getSourcePathPrefix());
Expand All @@ -85,6 +94,22 @@ public function testGetSourcePathWithPrefix()
{
$this->server->setSourcePathPrefix('img/');
$this->assertEquals('img/image.jpg', $this->server->getSourcePath('image.jpg'));

$this->server->setSourcePathPrefix('img://');
$this->assertEquals('img://image.jpg', $this->server->getSourcePath('image.jpg'));
$this->assertEquals('img://path/image.jpg', $this->server->getSourcePath('/path/image.jpg'));
}

public function testGetSourcePathWithBaseUrlAndPrefix()
{
$this->server->setBaseUrl('base/');

$this->server->setSourcePathPrefix('img/');
$this->assertEquals('img/image.jpg', $this->server->getSourcePath('/base/image.jpg'));

$this->server->setSourcePathPrefix('img://');
$this->assertEquals('img://image.jpg', $this->server->getSourcePath('base/image.jpg'));
$this->assertEquals('img://path/image.jpg', $this->server->getSourcePath('/base/path/image.jpg'));
}

public function testGetSourcePathWithMissingPath()
Expand Down Expand Up @@ -137,6 +162,15 @@ public function testSetCachePathPrefix()
$this->assertEquals('img', $this->server->getCachePathPrefix());
}

public function testSetCachePathPrefixWithMonthIdentifier()
{
$this->server->setCachePathPrefix('img://');
$this->assertEquals('img:/', $this->server->getCachePathPrefix());

$this->server->setCachePathPrefix('img:///');
$this->assertEquals('img:/', $this->server->getCachePathPrefix());
}

public function testGetCachePathPrefix()
{
$this->assertEquals('', $this->server->getCachePathPrefix());
Expand Down