/** * Default constructor for directory base * @param string $path */ function __construct($path) { if (!Str::endsWith($path, '/')) { $path .= '/'; } if (!Str::startsWith($path, '/')) { $path = '/' . $path; } $cwd = getcwd(); if (strpos($path, $cwd) === false) { $path = $cwd . $path; } $path = Str::flipDS($path); $this->path = $path; }
protected function updateNode(&$node, $aggregateName, $name, $value) { $nodeName = $this->getElementName($node); if ($nodeName === $name || $aggregateName === $name || qtil\StringUtil::endsWith($nodeName, $name)) { if ($node instanceof \SimpleXMLElement) { $node[0] = $value; } elseif ($node instanceof \DOMNode) { $node->nodeValue = $value; } } if ($node instanceof \SimpleXMLElement) { $children = $node->children(); } elseif ($node instanceof \DOMNode) { $children = $node->childNodes; } if (!empty($children)) { foreach ($children as $child) { $this->updateNode($child, $aggregateName . '/' . $this->getElementName($child), $name, $value); } } }
/** * Retrieve path of cache item with additional filters applied * @param string $path * @return string */ public function getPath($path) { $path = str_replace('\\', DIRECTORY_SEPARATOR, $path); $nfo = pathinfo($path); $basename = $nfo['basename']; $path = str_replace(DIRECTORY_SEPARATOR, '-', $basename); if (isset($this->data['hashing']) && $this->data['hashing'] === true) { $path = md5($path); } if (isset($this->data['prepend']) && is_string($this->data['prepend'])) { $path = $this->data['prepend'] . '.' . $path; } $sourcePath = (string) $this->source; if (!qtil\StringUtil::endsWith($sourcePath, DIRECTORY_SEPARATOR)) { $sourcePath .= DIRECTORY_SEPARATOR; } return $sourcePath . $path; }
function testStartEndsWith() { $str = 'hello world'; $this->assertTrue(\qtil\StringUtil::startsWith($str, 'hello')); $this->assertTrue(\qtil\StringUtil::endsWith($str, 'world')); }