*/
public $relPaths = FALSE;
+ /**
+ * @var array($key => $relUrl)
+ *
+ * Derived from $relPaths. On Unix systems (where file-paths and
+ * URL-paths both use '/' separator), this isn't necessary. On Windows
+ * systems, this is derived from $relPaths.
+ *
+ * Note: Treat as private. This is only public to facilitate debugging.
+ */
+ public $relUrls = FALSE;
+
/**
* @param string $baseDir local path to the container
* @param string $baseUrl public URL of the container
}
return $this->relPaths;
}
+
+ /**
+ * Scan $basedir for a list of extension-keys
+ *
+ * @param string $dirSep the local system's directory separator
+ * @return array($key => $relUrl)
+ */
+ protected function getRelUrls() {
+ if (DIRECTORY_SEPARATOR == '/') {
+ return $this->getRelPaths();
+ }
+ if (!is_array($this->relUrls)) {
+ $this->relUrls = self::convertPathsToUrls(DIRECTORY_SEPARATOR, $this->getRelPaths());
+ }
+ return $this->relUrls;
+ }
+
+ /**
+ * Convert a list of relative paths to relative URLs.
+ *
+ * Note: Treat as private. This is only public to facilitate testing.
+ *
+ * @param string $dirSep
+ * @param array $relPaths ($key => $relPath)
+ * @return array($key => $relUrl)
+ */
+ public static function convertPathsToUrls($dirSep, $relPaths) {
+ $relUrls = array();
+ foreach ($relPaths as $key => $relPath) {
+ $relUrls[$key] = str_replace($dirSep, '/', $relPath);
+ }
+ return $relUrls;
+ }
}
$c = new CRM_Extension_Container_Basic($basedir . $appendPathGarbage, 'http://example/basedir' . $appendPathGarbage, $cache, $cacheKey);
return array($basedir, $c);
}
+
+ function testConvertPathsToUrls() {
+ $relPaths = array(
+ 'foo.bar' => 'foo\bar',
+ 'whiz.bang' => 'tests\extensions\whiz\bang'
+ );
+ $expectedRelUrls = array(
+ 'foo.bar' => 'foo/bar',
+ 'whiz.bang' => 'tests/extensions/whiz/bang',
+ );
+ $actualRelUrls = CRM_Extension_Container_Basic::convertPathsToUrls('\\', $relPaths);
+ $this->assertEquals($expectedRelUrls, $actualRelUrls);
+ }
}