/** * @param string $targetPath * @param string $installPath * @param array $map * @param bool $isSymlink * @param bool $isRelative * * @throws IOException * @throws \InvalidArgumentException * * @api * * @quality:method [B] */ public function publish($targetPath, $installPath, array $map, $isSymlink, $isRelative) { $targetPath = rtrim($targetPath, '/'); $installPath = rtrim($installPath, '/'); $this->filesystem->mkdir($targetPath, 0777); foreach ($map as $from => $to) { $targetDir = realpath($targetPath) . '/' . $to; $sourceDir = realpath($installPath) . '/' . $from; $this->filesystem->remove($targetDir); if ($isSymlink) { $this->io->write(sprintf('Trying to install AdminLTE %s assets as symbolic links.', $from)); $originDir = $sourceDir; if ($isRelative) { $originDir = $this->filesystem->makePathRelative($sourceDir, realpath($targetPath)); } try { $this->filesystem->symlink($originDir, $targetDir); $this->io->write(sprintf('The AdminLTE %s assets were installed using symbolic links.', $from)); } catch (IOException $e) { $this->hardCopy($sourceDir, $targetDir); $this->io->write(sprintf('It looks like your system doesn\'t support symbolic links, so the AdminLTE %s assets were installed by copying them.', $from)); } } else { $this->io->write(sprintf('Installing AdminLTE %s assets as <comment>hard copies</comment>.', $from)); $this->hardCopy($sourceDir, $targetDir); } } }
private function symlinkPackageToVendor($packagePath, $vendorPath) { $relative = $this->fileSystem->makePathRelative(realpath($packagePath), realpath($vendorPath . '/../')); $this->fileSystem->rename($vendorPath, $vendorPath . '_linked', true); $this->fileSystem->symlink($relative, $vendorPath); $this->fileSystem->remove($vendorPath . '_linked'); }
/** * Adds extra JS to load on pages using the Scribite editor. * * @param Zikula_Event $event */ public function getScribiteEditorHelpers(Zikula_Event $event) { // intended is using the add() method to add a helper like below $helpers = $event->getSubject(); $helpers->add(['module' => 'CmfcmfMediaModule', 'type' => 'javascript', 'path' => $this->fs->makePathRelative($this->resourceRoot . '/public/js/vendor', $this->zikulaRoot) . 'toastr.min.js']); $helpers->add(['module' => 'CmfcmfMediaModule', 'type' => 'stylesheet', 'path' => $this->fs->makePathRelative($this->resourceRoot . '/public/css/vendor', $this->zikulaRoot) . 'toastr.min.css']); $helpers->add(['module' => 'CmfcmfMediaModule', 'type' => 'javascript', 'path' => $this->fs->makePathRelative($this->resourceRoot . '/public/js', $this->zikulaRoot) . 'util.js']); }
/** * @param string $src * * @return Configuration */ private function createConfig($src) { $configuration = new Configuration($src); $configuration->setJsonFile('component.json'); $configuration->setEndpoint('https://bower.herokuapp.com'); $configuration->setCache(new FilesystemCache($this->target . '/cache')); $configuration->setAssetDirectory($this->filesystem->makePathRelative($this->target . '/components', $src)); return $configuration; }
public function __construct(TranslatorInterface $translator, $kernelCacheDir, $kernelRootDir) { $this->fs = new Filesystem(); $this->cacheFile = $kernelCacheDir . "/CmfcmfMediaModule.zip"; $zikulaDir = realpath($kernelRootDir . '/..'); $this->moduleDir = $this->fs->makePathRelative(realpath(__DIR__ . '/..'), $zikulaDir); $this->domain = \ZLanguage::getModuleDomain('CmfcmfMediaModule'); $this->translator = $translator; }
protected function getCompilationOptions() { $fs = new Filesystem(); $fs->mkdir(dirname($this->getBootstrapLessFile())); $assets_dir = $fs->makePathRelative(realpath($this->getAssetsDir()), realpath(dirname($this->getBootstrapLessFile()))); $variablesDir = $fs->makePathRelative(realpath(dirname($this->getVariablesFile())), realpath(dirname($this->getBootstrapLessFile()))); $variablesFile = sprintf('%s%s', $variablesDir, basename($this->getVariablesFile())); return array('variables_dir' => $variablesDir, 'variables_file' => $variablesFile, 'assets_dir' => $assets_dir); }
/** * @param Bundle $bundle * @param string $type * @param boolean $regenerate * * @return string */ public function show(Bundle $bundle, $type = 'long', $regenerate = false) { $relativePath = $this->filesystem->makePathRelative($this->cacheDir, $this->rootDir); $filename = sprintf('%sbadges/%s/%s-%s.png', $relativePath, $type, $bundle->getOwnerName(), $bundle->getName()); if (false !== $regenerate || !$this->filesystem->exists($filename)) { $this->generate($bundle); } return $filename; }
private function symlink($target, $link) { // echo __LINE__, "\n", $target, " ==> " , $link, "\n" ; if (!file_exists($target)) { throw new \Exception(sprintf("`%s` is not exists", $target)); } if (is_link($link)) { $_target = readlink($link); if (realpath($_target) != realpath($target)) { // throw new \Exception( sprintf("`%s` should be a link point to `%s`, but it point to `%s`", $link , $target, $_target ) ) ; unlink($link); } else { return; } } else { if (file_exists($link)) { throw new \Exception(sprintf("`%s` should be a link point to `%s`", $link, $target)); } } $_path = $this->file_system->makePathRelative($target, dirname($link)); $_path = rtrim($_path, '/'); symlink($_path, $link); if (!file_exists($link)) { throw new \Exception(sprintf("`%s` is not exists, link to `%s` -> `%s`", $link, $_path, $target)); } }
/** * Links Drupal core, modules, themes and assets into Drupal root. * * @param Event $event */ public static function prepareDrupalRoot(Event $event) { $options = self::getOptions($event); $composer = $event->getComposer(); $filesystem = new Filesystem(); $originDir = realpath($composer->getConfig()->get('vendor-dir') . '/drupal/drupal'); $targetDir = realpath($options['drupal-root']); if (is_dir($originDir)) { if ($options['drupal-install']['relative']) { $originDir = rtrim($filesystem->makePathRelative($originDir, $targetDir), '/'); } $directories = array('includes', 'misc', 'modules', 'themes'); foreach ($directories as $directory) { $filesystem->remove($targetDir . '/' . $directory); if ($options['drupal-install']['symlink']) { $event->getIO()->write(sprintf('Creating symlink for Drupal\'s \'%s\' directory', $directory)); $filesystem->symlink($originDir . '/' . $directory, $targetDir . '/' . $directory); } else { $event->getIO()->write(sprintf('Copying Drupal\'s \'%s\' directory to web root', $directory)); $filesystem->mkdir($targetDir . '/' . $directory, 0777); // We use a custom iterator to ignore VCS files $filesystem->mirror($originDir . '/' . $directory, $targetDir . '/' . $directory, Finder::create()->ignoreDotFiles(false)->in($originDir)); } } } }
/** * @param $dir * @param InputInterface $input * @param OutputInterface $output * @return bool */ private function installPluginAssets($dir, InputInterface $input, OutputInterface $output) { // Create the specific assets directory otherwise symlink will fail. $assetsDir = $dir . '/assets/plugins/'; $this->filesystem->mkdir($assetsDir, 0777); $plugins = $this->getContainer()->get('simplr.pluginmanager')->getActivePlugins(); if (!empty($plugins)) { foreach ($plugins as $name => $configuration) { $activePluginPath = $this->getContainer()->get('simplr.pluginmanager')->getPathToPlugin($name); if (is_dir($originDir = $activePluginPath . '/Resources/public')) { $targetDir = $assetsDir . strtolower($name); $output->writeln(sprintf("Installing assets for plugin <comment>%s</comment> into <comment>%s</comment>", $name, $targetDir)); $this->filesystem->remove($targetDir); if ($input->getOption('symlink')) { if ($input->getOption('relative')) { $relativeOriginDir = $this->filesystem->makePathRelative($originDir, realpath($assetsDir)); } else { $relativeOriginDir = $originDir; } $this->filesystem->symlink($relativeOriginDir, $targetDir); } else { $this->filesystem->mkdir($targetDir, 0777); // We use a custom iterator to ignore VCS files $this->filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir)); } } } } else { $output->writeln('Installing assets for plugins... no plugins found!'); } return true; }
public function bbs_twig_template(\Twig_Environment $env, $file, $path, $templateid = 0) { /** * @var $loader \Symfony\Bundle\TwigBundle\Loader\FilesystemLoader */ $loader = $env->getLoader(); $tplfile = $loader->getCacheKey($file); if (null === $this->file_system) { $this->file_system = new \Symfony\Component\Filesystem\Filesystem(); } $tplfile = rtrim($this->file_system->makePathRelative($tplfile, DISCUZ_ROOT), '/'); if (empty($path) || !is_string($path)) { throw new \Exception(sprintf("path(%s) must be string", json_encode($path))); } $this->cache['app_template_cache_file'] = './data/template/' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . preg_replace('/\\W/', '_', $file) . '.tpl.php'; $tpldir = './template/default'; $_pos = strpos($path, ':'); if (false !== $_pos) { if ($_pos !== strrpos($path, ':')) { throw new \Exception(sprintf('not implement locate plugin tempalte dir:%s', $path)); } $tpldir = sprintf('./source/plugin/%s/template', substr($path, 0, $_pos)); } checktplrefresh($tplfile, $tplfile, @filemtime(DISCUZ_ROOT . $this->cache['app_template_cache_file']), $templateid, $this->cache['app_template_cache_file'], $tpldir, $path); unset($tplfile, $tpldir, $loader, $env, $path, $templateid, $_pos); extract($GLOBALS, EXTR_REFS); include DISCUZ_ROOT . $this->cache['app_template_cache_file']; }
/** * @return GitRepository */ protected function initializeLocalRepository() { $cloneUrl = $this->filesystem->makePathRelative(self::REMOTE_REPOSITORY_DIRECTORY, dirname(self::LOCAL_REPOSITORY_DIRECTORY)); $localRepository = new GitRepository($this->gitWrapper, self::LOCAL_REPOSITORY_DIRECTORY); $localRepository->create($cloneUrl); return $localRepository; }
/** * Get relative path. * * @param string $namespace * * @return string */ public function levelUp($namespace) { if (empty($namespace)) { return ''; } else { return $this->fs->makePathRelative($this->outputDir, $this->getPathByNamespace($namespace, true)); } }
/** * Prints trace / call stack / backtrace of an exception. * * @param array $trace The back trace to print out. */ private function printExceptionTrace(array $trace) { $trace = array_reverse($trace); $this->output->writeln('Call Stack:'); foreach ($trace as $i => $call) { $this->output->writeln(sprintf(' %d. <info>%s%s%s(</info>%s<info>)</info> in <comment>%s</comment>:%d', $i + 1, $call['class'], $call['type'], $call['function'], $this->parseCallArguments($call['args']), $this->filesystem->makePathRelative($call['file'], $this->cwd), $call['line'])); } }
/** * Checks if giving a relative path results in the same path under water. */ public function testCacheDirLocation() { $cacheDirLocation = $this->cache->getDirectory(); $filesystem = new Filesystem(); $relative = $filesystem->makePathRelative($cacheDirLocation, __DIR__); $newCache = new Cache($relative); $this->assertEquals($cacheDirLocation, $newCache->getDirectory()); }
/** * Set up our actions and filters */ public function __construct() { // Create a Filesystem object. $this->filesystem = new \Symfony\Component\Filesystem\Filesystem(); // Discover the correct relative path for the mu-plugins directory. $this->mu_plugin_dir = $this->filesystem->makePathRelative(WPMU_PLUGIN_DIR, WP_PLUGIN_DIR); if (!$this->filesystem->isAbsolutePath($this->mu_plugin_dir)) { $this->mu_plugin_dir = '/' . $this->mu_plugin_dir; } if ('/' === substr($this->mu_plugin_dir, -1)) { $this->mu_plugin_dir = rtrim($this->mu_plugin_dir, '/'); } // Load the plugins add_action('muplugins_loaded', array($this, 'muplugins_loaded__requirePlugins')); // Adjust the MU plugins list table to show which plugins are MU add_action('after_plugin_row_muplugins-subdir-loader.php', array($this, 'after_plugin_row__addRows')); }
/** * @param $path * * @return string * @throws FileNotFoundException If file doesn't exists */ public function getRelativePath($path) { $path = trim($path); $realpath = realpath($path); if (false === $realpath) { throw new FileNotFoundException($path); } return $this->fileSystem->makePathRelative($realpath, $this->getWorkingDir()); }
/** * Finds and instantiates generator commands. * * @return \Symfony\Component\Console\Command\Command[] * Array of generators. */ public function getGenerators() { $commands = []; foreach ($this->commandDirectories as $directory) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS)); foreach ($iterator as $path => $file) { if ($file->getExtension() == 'php') { $relative_path = $this->filesystem->makePathRelative($path, $directory); $class = self::COMMANDS_NAMESPACE . str_replace('/', '\\', preg_replace('#.php/$#', '', $relative_path)); $reflected_class = new ReflectionClass($class); if (!$reflected_class->isInterface() && !$reflected_class->isAbstract() && $reflected_class->implementsInterface(self::COMMANDS_BASE_INTERFACE)) { $commands[] = $class::create($this->twigDirectories); } } } } return $commands; }
/** * Generates a symlink. * * The method will try to generate relative symlinks and fall back to generating * absolute symlinks if relative symlinks are not supported (see #208). * * @param string $source The symlink name * @param string $target The symlink target * @param string $rootDir The root directory */ public static function symlink($source, $target, $rootDir) { static::validateSymlink($source, $target, $rootDir); $fs = new Filesystem(); if ('\\' === DIRECTORY_SEPARATOR) { $fs->symlink($rootDir . '/' . $source, $rootDir . '/' . $target); } else { $fs->symlink(rtrim($fs->makePathRelative($source, dirname($target)), '/'), $rootDir . '/' . $target); } }
/** * Creates symbolic link. * * @param string $originDir * @param string $targetDir * @param bool $relative * * @throws IOException If link can not be created. */ private function symlink($originDir, $targetDir, $relative = false) { if ($relative) { $originDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir))); } $this->filesystem->symlink($originDir, $targetDir); if (!file_exists($targetDir)) { throw new IOException(sprintf('Symbolic link "%s" was created but appears to be broken.', $targetDir), 0, null, $targetDir); } }
protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $resolved = $this->getContainer()->get('hoathis.locator.wrapper')->resolve($input->getArgument('path')); if ($input->getOption('relative') === true) { $resolved = $fs->makePathRelative(dirname($resolved), $input->getOption('relative-root')) . basename($resolved); } $table = $this->getHelper('table'); $table->addRows(array(array('Virtual path', sprintf('<info>%s</info>', $input->getArgument('path'))), array('Resolved path', sprintf('<info>%s</info>', $resolved)), array('Is directory', sprintf('<info>%s</info>', $this->yesNo(is_dir($resolved)))), array('Is file', sprintf('<info>%s</info>', $this->yesNo(is_file($resolved)))), array('Is symlink', sprintf('<info>%s</info>', $this->yesNo(is_link($resolved))))))->render($output); }
public function search($q, $path) { $path = $this->preparePath($path); $files = $this->doSearch($q, $path); $data = []; foreach ($files as $file) { $type = $file->isDir() ? 'dir' : 'file'; $data[] = ['thumbnail' => 'false', 'base64' => 'false', 'type' => $type, 'path' => $this->fileSystem->makePathRelative($file->getRealpath(), $this->root), 'label' => $file->getFilename()]; } return $data; }
protected function doExecute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $output->writeln('To run behat test you must first get selenium :'); $output->writeln('<info>http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar'); $output->writeln('and run it with the following command "java -jar selenium-server-standalone-2.31.0.jar > /dev/null &"'); $output->writeln('Then you must run the following command :'); $relativePath = $fs->makePathRelative(getcwd(), $this->container['root.path'] . '/behat.yml'); $cmd = sprintf('cp %sbehat.yml.dist %sbehat.yml', $relativePath, $relativePath); $output->writeln('<info>' . $cmd . '</info>'); }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $addon_id = $input->getArgument('name'); $abs_cart_path = rtrim(realpath($input->getArgument('cart-directory')), '\\/') . '/'; $this->validateCartPath($abs_cart_path, $input, $output); $abs_addon_path = rtrim(realpath($input->getArgument('addon-directory')), '\\/') . '/'; chdir($abs_addon_path); $addon = new Addon($addon_id, $abs_addon_path); $addon_files_glob_masks = $addon->getFilesGlobMasks(); $addon_files_glob_masks = array_filter($addon_files_glob_masks, function ($glob_mask) { // Always ignore "design/themes/" masks because there shouldn't // be such directory in add-on files directory if (mb_strpos($glob_mask, 'design/themes/') === 0) { return false; } return true; }); $glob_matches = $addon->matchFilesAgainstGlobMasks($addon_files_glob_masks, $abs_addon_path); $output->writeln(sprintf('<fg=magenta;options=bold>Creating symlinks at the "%s" directory:</>', $abs_cart_path)); foreach ($glob_matches as $rel_filepath) { $abs_addon_filepath = $abs_addon_path . $rel_filepath; // Add-on templates at the "var/themes_repository/" directory will be // symlinked to the "design/themes/" directory. if ($input->getOption('templates-to-design') && mb_strpos($rel_filepath, 'var/themes_repository/') === 0) { $abs_cart_filepath = $abs_cart_path . 'design/themes/' . mb_substr($rel_filepath, mb_strlen('var/themes_repository/')); } else { $abs_cart_filepath = $abs_cart_path . $rel_filepath; } // Delete existing files and links located at cart directory clearstatcache(true, $abs_cart_filepath); if (file_exists($abs_cart_filepath)) { $is_link = is_link($abs_cart_filepath); $is_file = $is_link ? is_file(readlink($abs_cart_filepath)) : is_file($abs_cart_filepath); $is_dir = $is_link ? is_dir(readlink($abs_cart_filepath)) : is_dir($abs_cart_filepath); // Confirm overwriting of the found conflicting file or directory on the same path. // We only ask confirmation for files which are not symbolic links, because we assume // that symbolic links were created by this command earlier and can be overwritten without // the loss of any data. if (!$is_link && ($is_file || $is_dir)) { $helper = $this->getHelper('question'); $question = new ConfirmationQuestion(sprintf('<question>%s "%s" already exists. Overwrite? [y/N]:</question> ', $is_dir ? 'Directory' : 'File', $abs_cart_filepath), false); if (!$helper->ask($input, $output, $question)) { continue; } } $fs->remove($abs_cart_filepath); } $symlink_target_filepath = $input->getOption('relative') ? $fs->makePathRelative(dirname($abs_addon_filepath), dirname($abs_cart_filepath)) . basename($abs_cart_filepath) : $abs_addon_filepath; $fs->symlink($symlink_target_filepath, $abs_cart_filepath); $output->writeln(sprintf('Creating symlink for %s... <info>OK</info>', $rel_filepath)); } }
public static function installXhprofGui(CommandEvent $event) { $options = static::getOptions($event); $webDir = $options['symfony-web-dir']; if (!static::hasDirectory($event, 'symfony-web-dir', $webDir, 'install XHProf GUI')) { return; } $rootDir = getcwd(); $originDir = $rootDir . '/vendor/friendsofphp/uprofiler/uprofiler_html'; $fs = new Filesystem(); $symlink = false; if ($options['symfony-assets-install'] == 'symlink' || $options['symfony-assets-install'] == 'relative') { $symlink = true; } $targetDir = $webDir . DIRECTORY_SEPARATOR . 'xhprof'; $event->getIO()->write(sprintf('Installing XHProf GUI into <comment>%s</comment>', $targetDir)); $fs->remove($targetDir); if ($symlink) { if ($options['symfony-assets-install'] == 'relative') { $relativeOriginDir = $fs->makePathRelative($originDir, realpath($webDir)); } else { $relativeOriginDir = $originDir; } try { $fs->symlink($relativeOriginDir, $targetDir); if (!file_exists($targetDir)) { throw new IOException('Symbolic link is broken'); } $event->getIO()->write('XHProf GUI was installed using symbolic links.'); } catch (IOException $e) { $event->getIO()->write('It looks like your system doesn\'t support symbolic links, please change your options accordingly.'); } } else { $fs->mkdir($targetDir, 0755); // We use a custom iterator to ignore VCS files $fs->mirror($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); $patcher = new XhprofPatcher($fs->makePathRelative(realpath($originDir . '/../uprofiler_lib'), realpath($targetDir))); $patcher->patch($targetDir); } }
public function generate($name, array $files_to_include) { // find paths relative to config directory $filesystem = new Filesystem(); $config_include_dir = AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . 'includes'; $relative_file_paths = []; foreach ($files_to_include as $file_to_include) { $relative_path = $filesystem->makePathRelative(dirname($file_to_include), $config_include_dir); $relative_file_paths[] = $relative_path . basename($file_to_include); } $this->twig_renderer->renderToFile(SkeletonFinder::VALIDATION_FILE . '.twig', $this->target_path, ['name' => $name, 'files' => $relative_file_paths]); return $files_to_include; }
/** * Create symlink * * @param string $target Source * @param string $link Destination link * * @return boolean */ public static function symlink($target, $link) { $target1 = $target; if (file_exists($link)) { return false; } $linkDir = dirname($link); $filesystem = new Filesystem(); $filesystem->mkdir($linkDir); $target = realpath($target); $dir = getcwd(); chdir($linkDir); $target = $filesystem->makePathRelative($target, $linkDir); $target = trim($target, "\\/"); $target = str_replace("/", DIRECTORY_SEPARATOR, $target); symlink($target, basename($link)); chdir($dir); return true; }
/** * @return void */ protected function bundlePackage() { $this->getBundlerLogger()->logDebug("compressing files to single file"); $benchmark = new Benchmark(); $benchmark->start(); $fileSystem = new Filesystem(); $content = []; foreach ($this->getIncludes() as $sourceFile) { $sourceFile = realpath($this->getRoot() . '/' . $sourceFile); $destinationFile = realpath($this->getDestinationMax()); $path = $fileSystem->makePathRelative(dirname($sourceFile), dirname($destinationFile)); $path = trim($path, '/'); $css = file_get_contents($sourceFile); $css = $this->changeCssUrls($path, $css); $content[] = $css; $this->getBundlerLogger()->logDebug('- ' . $sourceFile); } $this->compressContent($content); $benchmark->stop(); $this->getBundlerLogger()->logDebug("compressing files to single file in {$benchmark->getTime()} seconds"); }
/** * @param string $origin * @param string $target * @param integer $symlinkMask * * @return integer */ protected function installAsset($origin, $target, $symlinkMask) { if (AssetsInstallerInterface::RELATIVE_SYMLINK === $symlinkMask) { try { $targetDirname = realpath(is_dir($target) ? $target : dirname($target)); $relativeOrigin = rtrim($this->filesystem->makePathRelative($origin, $targetDirname), '/'); $this->doInstallAsset($relativeOrigin, $target, true); return AssetsInstallerInterface::RELATIVE_SYMLINK; } catch (IOException $exception) { // Do nothing, trying to create non-relative symlinks later. } } if (AssetsInstallerInterface::HARD_COPY !== $symlinkMask) { try { $this->doInstallAsset($origin, $target, true); return AssetsInstallerInterface::SYMLINK; } catch (IOException $exception) { // Do nothing, hard copy later. } } $this->doInstallAsset($origin, $target, false); return AssetsInstallerInterface::HARD_COPY; }
/** * @dataProvider providePathsForMakePathRelative */ public function testMakePathRelative($endPath, $startPath, $expectedPath) { $path = $this->filesystem->makePathRelative($endPath, $startPath); $this->assertEquals($expectedPath, $path); }