mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Allow Folder::addPathElement() to accept arrays, also corrected docblock
This commit is contained in:
parent
5e9b22271a
commit
b9003e5f7c
2 changed files with 19 additions and 4 deletions
|
@ -345,11 +345,24 @@ class FolderTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testAddPathElement() {
|
public function testAddPathElement() {
|
||||||
|
$expected = DS . 'some' . DS . 'dir' . DS . 'another_path';
|
||||||
|
|
||||||
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
|
||||||
$this->assertEquals(DS . 'some' . DS . 'dir' . DS . 'another_path', $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
|
||||||
$this->assertEquals(DS . 'some' . DS . 'dir' . DS . 'another_path', $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', array('another_path'));
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, array('another_path'));
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$expected = DS . 'some' . DS . 'dir' . DS . 'another_path' . DS . 'and' . DS . 'another';
|
||||||
|
|
||||||
|
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', array('another_path', 'and', 'another'));
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -321,12 +321,14 @@ class Folder {
|
||||||
* Returns $path with $element added, with correct slash in-between.
|
* Returns $path with $element added, with correct slash in-between.
|
||||||
*
|
*
|
||||||
* @param string $path Path
|
* @param string $path Path
|
||||||
* @param string $element Element to and at end of path
|
* @param string|array $element Element to add at end of path
|
||||||
* @return string Combined path
|
* @return string Combined path
|
||||||
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::addPathElement
|
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::addPathElement
|
||||||
*/
|
*/
|
||||||
public static function addPathElement($path, $element) {
|
public static function addPathElement($path, $element) {
|
||||||
return rtrim($path, DS) . DS . $element;
|
$element = (array)$element;
|
||||||
|
array_unshift($element, rtrim($path, DS));
|
||||||
|
return implode(DS, $element)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue