Changeset 12847
- Timestamp:
- 11/09/08 20:01:49 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/plugin/sfSymfonyPluginManager.class.php
r12843 r12847 73 73 74 74 $filesystem = new sfFilesystem(); 75 $target = $this->environment->getOption('web_dir').DIRECTORY_SEPARATOR.$plugin; 76 $filesystem->symlink($this->getRelativePath($target, $webDir), $target, true); 75 $filesystem->relativeSymlink($webDir, $this->environment->getOption('web_dir').DIRECTORY_SEPARATOR.$plugin, true); 77 76 } 78 77 } … … 173 172 return true; 174 173 } 175 176 /**177 * Calculates the relative path from one to another directory.178 * If it would go beyond sf_root_dir the absolute path of $to is returned.179 *180 * @param string $from directory from that the relative path shall be calculated181 * @param string $to target directory182 */183 protected function getRelativePath($from, $to)184 {185 $root = $this->environment->getOption('sf_root_dir').DIRECTORY_SEPARATOR;186 if (strstr($from, $root) && strstr($to, $root))187 {188 $levelUp = substr_count($from, DIRECTORY_SEPARATOR, strlen($root));189 // up that many level190 $relativePath = str_repeat("..".DIRECTORY_SEPARATOR, $levelUp);191 // down the remaining $to path192 $relativePath .= substr($to, strlen($root));193 return $relativePath;194 }195 else196 {197 // $to is outside sf_root_dir so return absolute path198 return $to;199 }200 }201 174 } branches/1.2/lib/task/sfFilesystem.class.php
r9097 r12847 227 227 228 228 /** 229 * Creates a symbolic link using a relative path if possible. 230 * 231 * @param string $originDir The origin directory path 232 * @param string $targetDir The symbolic link name 233 * @param bool $copyOnWindows Whether to copy files if on windows 234 */ 235 public function relativeSymlink($originDir, $targetDir, $copyOnWindows = false) 236 { 237 if (function_exists('symlink') || !$copyOnWindows) 238 { 239 $originDir = $this->calculateRelativeDir($targetDir, $originDir); 240 } 241 $this->symlink($originDir, $targetDir, $copyOnWindows); 242 } 243 244 /** 229 245 * Mirrors a directory to another. 230 246 * … … 326 342 $this->dispatcher->notify(new sfEvent($this, 'command.log', array($message))); 327 343 } 344 345 /** 346 * Calculates the relative path from one to another directory. 347 * If they share no common path the absolute target dir is returned 348 * 349 * @param string $from directory from that the relative path shall be calculated 350 * @param string $to target directory 351 */ 352 protected function calculateRelativeDir($from, $to) 353 { 354 $commonChars = 0; 355 $minPathLength = min(strlen($from), strlen($to)); 356 // count how many chars the strings have in common 357 for ($i = 0; $i < $minPathLength; $i++) 358 { 359 if ($from[$i] != $to[$i]) break; 360 $commonChars++; 361 } 362 if ($commonChars) 363 { 364 $levelUp = substr_count($from, DIRECTORY_SEPARATOR, $commonChars); 365 // up that many level 366 $relativeDir = str_repeat("..".DIRECTORY_SEPARATOR, $levelUp); 367 // down the remaining $to path 368 $relativeDir .= substr($to, $commonChars); 369 return $relativeDir; 370 } 371 return $to; 372 } 328 373 }

