本文整理汇总了PHP中CRM_Utils_File::relativize方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_File::relativize方法的具体用法?PHP CRM_Utils_File::relativize怎么用?PHP CRM_Utils_File::relativize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_File
的用法示例。
在下文中一共展示了CRM_Utils_File::relativize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCiviSourceStorage
/**
* Determine the location of the CiviCRM source tree.
*
* @return array
* - url: string. ex: "http://example.com/sites/all/modules/civicrm"
* - path: string. ex: "/var/www/sites/all/modules/civicrm"
*/
public function getCiviSourceStorage()
{
global $civicrm_root;
// Don't use $config->userFrameworkBaseURL; it has garbage on it.
// More generally, we shouldn't be using $config here.
if (!defined('CIVICRM_UF_BASEURL')) {
throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL');
}
$cmsPath = $this->cmsRootPath();
// $config = CRM_Core_Config::singleton();
// overkill? // $cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
$cmsUrl = CIVICRM_UF_BASEURL;
if (CRM_Utils_System::isSSL()) {
$cmsUrl = str_replace('http://', 'https://', $cmsUrl);
}
$civiRelPath = CRM_Utils_File::relativize($civicrm_root, $cmsPath);
$civiUrl = rtrim($cmsUrl, '/') . '/' . ltrim($civiRelPath, ' /');
return array('url' => CRM_Utils_File::addTrailingSlash($civiUrl, '/'), 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root));
}
示例2: glob
/**
* Evaluate a glob pattern in the context of a particular extension.
*
* @param string $ext
* Extension name; use 'civicrm' for core.
* @param string|array $patterns
* Glob pattern; e.g. "*.html".
* @param null|int $flags
* See glob().
* @return array
* List of matching files, relative to the extension base dir.
* @see glob()
*/
public function glob($ext, $patterns, $flags = NULL)
{
$path = $this->getPath($ext);
$patterns = (array) $patterns;
$files = array();
foreach ($patterns as $pattern) {
if (CRM_Utils_File::isAbsolute($pattern)) {
// Absolute path.
$files = array_merge($files, (array) glob($pattern, $flags));
} else {
// Relative path.
$files = array_merge($files, (array) glob("{$path}/{$pattern}", $flags));
}
}
sort($files);
// Deterministic order.
$files = array_unique($files);
return array_map(function ($file) use($path) {
return CRM_Utils_File::relativize($file, "{$path}/");
}, $files);
}
示例3: getRelPaths
/**
* Scan $basedir for a list of extension-keys
*
* @return array
* ($key => $relPath)
*/
protected function getRelPaths()
{
if (!is_array($this->relPaths)) {
if ($this->cache) {
$this->relPaths = $this->cache->get($this->cacheKey);
}
if (!is_array($this->relPaths)) {
$this->relPaths = array();
$infoPaths = CRM_Utils_File::findFiles($this->baseDir, 'info.xml');
foreach ($infoPaths as $infoPath) {
$relPath = CRM_Utils_File::relativize(dirname($infoPath), $this->baseDir);
try {
$info = CRM_Extension_Info::loadFromFile($infoPath);
} catch (CRM_Extension_Exception_ParseException $e) {
CRM_Core_Session::setStatus(ts('Parse error in extension: %1', array(1 => $e->getMessage())), '', 'error');
CRM_Core_Error::debug_log_message("Parse error in extension: " . $e->getMessage());
continue;
}
$this->relPaths[$info->key] = $relPath;
}
if ($this->cache) {
$this->cache->set($this->cacheKey, $this->relPaths);
}
}
}
return $this->relPaths;
}
示例4: findFiles
/**
* Search directory tree for files which match a glob pattern.
*
* Note: Dot-directories (like "..", ".git", or ".svn") will be ignored.
*
* @param string $dir
* base dir.
* @param string $pattern
* glob pattern, eg "*.txt".
* @param bool $relative
* TRUE if paths should be made relative to $dir
* @return array(string)
*/
public static function findFiles($dir, $pattern, $relative = FALSE)
{
if (!is_dir($dir)) {
return array();
}
$dir = rtrim($dir, '/');
$todos = array($dir);
$result = array();
while (!empty($todos)) {
$subdir = array_shift($todos);
$matches = glob("{$subdir}/{$pattern}");
if (is_array($matches)) {
foreach ($matches as $match) {
if (!is_dir($match)) {
$result[] = $relative ? CRM_Utils_File::relativize($match, "{$dir}/") : $match;
}
}
}
if ($dh = opendir($subdir)) {
while (FALSE !== ($entry = readdir($dh))) {
$path = $subdir . DIRECTORY_SEPARATOR . $entry;
if ($entry[0] == '.') {
// ignore
} elseif (is_dir($path)) {
$todos[] = $path;
}
}
closedir($dh);
}
}
return $result;
}