/** * Get unique but consistent name * @param string $name * @param string $type * @param integer $index * @param array $content_range * @param string $extension * @return string */ protected function getUniqueFilename($name, $type, $index, $content_range, $extension) { $name = $this->generateRandom() . "." . $extension; while ($this->filesystem->isDir($this->pathresolver->getUploadPath($name))) { $name = $this->generateRandom() . "." . $extension; } $uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1])); while ($this->filesystem->isFile($this->pathresolver->getUploadPath($name))) { if ($uploaded_bytes == $this->filesystem->getFilesize($this->pathresolver->getUploadPath($name))) { break; } $name = $this->generateRandom() . "." . $extension; } return $name; }
function __construct($directory = null) { if (!$directory || !is_dir($directory)) { $this->directory = PathResolver::getInstance()->getTmpDir($this, $directory); } $this->directory = $directory; }
function __construct($customDirectory = null) { if (!$customDirectory) { $customDirectory = PathResolver::getInstance()->getTmpDir($this); } $this->directory = $customDirectory; }
/** * Test for checking the logic of custom realpath() implementation * * @param string $path Given path * @param string $expected Expected path * * @dataProvider realpathExamples */ public function testRealpathWorkingCorrectly($path, $expected) { // Trick to get scheme name and path in one action. If no scheme, then there will be only one part $components = explode('://', $expected, 2); list($pathScheme, $localPath) = isset($components[1]) ? $components : array(null, $components[0]); // resolve path parts (single dot, double dot and double delimiters) $localPath = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $localPath); if ($pathScheme) { $localPath = "{$pathScheme}://{$localPath}"; } $actual = PathResolver::realpath($path); $this->assertEquals($localPath, $actual); }
function make($file) { $cmd = new ShellCommand($this->executable, $this->winDir); $dbc = $this->getDBConnector(); //force,skip possible errors $cmd->addArg(new ShellArg("-f")); $cmd->addArg(new ShellArg('-u', $dbc->getUser())); $cmd->addArg(new ShellArg('--password', $dbc->getPassword(), '=')); $cmd->addArg(new ShellArg('-D', $dbc->getDbName())); $cmd->addArg(new ShellArg('-h', $dbc->getHost())); $cmd->addArg(new ShellArg("-q")); $cmd->addArg(new ShellArg("-s")); $cmd->addArg(new ShellArg(' < ', $file)); $cmd->execute(PathResolver::getInstance()->getLogDir($this, $dbc->getDriver()->getName() . "." . $dbc->getName() . '.log')); }
function make($storeStructure, $storeData) { $cmd = ShellCommand::create($this->executable, $this->winDir); $dbc = $this->getDBConnector(); if ($storeData && !$storeStructure) { $cmd->addArg(ShellArg::create("--data-only")); } if ($storeStructure && !$storeData) { $cmd->addArg(ShellArg::create("--schema-only")); } $cmd->addArg(ShellArg::create("--clean")); //--column-inserts //$cmd->AddArg("-D"); //target file $cmd->addArg(ShellArg::create("-f", $this->getTarget())); //--format=format $cmd->addArg(ShellArg::create('-F', 'p')); $cmd->addArg(ShellArg::create("--no-owner")); $cmd->addArg(ShellArg::create("--no-privileges")); //connection settings if ($dbc->getHost()) { $cmd->addArg(ShellArg::create('-h', $dbc->getHost())); } //dbname $cmd->addArg(ShellArg::create()->setValue($dbc->getDbName())); if (substr(PHP_OS, 0, 3) == 'WIN') { putenv('PGUSER='******'PGPASSWORD='******'env'); $env->addArg(ShellArg::create()->setValue('PGUSER='******'PGPASSWORD='******'.log')); }
function make($file) { $cmd = new ShellCommand($this->executable, $this->winDir); $dbc = $this->getDBConnector(); if ($dbc->getHost()) { $cmd->AddArg("-h", $dbc->getHost()); } $cmd->addArg(new ShellArg($dbc->getDbName())); $cmd->addArg(new ShellArg(' < ', $file)); //we are to use local envvars because our magic dances with proc_open and writing //the password directly to the pipe failed if (substr(PHP_OS, 0, 3) == 'WIN') { putenv('PGUSER='******'PGPASSWORD='******'env'); $env->addArg(ShellArg::create()->setValue('PGUSER='******'PGPASSWORD='******'.log')); }
function execute($logPath = null) { $command = $this->getFullCommand(); $out = shell_exec($command); if (!$logPath) { $logPath = PathResolver::getInstance()->getTmpDir($this, $this->getExecutableName() . '.txt'); } file_put_contents($logPath, $command . PHP_EOL . $out); return $out; }
/** * Return fallback public files directory path. * * This returns the default path of the public files directory. * * @return string * The fallback path to the public files directory of Drupal. */ protected static function publicFilesDirectoryFallback() { return PathResolver::siteDirectory() . '/files'; }
/** * @return string */ private function getCacheFilename() { return PathResolver::getInstance()->getTmpDir($this) . DIRECTORY_SEPARATOR . $this->getCacheId(); }
/** * Creates a temporary directory and returns a direct path to it * @throws FSOperationException * @param string $prefix * @return string */ static function getTempDirectory($prefix = '') { Assert::isScalar($prefix); $directory = PathResolver::getInstance()->getTmpDir($prefix); $attempts = 5; $path = null; do { --$attempts; $path = $directory . DIRECTORY_SEPARATOR . $prefix . microtime(true) . mt_rand(); } while (!mkdir($path, 0700, true) && $attempts > 0 && !usleep(100)); if ($attempts == 0) { throw new FSOperationException("failed to create subdirectory in {$directory}"); } return $path; }
/** * Initializes the autoloader * @return void */ private function initialize() { if ($this->isInitialized) { return; } $this->isInitialized = true; $cacheDirectory = PathResolver::getInstance()->getTmpDir($this); $this->mutexFilename = $cacheDirectory . DIRECTORY_SEPARATOR . $this->getMutexId() . '.mutex'; if (!file_exists($this->mutexFilename)) { file_put_contents($this->mutexFilename, null); } $this->cacheFilename = $cacheDirectory . DIRECTORY_SEPARATOR . 'merged_' . sha1($this->slotId) . '_' . filemtime($this->mutexFilename) . '.php'; return $this; }
/** * Is valid environment? * * @param string $environment * An environment string. * * @return bool * Whether the environment is valid or not. */ public static function isValid($environment) { return $environment && ($environment === static::LOCAL || $environment == static::DEVDESKTOP || file_exists(PathResolver::siteDirectory() . '/settings.' . $environment . '.php')); }
public static function path($path) { return PathResolver::getInstance()->getPath($path); }