当前位置: 首页>>代码示例>>PHP>>正文


PHP FileHandler::CreateFile方法代码示例

本文整理汇总了PHP中FileHandler::CreateFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHandler::CreateFile方法的具体用法?PHP FileHandler::CreateFile怎么用?PHP FileHandler::CreateFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileHandler的用法示例。


在下文中一共展示了FileHandler::CreateFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: apiCreate

 /**
  * Create a new run
  *
  * @param Request $r
  * @return array
  * @throws Exception
  * @throws InvalidDatabaseOperationException
  * @throws InvalidFilesystemOperationException
  */
 public static function apiCreate(Request $r)
 {
     // Init
     self::initializeGrader();
     // Authenticate user
     self::authenticateRequest($r);
     // Validate request
     self::validateCreateRequest($r);
     self::$log->info('New run being submitted!!');
     $response = array();
     if (self::$practice) {
         if (OMEGAUP_LOCKDOWN) {
             throw new ForbiddenAccessException('lockdown');
         }
         $submit_delay = 0;
         $contest_id = null;
         $test = 0;
     } else {
         //check the kind of penalty_type for this contest
         $penalty_type = $r['contest']->penalty_type;
         switch ($penalty_type) {
             case 'contest_start':
                 // submit_delay is calculated from the start
                 // of the contest
                 $start = $r['contest']->getStartTime();
                 break;
             case 'problem_open':
                 // submit delay is calculated from the
                 // time the user opened the problem
                 $opened = ContestProblemOpenedDAO::getByPK($r['contest']->getContestId(), $r['problem']->getProblemId(), $r['current_user_id']);
                 if (is_null($opened)) {
                     //holy moly, he is submitting a run
                     //and he hasnt even opened the problem
                     //what should be done here?
                     throw new NotAllowedToSubmitException('runEvenOpened');
                 }
                 $start = $opened->getOpenTime();
                 break;
             case 'none':
             case 'runtime':
                 //we dont care
                 $start = null;
                 break;
             default:
                 self::$log->error('penalty_type for this contests is not a valid option, asuming `none`.');
                 $start = null;
         }
         if (!is_null($start)) {
             //ok, what time is it now?
             $c_time = time();
             $start = strtotime($start);
             //asuming submit_delay is in minutes
             $submit_delay = (int) (($c_time - $start) / 60);
         } else {
             $submit_delay = 0;
         }
         $contest_id = $r['contest']->getContestId();
         $test = Authorization::IsContestAdmin($r['current_user_id'], $r['contest']) ? 1 : 0;
     }
     // Populate new run object
     $run = new Runs(array('user_id' => $r['current_user_id'], 'problem_id' => $r['problem']->getProblemId(), 'contest_id' => $contest_id, 'language' => $r['language'], 'source' => $r['source'], 'status' => 'new', 'runtime' => 0, 'penalty' => $submit_delay, 'memory' => 0, 'score' => 0, 'contest_score' => $contest_id != null ? 0 : null, 'submit_delay' => $submit_delay, 'guid' => md5(uniqid(rand(), true)), 'verdict' => 'JE', 'test' => $test));
     try {
         // Push run into DB
         RunsDAO::save($run);
         SubmissionLogDAO::save(new SubmissionLog(array('user_id' => $run->user_id, 'run_id' => $run->run_id, 'contest_id' => $run->contest_id, 'ip' => ip2long($_SERVER['REMOTE_ADDR']))));
         // Update submissions counter++
         $r['problem']->setSubmissions($r['problem']->getSubmissions() + 1);
         ProblemsDAO::save($r['problem']);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     try {
         // Create file for the run
         $filepath = RunController::getSubmissionPath($run);
         FileHandler::CreateFile($filepath, $r['source']);
     } catch (Exception $e) {
         throw new InvalidFilesystemOperationException($e);
     }
     // Call Grader
     try {
         self::$grader->Grade([$run->guid], false, false);
     } catch (Exception $e) {
         self::$log->error('Call to Grader::grade() failed:');
         self::$log->error($e);
     }
     if (self::$practice) {
         $response['submission_deadline'] = 0;
     } else {
         // Add remaining time to the response
         try {
//.........这里部分代码省略.........
开发者ID:andreasantillana,项目名称:omegaup,代码行数:101,代码来源:RunController.php

示例2: HTMLizeStatement

 /**
  * Given the $lang.markdown contents, deploys the .markdown file and creates the .html file
  *
  * @param string $problemBasePath
  * @param string $statementFileName
  * @param string $lang The 2-letter code for the language
  */
 private function HTMLizeStatement($problemBasePath, $statementFileName)
 {
     $this->log->info('HTMLizing statement: ' . $statementFileName);
     // Path used to deploy the raw problem statement (.markdown)
     $markdown_filepath = "{$problemBasePath}/statements/{$statementFileName}";
     // Get the language of this statement
     $lang = basename($statementFileName, '.markdown');
     // Fix for Windows Latin-1 statements:
     // For now, assume that if it is not UTF-8, then it is Windows Latin-1 and then convert
     if (!mb_check_encoding($this->current_markdown_file_contents, 'UTF-8')) {
         $this->log->info('File is not UTF-8.');
         // Convert from ISO-8859-1 (Windows Latin1) to UTF-8
         $this->log->info('Converting encoding from ISO-8859-1 to UTF-8 (Windows Latin1 to UTF-8, fixing accents)');
         $this->current_markdown_file_contents = mb_convert_encoding($this->current_markdown_file_contents, 'UTF-8', 'ISO-8859-1');
     } else {
         $this->log->info('File is UTF-8. Nice :)');
     }
     // Transform markdown to HTML and sync img paths between Markdown and HTML
     $this->log->info('Transforming markdown to html');
     $this->currentLanguage = $lang;
     $html_file_contents = Markdown($this->current_markdown_file_contents, array($this, 'imageMarkdownCallback'), array($this, 'translationCallback'));
     // Then save the changes to the markdown file
     $this->log->info('Saving markdown after Markdown-HTML img path sync: ' . $markdown_filepath);
     FileHandler::CreateFile($markdown_filepath, $this->current_markdown_file_contents);
     // Save the HTML file in the path .../problem_alias/statements/lang.html
     $html_filepath = "{$problemBasePath}/statements/{$lang}.html";
     $this->log->info('Saving HTML statement in ' . $html_filepath);
     FileHandler::CreateFile($html_filepath, $html_file_contents);
 }
开发者ID:RicardoMelgoza,项目名称:omegaup,代码行数:36,代码来源:ProblemDeployer.php


注:本文中的FileHandler::CreateFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。