本文整理汇总了PHP中FileHandler::TempDir方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHandler::TempDir方法的具体用法?PHP FileHandler::TempDir怎么用?PHP FileHandler::TempDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandler
的用法示例。
在下文中一共展示了FileHandler::TempDir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($alias, $operation)
{
$this->log = Logger::getLogger('ProblemDeployer');
$this->alias = $alias;
$this->tmpDir = FileHandler::TempDir('/tmp', 'ProblemDeployer', 0755);
$this->targetDir = PROBLEMS_PATH . DIRECTORY_SEPARATOR . $this->alias;
$this->gitDir = PROBLEMS_GIT_PATH . DIRECTORY_SEPARATOR . $this->alias;
$this->operation = $operation;
if (!is_writable(PROBLEMS_GIT_PATH)) {
$this->log->error('path is not writable:' . PROBLEMS_GIT_PATH);
throw new ProblemDeploymentFailedException();
}
if ($this->operation == ProblemDeployer::CREATE) {
// Atomically try to create the bare repository.
if (!@mkdir($this->gitDir, 0755)) {
throw new InvalidParameterException('aliasInUse');
}
$this->git('init -q --bare ' . escapeshellarg($this->gitDir), PROBLEMS_GIT_PATH);
$this->created = true;
}
// Clone repository into tmp dir
$this->git('clone ' . escapeshellarg($this->gitDir) . ' ' . escapeshellarg($this->tmpDir), '/tmp');
// Ensure .gitattributes flags all inputs/outputs as binaries so it does not
// take several minutes diffing them to save a little space.
if (!file_exists("{$this->tmpDir}/.gitattributes")) {
FileHandler::CreateFile("{$this->tmpDir}/.gitattributes", "cases/in/* -diff -delta -merge -text -crlf\n" . 'cases/out/* -diff -delta -merge -text -crlf');
}
if ($this->operation == ProblemDeployer::UPDATE_CASES) {
$dh = opendir($this->tmpDir);
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..' || $file == '.git' || $file == 'statements' || $file == '.gitattributes') {
continue;
}
$this->git('rm -rf ' . escapeshellarg($file), $this->tmpDir);
}
closedir($dh);
}
}
示例2: elseif
require_once '../../../server/bootstrap.php';
if ($_POST) {
if (!in_array($_POST['language'], array('c', 'cpp', 'java'))) {
$smarty->assign('error', $smarty->getConfigVars('parameterInvalid'));
$smarty->assign('error_field', 'language');
} elseif (!in_array($_POST['os'], array('unix', 'windows'))) {
$smarty->assign('error', $smarty->getConfigVars('parameterInvalid'));
$smarty->assign('error_field', 'os');
} elseif (!preg_match('/^[a-z_][a-z0-9_]{0,31}$/i', $_POST['name'])) {
$smarty->assign('error', $smarty->getConfigVars('parameterInvalid'));
$smarty->assign('error_field', 'name');
} elseif (empty($_POST['idl'])) {
$smarty->assign('error', $smarty->getConfigVars('parameterInvalid'));
$smarty->assign('error_field', 'idl');
} else {
$dirname = FileHandler::TempDir(sys_get_temp_dir(), 'libinteractive');
try {
file_put_contents("{$dirname}/{$_POST['name']}.idl", $_POST['idl']);
$args = array('/usr/bin/java', '-jar', '/opt/omegaup/bin/libinteractive.jar', 'generate', "{$_POST['name']}.idl", $_POST['language'], $_POST['language'], '--makefile', "--{$_POST['os']}");
$descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$cmd = join(' ', array_map('escapeshellarg', $args));
$proc = proc_open($cmd, $descriptorspec, $pipes, $dirname, array('LANG' => 'en_US.UTF-8'));
if (!is_resource($proc)) {
$smarty->assign('error', error_get_last());
} else {
fclose($pipes[0]);
$output = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);
$retval = proc_close($proc);
if ($retval != 0) {
$smarty->assign('error', $output . $err);