Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit 21facc7

Browse files
committed
Merge branch 'feature/windows-anchored-relative' into develop
2 parents 09f6720 + f5ffc7c commit 21facc7

40 files changed

+2637
-1793
lines changed

src/Eloquent/Pathogen/AbsolutePath.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ public static function fromString($path)
3737
/**
3838
* Creates a new absolute path from a set of path atoms.
3939
*
40-
* Unless otherwise specified, created paths will have no trailing
41-
* separator.
42-
*
4340
* @param mixed<string> $atoms The path atoms.
4441
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
4542
*
4643
* @return AbsolutePathInterface The newly created absolute path.
4744
* @throws Exception\InvalidPathAtomExceptionInterface If any of the supplied atoms are invalid.
45+
* @throws Exception\InvalidPathStateException If the supplied arguments would produce an invalid path.
4846
*/
4947
public static function fromAtoms($atoms, $hasTrailingSeparator = null)
5048
{
@@ -87,7 +85,8 @@ public function joinTrailingSlash()
8785
* If this path is relative, a new absolute path with equivalent atoms will
8886
* be returned. Otherwise, this path will be retured unaltered.
8987
*
90-
* @return AbsolutePathInterface An absolute version of this path.
88+
* @return AbsolutePathInterface An absolute version of this path.
89+
* @throws Exception\InvalidPathStateException If absolute conversion is not possible for this path.
9190
*/
9291
public function toAbsolute()
9392
{
@@ -108,7 +107,7 @@ public function toRelative()
108107
return $this->createPath(
109108
$this->atoms(),
110109
false,
111-
$this->hasTrailingSeparator()
110+
false
112111
);
113112
}
114113

@@ -195,7 +194,7 @@ public function relativeTo(AbsolutePathInterface $path)
195194
}
196195
}
197196

198-
return $this->createPath($diffAtoms, false);
197+
return $this->createPath($diffAtoms, false, false);
199198
}
200199

201200
/**

src/Eloquent/Pathogen/AbstractPath.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ public function string()
157157
{
158158
return
159159
implode(static::ATOM_SEPARATOR, $this->atoms()) .
160-
($this->hasTrailingSeparator() ? static::ATOM_SEPARATOR : '')
161-
;
160+
($this->hasTrailingSeparator() ? static::ATOM_SEPARATOR : '');
162161
}
163162

164163
/**
@@ -579,17 +578,14 @@ public function parent($numLevels = null)
579578
$numLevels = 1;
580579
}
581580

582-
$atoms = array_merge(
583-
$this->atoms(),
584-
array_fill(0, $numLevels, static::PARENT_ATOM)
585-
);
586-
587-
$parent = $this->createPath(
588-
$atoms,
589-
$this instanceof AbsolutePathInterface
581+
return $this->createPath(
582+
array_merge(
583+
$this->atoms(),
584+
array_fill(0, $numLevels, static::PARENT_ATOM)
585+
),
586+
$this instanceof AbsolutePathInterface,
587+
false
590588
);
591-
592-
return $parent;
593589
}
594590

595591
/**
@@ -605,7 +601,8 @@ public function stripTrailingSlash()
605601

606602
return $this->createPath(
607603
$this->atoms(),
608-
$this instanceof AbsolutePathInterface
604+
$this instanceof AbsolutePathInterface,
605+
false
609606
);
610607
}
611608

@@ -659,7 +656,8 @@ public function joinAtomSequence($atoms)
659656

660657
return $this->createPath(
661658
array_merge($this->atoms(), $atoms),
662-
$this instanceof AbsolutePathInterface
659+
$this instanceof AbsolutePathInterface,
660+
false
663661
);
664662
}
665663

@@ -794,7 +792,8 @@ public function replace($index, $replacement, $length = null)
794792

795793
return $this->createPath(
796794
$atoms,
797-
$this instanceof AbsolutePathInterface
795+
$this instanceof AbsolutePathInterface,
796+
false
798797
);
799798
}
800799

@@ -822,7 +821,8 @@ public function replaceName($name)
822821

823822
return $this->createPath(
824823
$atoms,
825-
$this instanceof AbsolutePathInterface
824+
$this instanceof AbsolutePathInterface,
825+
false
826826
);
827827
}
828828

@@ -997,8 +997,7 @@ protected function normalizeAtoms($atoms)
997997
*
998998
* @param string $atom The atom to validate.
999999
*
1000-
* @throws Exception\EmptyPathAtomException If the path atom is empty.
1001-
* @throws Exception\PathAtomContainsSeparatorException If the path atom contains a separator.
1000+
* @throws Exception\InvalidPathAtomExceptionInterface If an invalid path atom is encountered.
10021001
*/
10031002
protected function validateAtom($atom)
10041003
{
@@ -1058,7 +1057,7 @@ protected static function normalizer()
10581057
/**
10591058
* Get the most appropriate path resolver for this type of path.
10601059
*
1061-
* @return Normalizer\PathResolverInterface The path resolver.
1060+
* @return Resolver\PathResolverInterface The path resolver.
10621061
*/
10631062
protected static function resolver()
10641063
{

src/Eloquent/Pathogen/Factory/PathFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Eloquent\Pathogen\AbsolutePath;
1515
use Eloquent\Pathogen\AbstractPath;
1616
use Eloquent\Pathogen\Exception\InvalidPathAtomExceptionInterface;
17+
use Eloquent\Pathogen\Exception\InvalidPathStateException;
1718
use Eloquent\Pathogen\PathInterface;
1819
use Eloquent\Pathogen\RelativePath;
1920

@@ -86,24 +87,23 @@ public function create($path)
8687
/**
8788
* Creates a new path instance from a set of path atoms.
8889
*
89-
* Unless otherwise specified, created paths will be absolute, and have no
90-
* trailing separator.
91-
*
9290
* @param mixed<string> $atoms The path atoms.
9391
* @param boolean|null $isAbsolute True if the path is absolute.
9492
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
9593
*
9694
* @return PathInterface The newly created path instance.
9795
* @throws InvalidPathAtomExceptionInterface If any of the supplied atoms are invalid.
96+
* @throws InvalidPathStateException If the supplied arguments would produce an invalid path.
9897
*/
9998
public function createFromAtoms(
10099
$atoms,
101100
$isAbsolute = null,
102101
$hasTrailingSeparator = null
103102
) {
104103
if (null === $isAbsolute) {
105-
$isAbsolute = true;
104+
$isAbsolute = false;
106105
}
106+
107107
if ($isAbsolute) {
108108
return new AbsolutePath($atoms, $hasTrailingSeparator);
109109
}

src/Eloquent/Pathogen/Factory/PathFactoryInterface.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Eloquent\Pathogen\Factory;
1313

1414
use Eloquent\Pathogen\Exception\InvalidPathAtomExceptionInterface;
15+
use Eloquent\Pathogen\Exception\InvalidPathStateException;
1516
use Eloquent\Pathogen\PathInterface;
1617

1718
/**
@@ -31,15 +32,13 @@ public function create($path);
3132
/**
3233
* Creates a new path instance from a set of path atoms.
3334
*
34-
* Unless otherwise specified, created paths will be absolute, and have no
35-
* trailing separator.
36-
*
3735
* @param mixed<string> $atoms The path atoms.
3836
* @param boolean|null $isAbsolute True if the path is absolute.
3937
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
4038
*
4139
* @return PathInterface The newly created path instance.
4240
* @throws InvalidPathAtomExceptionInterface If any of the supplied atoms are invalid.
41+
* @throws InvalidPathStateException If the supplied arguments would produce an invalid path.
4342
*/
4443
public function createFromAtoms(
4544
$atoms,

src/Eloquent/Pathogen/FileSystem/Factory/FileSystemPathFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Eloquent\Pathogen\FileSystem\Factory;
1313

14+
use Eloquent\Pathogen\Exception\InvalidPathAtomExceptionInterface;
15+
use Eloquent\Pathogen\Exception\InvalidPathStateException;
1416
use Eloquent\Pathogen\PathInterface;
1517

1618
/**
@@ -42,7 +44,7 @@ public static function instance()
4244
*/
4345
public function create($path)
4446
{
45-
if (preg_match('/^([a-zA-Z]):/', $path)) {
47+
if (preg_match('{^([a-zA-Z]):}', $path)) {
4648
return $this->windowsFactory()->create($path);
4749
}
4850

@@ -52,15 +54,13 @@ public function create($path)
5254
/**
5355
* Creates a new path instance from a set of path atoms.
5456
*
55-
* Unless otherwise specified, created paths will be absolute, and have no
56-
* trailing separator.
57-
*
5857
* @param mixed<string> $atoms The path atoms.
5958
* @param boolean|null $isAbsolute True if the path is absolute.
6059
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
6160
*
6261
* @return PathInterface The newly created path instance.
6362
* @throws InvalidPathAtomExceptionInterface If any of the supplied atoms are invalid.
63+
* @throws InvalidPathStateException If the supplied arguments would produce an invalid path.
6464
*/
6565
public function createFromAtoms(
6666
$atoms,

src/Eloquent/Pathogen/FileSystem/Factory/PlatformFileSystemPathFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Eloquent\Pathogen\FileSystem\Factory;
1313

14+
use Eloquent\Pathogen\Exception\InvalidPathStateException;
1415
use Eloquent\Pathogen\PathInterface;
1516

1617
/**
@@ -48,15 +49,13 @@ public function create($path)
4849
/**
4950
* Creates a new path instance from a set of path atoms.
5051
*
51-
* Unless otherwise specified, created paths will be absolute, and have no
52-
* trailing separator.
53-
*
5452
* @param mixed<string> $atoms The path atoms.
5553
* @param boolean|null $isAbsolute True if the path is absolute.
5654
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
5755
*
5856
* @return PathInterface The newly created path instance.
5957
* @throws InvalidPathAtomExceptionInterface If any of the supplied atoms are invalid.
58+
* @throws InvalidPathStateException If the supplied arguments would produce an invalid path.
6059
*/
6160
public function createFromAtoms(
6261
$atoms,

src/Eloquent/Pathogen/Path.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ public static function fromString($path)
3333
/**
3434
* Creates a new path instance from a set of path atoms.
3535
*
36-
* Unless otherwise specified, created paths will be absolute, and have no
37-
* trailing separator.
38-
*
3936
* @param mixed<string> $atoms The path atoms.
4037
* @param boolean|null $isAbsolute True if the path is absolute.
4138
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.

src/Eloquent/Pathogen/PathInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ public function replaceNameAtoms($index, $replacement, $length = null);
455455
* If this path is relative, a new absolute path with equivalent atoms will
456456
* be returned. Otherwise, this path will be retured unaltered.
457457
*
458-
* @return AbsolutePathInterface An absolute version of this path.
458+
* @return AbsolutePathInterface An absolute version of this path.
459+
* @throws Exception\InvalidPathStateException If absolute conversion is not possible for this path.
459460
*/
460461
public function toAbsolute();
461462

src/Eloquent/Pathogen/RelativePath.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ public static function fromString($path)
3737
/**
3838
* Creates a new relative path from a set of path atoms.
3939
*
40-
* Unless otherwise specified, created paths will have no trailing
41-
* separator.
42-
*
4340
* @param mixed<string> $atoms The path atoms.
4441
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
4542
*
4643
* @return RelativePathInterface The newly created relative path.
4744
* @throws Exception\InvalidPathAtomExceptionInterface If any of the supplied atoms are invalid.
45+
* @throws Exception\InvalidPathStateException If the supplied arguments would produce an invalid path.
4846
*/
4947
public static function fromAtoms($atoms, $hasTrailingSeparator = null)
5048
{
@@ -63,14 +61,15 @@ public static function fromAtoms($atoms, $hasTrailingSeparator = null)
6361
* If this path is relative, a new absolute path with equivalent atoms will
6462
* be returned. Otherwise, this path will be retured unaltered.
6563
*
66-
* @return AbsolutePathInterface An absolute version of this path.
64+
* @return AbsolutePathInterface An absolute version of this path.
65+
* @throws Exception\InvalidPathStateException If absolute conversion is not possible for this path.
6766
*/
6867
public function toAbsolute()
6968
{
7069
return $this->createPath(
7170
$this->atoms(),
7271
true,
73-
$this->hasTrailingSeparator()
72+
false
7473
);
7574
}
7675

src/Eloquent/Pathogen/Unix/AbsoluteUnixPath.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Eloquent\Pathogen\Factory\PathFactoryInterface;
1616
use Eloquent\Pathogen\FileSystem\AbsoluteFileSystemPathInterface;
1717
use Eloquent\Pathogen\Normalizer\PathNormalizerInterface;
18-
use Eloquent\Pathogen\PathInterface;
1918

2019
/**
2120
* Represents an absolute Unix path.
@@ -24,20 +23,6 @@ class AbsoluteUnixPath extends AbsolutePath implements
2423
AbsoluteFileSystemPathInterface,
2524
AbsoluteUnixPathInterface
2625
{
27-
// Implementation of PathInterface =========================================
28-
29-
/**
30-
* Get the parent of this path a specified number of levels up.
31-
*
32-
* @param integer|null $numLevels The number of levels up. Defaults to 1.
33-
*
34-
* @return PathInterface The parent of this path $numLevels up.
35-
*/
36-
public function parent($numLevels = null)
37-
{
38-
return parent::parent($numLevels)->normalize();
39-
}
40-
4126
// Implementation details ==================================================
4227

4328
/**

src/Eloquent/Pathogen/Unix/Factory/UnixPathFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Eloquent\Pathogen\Unix\Factory;
1313

1414
use Eloquent\Pathogen\Exception\InvalidPathAtomExceptionInterface;
15+
use Eloquent\Pathogen\Exception\InvalidPathStateException;
1516
use Eloquent\Pathogen\Factory\PathFactory;
1617
use Eloquent\Pathogen\PathInterface;
1718
use Eloquent\Pathogen\Unix\AbsoluteUnixPath;
@@ -39,24 +40,23 @@ public static function instance()
3940
/**
4041
* Creates a new path instance from a set of path atoms.
4142
*
42-
* Unless otherwise specified, created paths will be absolute, and have no
43-
* trailing separator.
44-
*
4543
* @param mixed<string> $atoms The path atoms.
4644
* @param boolean|null $isAbsolute True if the path is absolute.
4745
* @param boolean|null $hasTrailingSeparator True if the path has a trailing separator.
4846
*
4947
* @return PathInterface The newly created path instance.
5048
* @throws InvalidPathAtomExceptionInterface If any of the supplied atoms are invalid.
49+
* @throws InvalidPathStateException If the supplied arguments would produce an invalid path.
5150
*/
5251
public function createFromAtoms(
5352
$atoms,
5453
$isAbsolute = null,
5554
$hasTrailingSeparator = null
5655
) {
5756
if (null === $isAbsolute) {
58-
$isAbsolute = true;
57+
$isAbsolute = false;
5958
}
59+
6060
if ($isAbsolute) {
6161
return new AbsoluteUnixPath($atoms, $hasTrailingSeparator);
6262
}

0 commit comments

Comments
 (0)