Skip to content

Commit 97a1edc

Browse files
committed
0.0.4
1 parent 33fa3d5 commit 97a1edc

4 files changed

Lines changed: 7 additions & 57 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codemommy/autoloadphp",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "Automatic load namespaces, classes and files",
55
"keywords": [
66
"CodeMommy",

private/Path.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,6 @@
1313
*/
1414
class Path
1515
{
16-
/**
17-
* Remove First Slash
18-
* @param $string
19-
*/
20-
public static function removeFirstSlash(&$string)
21-
{
22-
if (substr($string, 0, 1) == '/' || substr($string, 0, 1) == '\\') {
23-
$string = substr($string, 1);
24-
self::removeFirstSlash($string);
25-
}
26-
}
27-
28-
/**
29-
* Remove Last Slash
30-
* @param $string
31-
*/
32-
public static function removeLastSlash(&$string)
33-
{
34-
if (substr($string, -1) == '/' || substr($string, -1) == '\\') {
35-
$string = substr($string, 0, -1);
36-
self::removeLastSlash($string);
37-
}
38-
}
39-
4016
/**
4117
* Replace Slash
4218
* @param $string

source/Autoload.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ public static function directory($directory, $namespaceRoot)
2626
{
2727
spl_autoload_register(function ($className) use ($directory, $namespaceRoot) {
2828
Path::replaceSlash($directory);
29-
Path::removeLastSlash($directory);
29+
$directory = rtrim($directory, '/\\');
3030
Path::replaceSlash($namespaceRoot);
31-
Path::removeFirstSlash($namespaceRoot);
32-
Path::removeLastSlash($namespaceRoot);
31+
$namespaceRoot = trim($namespaceRoot, '/\\');
3332
Path::replaceSlash($className);
34-
Path::removeFirstSlash($className);
35-
Path::removeLastSlash($className);
33+
$className = trim($className, '/\\');
3634
if (substr($className, 0, strlen($namespaceRoot)) == $namespaceRoot) {
3735
$className = substr($className, strlen($namespaceRoot));
38-
Path::removeFirstSlash($className);
36+
$className = ltrim($className, '/\\');
3937
}
4038
$extensionList = array('php', 'class.php');
4139
foreach ($extensionList as $extension) {
@@ -56,11 +54,9 @@ public static function file($file, $className)
5654
{
5755
spl_autoload_register(function ($name) use ($file, $className) {
5856
Path::replaceSlash($className);
59-
Path::removeFirstSlash($className);
60-
Path::removeLastSlash($className);
57+
$className = trim($className, '/\\');
6158
Path::replaceSlash($name);
62-
Path::removeFirstSlash($name);
63-
Path::removeLastSlash($name);
59+
$name = trim($name, '/\\');
6460
if ($className == $name) {
6561
if (is_file($file)) {
6662
require_once($file);

test/PathTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,6 @@
2020
*/
2121
class PathTest extends TestCase
2222
{
23-
/**
24-
* Test Remove First Slash
25-
* @return void
26-
*/
27-
public function testRemoveFirstSlash()
28-
{
29-
$string = '/\\CodeMommy';
30-
Path::removeFirstSlash($string);
31-
$this->assertEquals($string, 'CodeMommy');
32-
}
33-
34-
/**
35-
* Test Remove Last Slash
36-
* @return void
37-
*/
38-
public function testRemoveLastSlash()
39-
{
40-
$string = 'CodeMommy/\\';
41-
Path::removeLastSlash($string);
42-
$this->assertEquals($string, 'CodeMommy');
43-
}
44-
4523
/**
4624
* Test Replace Slash
4725
* @return void

0 commit comments

Comments
 (0)