本文整理汇总了PHP中Cake\Filesystem\Folder::addPathElement方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::addPathElement方法的具体用法?PHP Folder::addPathElement怎么用?PHP Folder::addPathElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\Folder
的用法示例。
在下文中一共展示了Folder::addPathElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: realpath
/**
* Get the real path (taking ".." and such into account)
*
* @param string $path Path to resolve
* @return string The resolved path
*/
public function realpath($path)
{
if (strpos($path, '..') === false) {
if (!Folder::isAbsolute($path)) {
$path = Folder::addPathElement($this->path, $path);
}
return $path;
}
$path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
$parts = explode(DIRECTORY_SEPARATOR, $path);
$newparts = [];
$newpath = '';
if ($path[0] === DIRECTORY_SEPARATOR) {
$newpath = DIRECTORY_SEPARATOR;
}
while (($part = array_shift($parts)) !== null) {
if ($part === '.' || $part === '') {
continue;
}
if ($part === '..') {
if (!empty($newparts)) {
array_pop($newparts);
continue;
}
return false;
}
$newparts[] = $part;
}
$newpath .= implode(DIRECTORY_SEPARATOR, $newparts);
return Folder::slashTerm($newpath);
}
示例2: testAddPathElement
/**
* test Adding path elements to a path
*
* @return void
*/
public function testAddPathElement()
{
$expected = DS . 'some' . DS . 'dir' . DS . 'another_path';
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', 'another_path');
$this->assertEquals($expected, $result);
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, 'another_path');
$this->assertEquals($expected, $result);
$result = Folder::addPathElement(DS . 'some' . DS . 'dir', ['another_path']);
$this->assertEquals($expected, $result);
$result = Folder::addPathElement(DS . 'some' . DS . 'dir' . DS, ['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', ['another_path', 'and', 'another']);
$this->assertEquals($expected, $result);
}