-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18aa3e3
commit e6239b1
Showing
4 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `src-run/vermicious-environment-library` project. | ||
* | ||
* (c) Rob Frawley 2nd <rmf@src.run> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SR\Environment; | ||
|
||
/** | ||
* Class IncludePath. | ||
*/ | ||
final class IncludePath | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
static public function restore() | ||
{ | ||
restore_include_path(); | ||
|
||
return static::get(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
static public function get() | ||
{ | ||
return (string) get_include_path(); | ||
} | ||
|
||
/** | ||
* @param string $includePath | ||
* @param bool $prepend | ||
* | ||
* @return bool|string | ||
*/ | ||
static public function add($includePath, $prepend = true) | ||
{ | ||
if (!file_exists($includePath)) { | ||
return false; | ||
} | ||
|
||
$existing = static::get(); | ||
|
||
if ($prepend) { | ||
return set_include_path( | ||
($includePath . PATH_SEPARATOR) . | ||
(substr($existing, 0, 1) === PATH_SEPARATOR ? substr($existing, 1) : $existing)); | ||
} | ||
|
||
return set_include_path( | ||
(substr($existing, -1, 1) === PATH_SEPARATOR ? substr($existing, 0, strlen($existing) - 1) : $existing) . | ||
(PATH_SEPARATOR . $includePath)); | ||
} | ||
|
||
/** | ||
* @param string $includePath | ||
* | ||
* @return bool|string | ||
*/ | ||
static public function prependAdd($includePath) | ||
{ | ||
return static::add($includePath, true); | ||
} | ||
|
||
/** | ||
* @param string $includePath | ||
* | ||
* @return bool|string | ||
*/ | ||
static public function appendAdd($includePath) | ||
{ | ||
return static::add($includePath, false); | ||
} | ||
} | ||
|
||
/* EOF */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the `src-run/vermicious-environment-library` project. | ||
* | ||
* (c) Rob Frawley 2nd <rmf@src.run> | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SR\Environment\Tests; | ||
|
||
use SR\Environment\IncludePath; | ||
|
||
/** | ||
* Class IncludePath. | ||
*/ | ||
class IncludePathTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testPrependAdd() | ||
{ | ||
IncludePath::restore(); | ||
|
||
$default = IncludePath::get(); | ||
IncludePath::prependAdd(__DIR__); | ||
$expected = __DIR__ . PATH_SEPARATOR . $default; | ||
|
||
$this->assertSame($expected, IncludePath::get()); | ||
} | ||
|
||
public function testAppendAdd() | ||
{ | ||
IncludePath::restore(); | ||
|
||
$default = IncludePath::get(); | ||
IncludePath::appendAdd(__DIR__); | ||
$expected = $default . __DIR__; | ||
|
||
$this->assertSame($expected, IncludePath::get()); | ||
} | ||
|
||
public function testAddInvalid() | ||
{ | ||
IncludePath::restore(); | ||
|
||
$default = IncludePath::get(); | ||
IncludePath::appendAdd(__DIR__ . '/does/not/exist'); | ||
$expected = $default; | ||
|
||
$this->assertSame($expected, IncludePath::get()); | ||
} | ||
|
||
public function testRestore() | ||
{ | ||
IncludePath::restore(); | ||
|
||
$default = IncludePath::get(); | ||
IncludePath::appendAdd(__DIR__); | ||
$expected = $default . __DIR__; | ||
|
||
$this->assertSame($expected, IncludePath::get()); | ||
|
||
IncludePath::restore(); | ||
$expected = '.:'; | ||
|
||
$this->assertSame($expected, IncludePath::get()); | ||
} | ||
} | ||
|
||
/* EOF */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters