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


PHP phutil_units函数代码示例

本文整理汇总了PHP中phutil_units函数的典型用法代码示例。如果您正苦于以下问题:PHP phutil_units函数的具体用法?PHP phutil_units怎么用?PHP phutil_units使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: execute

 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $since = PhabricatorTime::getNow() - phutil_units('30 days in seconds');
     $until = PhabricatorTime::getNow();
     $mails = id(new PhabricatorMetaMTAMailQuery())->setViewer($viewer)->withDateCreatedBetween($since, $until)->execute();
     $unfiltered = array();
     foreach ($mails as $mail) {
         $unfiltered_actors = mpull($mail->loadAllActors(), 'getPHID');
         foreach ($unfiltered_actors as $phid) {
             if (empty($unfiltered[$phid])) {
                 $unfiltered[$phid] = 0;
             }
             $unfiltered[$phid]++;
         }
     }
     arsort($unfiltered);
     $table = id(new PhutilConsoleTable())->setBorders(true)->addColumn('user', array('title' => pht('User')))->addColumn('unfiltered', array('title' => pht('Unfiltered')));
     $handles = $viewer->loadHandles(array_keys($unfiltered));
     $names = mpull(iterator_to_array($handles), 'getName', 'getPHID');
     foreach ($unfiltered as $phid => $count) {
         $table->addRow(array('user' => idx($names, $phid), 'unfiltered' => $count));
     }
     $table->draw();
     echo "\n";
     echo pht('Mail sent in the last 30 days.') . "\n";
     echo pht('"Unfiltered" is raw volume before preferences were applied.') . "\n";
     echo "\n";
     return 0;
 }
开发者ID:JohnnyEstilles,项目名称:phabricator,代码行数:31,代码来源:PhabricatorMailManagementVolumeWorkflow.php

示例2: renderModuleStatus

 public function renderModuleStatus(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $collectors = PhabricatorGarbageCollector::getAllCollectors();
     $collectors = msort($collectors, 'getCollectorConstant');
     $rows = array();
     $rowc = array();
     foreach ($collectors as $key => $collector) {
         $class = null;
         if ($collector->hasAutomaticPolicy()) {
             $policy_view = phutil_tag('em', array(), pht('Automatic'));
         } else {
             $policy = $collector->getRetentionPolicy();
             if ($policy === null) {
                 $policy_view = pht('Indefinite');
             } else {
                 $days = ceil($policy / phutil_units('1 day in seconds'));
                 $policy_view = pht('%s Day(s)', new PhutilNumber($days));
             }
             $default = $collector->getDefaultRetentionPolicy();
             if ($policy !== $default) {
                 $class = 'highlighted';
                 $policy_view = phutil_tag('strong', array(), $policy_view);
             }
         }
         $rowc[] = $class;
         $rows[] = array($collector->getCollectorConstant(), $collector->getCollectorName(), $policy_view);
     }
     $table = id(new AphrontTableView($rows))->setRowClasses($rowc)->setHeaders(array(pht('Constant'), pht('Name'), pht('Retention Policy')))->setColumnClasses(array(null, 'pri wide', null));
     $header = id(new PHUIHeaderView())->setHeader(pht('Garbage Collectors'))->setSubheader(pht('Collectors with custom policies are highlighted. Use ' . '%s to change retention policies.', phutil_tag('tt', array(), 'bin/garbage set-policy')));
     return id(new PHUIObjectBoxView())->setHeader($header)->setTable($table);
 }
开发者ID:pugong,项目名称:phabricator,代码行数:32,代码来源:PhabricatorConfigCollectorsModule.php

示例3: executeQuery

 protected final function executeQuery()
 {
     $future = $this->newQueryFuture();
     $drequest = $this->getRequest();
     $name = basename($drequest->getPath());
     $ttl = PhabricatorTime::getNow() + phutil_units('48 hours in seconds');
     try {
         $threshold = PhabricatorFileStorageEngine::getChunkThreshold();
         $future->setReadBufferSize($threshold);
         $source = id(new PhabricatorExecFutureFileUploadSource())->setName($name)->setTTL($ttl)->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)->setExecFuture($future);
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         $file = $source->uploadFile();
         unset($unguarded);
     } catch (CommandException $ex) {
         if (!$future->getWasKilledByTimeout()) {
             throw $ex;
         }
         $this->didHitTimeLimit = true;
         $file = null;
     }
     $byte_limit = $this->getByteLimit();
     if ($byte_limit && $file->getByteSize() > $byte_limit) {
         $this->didHitByteLimit = true;
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         id(new PhabricatorDestructionEngine())->destroyObject($file);
         unset($unguarded);
         $file = null;
     }
     return $file;
 }
开发者ID:endlessm,项目名称:phabricator,代码行数:30,代码来源:DiffusionFileFutureQuery.php

示例4: collectGarbage

 public function collectGarbage()
 {
     $ttl = phutil_units('90 days in seconds');
     $table = new MultimeterEvent();
     $conn_w = $table->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE epoch < %d LIMIT 100', $table->getTableName(), PhabricatorTime::getNow() - $ttl);
     return $conn_w->getAffectedRows() == 100;
 }
开发者ID:fengshao0907,项目名称:phabricator,代码行数:8,代码来源:MultimeterEventGarbageCollector.php

示例5: collectGarbage

 public function collectGarbage()
 {
     $ttl = phutil_units('90 days in seconds');
     $table = new PhabricatorMetaMTAMail();
     $conn_w = $table->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', $table->getTableName(), time() - $ttl);
     return $conn_w->getAffectedRows() == 100;
 }
开发者ID:denghp,项目名称:phabricator,代码行数:8,代码来源:MetaMTAMailSentGarbageCollector.php

示例6: collectGarbage

 public function collectGarbage()
 {
     $ttl = phutil_units('3 days in seconds');
     $table = new PhabricatorSystemActionLog();
     $conn_w = $table->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE epoch < %d LIMIT 100', $table->getTableName(), time() - $ttl);
     return $conn_w->getAffectedRows() == 100;
 }
开发者ID:fengshao0907,项目名称:phabricator,代码行数:8,代码来源:PhabricatorSystemActionGarbageCollector.php

示例7: collectGarbage

 public function collectGarbage()
 {
     $ttl = phutil_units('90 days in seconds');
     $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere('dateCreated < %d LIMIT 100', PhabricatorTime::getNow() - $ttl);
     foreach ($mails as $mail) {
         $mail->delete();
     }
     return count($mails) == 100;
 }
开发者ID:fengshao0907,项目名称:phabricator,代码行数:9,代码来源:MetaMTAMailSentGarbageCollector.php

示例8: execute

 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $days = (int) $args->getArg('days');
     if ($days < 1) {
         throw new PhutilArgumentUsageException(pht('Period specified with --days must be at least 1.'));
     }
     $duration = phutil_units("{$days} days in seconds");
     $since = PhabricatorTime::getNow() - $duration;
     $until = PhabricatorTime::getNow();
     $mails = id(new PhabricatorMetaMTAMailQuery())->setViewer($viewer)->withDateCreatedBetween($since, $until)->execute();
     $unfiltered = array();
     $delivered = array();
     foreach ($mails as $mail) {
         // Count messages we attempted to deliver. This includes messages which
         // were voided by preferences or other rules.
         $unfiltered_actors = mpull($mail->loadAllActors(), 'getPHID');
         foreach ($unfiltered_actors as $phid) {
             if (empty($unfiltered[$phid])) {
                 $unfiltered[$phid] = 0;
             }
             $unfiltered[$phid]++;
         }
         // Now, count mail we actually delivered.
         $result = $mail->getDeliveredActors();
         if ($result) {
             foreach ($result as $actor_phid => $actor_info) {
                 if (!$actor_info['deliverable']) {
                     continue;
                 }
                 if (empty($delivered[$actor_phid])) {
                     $delivered[$actor_phid] = 0;
                 }
                 $delivered[$actor_phid]++;
             }
         }
     }
     // Sort users by delivered mail, then unfiltered mail.
     arsort($delivered);
     arsort($unfiltered);
     $delivered = $delivered + array_fill_keys(array_keys($unfiltered), 0);
     $table = id(new PhutilConsoleTable())->setBorders(true)->addColumn('user', array('title' => pht('User')))->addColumn('unfiltered', array('title' => pht('Unfiltered')))->addColumn('delivered', array('title' => pht('Delivered')));
     $handles = $viewer->loadHandles(array_keys($unfiltered));
     $names = mpull(iterator_to_array($handles), 'getName', 'getPHID');
     foreach ($delivered as $phid => $delivered_count) {
         $unfiltered_count = idx($unfiltered, $phid, 0);
         $table->addRow(array('user' => idx($names, $phid), 'unfiltered' => $unfiltered_count, 'delivered' => $delivered_count));
     }
     $table->draw();
     echo "\n";
     echo pht('Mail sent in the last %s day(s).', new PhutilNumber($days)) . "\n";
     echo pht('"Unfiltered" is raw volume before rules applied.') . "\n";
     echo pht('"Delivered" shows email actually sent.') . "\n";
     echo "\n";
     return 0;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:57,代码来源:PhabricatorMailManagementVolumeWorkflow.php

示例9: newHTTPAuthorization

 public static function newHTTPAuthorization(PhabricatorRepository $repository, PhabricatorUser $viewer, $operation)
 {
     $lfs_user = self::HTTP_USERNAME;
     $lfs_pass = Filesystem::readRandomCharacters(32);
     $lfs_hash = PhabricatorHash::digest($lfs_pass);
     $ttl = PhabricatorTime::getNow() + phutil_units('1 day in seconds');
     $token = id(new PhabricatorAuthTemporaryToken())->setTokenResource($repository->getPHID())->setTokenType(self::TOKENTYPE)->setTokenCode($lfs_hash)->setUserPHID($viewer->getPHID())->setTemporaryTokenProperty('lfs.operation', $operation)->setTokenExpires($ttl)->save();
     $authorization_header = base64_encode($lfs_user . ':' . $lfs_pass);
     return 'Basic ' . $authorization_header;
 }
开发者ID:rchicoli,项目名称:phabricator,代码行数:10,代码来源:DiffusionGitLFSTemporaryTokenType.php

示例10: execute

 public function execute(PhutilArgumentParser $args)
 {
     $viewer = $this->getViewer();
     $engine = new PhabricatorCalendarNotificationEngine();
     $minutes = $args->getArg('minutes');
     if ($minutes) {
         $engine->setNotifyWindow(phutil_units("{$minutes} minutes in seconds"));
     }
     $engine->publishNotifications();
     return 0;
 }
开发者ID:NeoArmageddon,项目名称:phabricator,代码行数:11,代码来源:PhabricatorCalendarManagementNotifyWorkflow.php

示例11: testICSDuration

 public function testICSDuration()
 {
     $event = $this->parseICSSingleEvent('duration.ics');
     // Raw value is "20160719T095722Z".
     $start_epoch = strtotime('2016-07-19 09:57:22 UTC');
     $this->assertEqual(1468922242, $start_epoch);
     // Raw value is "P1DT17H4M23S".
     $duration = phutil_units('1 day in seconds') + phutil_units('17 hours in seconds') + phutil_units('4 minutes in seconds') + phutil_units('23 seconds in seconds');
     $this->assertEqual($start_epoch, $event->getStartDateTime()->getEpoch());
     $this->assertEqual($start_epoch + $duration, $event->getEndDateTime()->getEpoch());
 }
开发者ID:endlessm,项目名称:libphutil,代码行数:11,代码来源:PhutilICSParserTestCase.php

示例12: getSessionTypeTTL

 public static function getSessionTypeTTL($session_type)
 {
     switch ($session_type) {
         case self::TYPE_WEB:
             return phutil_units('30 days in seconds');
         case self::TYPE_CONDUIT:
             return phutil_units('24 hours in seconds');
         default:
             throw new Exception(pht('Unknown session type "%s".', $session_type));
     }
 }
开发者ID:pugong,项目名称:phabricator,代码行数:11,代码来源:PhabricatorAuthSession.php

示例13: processAddFactorForm

 public function processAddFactorForm(AphrontFormView $form, AphrontRequest $request, PhabricatorUser $user)
 {
     $totp_token_type = PhabricatorAuthTOTPKeyTemporaryTokenType::TOKENTYPE;
     $key = $request->getStr('totpkey');
     if (strlen($key)) {
         // If the user is providing a key, make sure it's a key we generated.
         // This raises the barrier to theoretical attacks where an attacker might
         // provide a known key (such attacks are already prevented by CSRF, but
         // this is a second barrier to overcome).
         // (We store and verify the hash of the key, not the key itself, to limit
         // how useful the data in the table is to an attacker.)
         $temporary_token = id(new PhabricatorAuthTemporaryTokenQuery())->setViewer($user)->withTokenResources(array($user->getPHID()))->withTokenTypes(array($totp_token_type))->withExpired(false)->withTokenCodes(array(PhabricatorHash::digest($key)))->executeOne();
         if (!$temporary_token) {
             // If we don't have a matching token, regenerate the key below.
             $key = null;
         }
     }
     if (!strlen($key)) {
         $key = self::generateNewTOTPKey();
         // Mark this key as one we generated, so the user is allowed to submit
         // a response for it.
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         id(new PhabricatorAuthTemporaryToken())->setTokenResource($user->getPHID())->setTokenType($totp_token_type)->setTokenExpires(time() + phutil_units('1 hour in seconds'))->setTokenCode(PhabricatorHash::digest($key))->save();
         unset($unguarded);
     }
     $code = $request->getStr('totpcode');
     $e_code = true;
     if ($request->getExists('totp')) {
         $okay = self::verifyTOTPCode($user, new PhutilOpaqueEnvelope($key), $code);
         if ($okay) {
             $config = $this->newConfigForUser($user)->setFactorName(pht('Mobile App (TOTP)'))->setFactorSecret($key);
             return $config;
         } else {
             if (!strlen($code)) {
                 $e_code = pht('Required');
             } else {
                 $e_code = pht('Invalid');
             }
         }
     }
     $form->addHiddenInput('totp', true);
     $form->addHiddenInput('totpkey', $key);
     $form->appendRemarkupInstructions(pht('First, download an authenticator application on your phone. Two ' . 'applications which work well are **Authy** and **Google ' . 'Authenticator**, but any other TOTP application should also work.'));
     $form->appendInstructions(pht('Launch the application on your phone, and add a new entry for ' . 'this Phabricator install. When prompted, scan the QR code or ' . 'manually enter the key shown below into the application.'));
     $prod_uri = new PhutilURI(PhabricatorEnv::getProductionURI('/'));
     $issuer = $prod_uri->getDomain();
     $uri = urisprintf('otpauth://totp/%s:%s?secret=%s&issuer=%s', $issuer, $user->getUsername(), $key, $issuer);
     $qrcode = $this->renderQRCode($uri);
     $form->appendChild($qrcode);
     $form->appendChild(id(new AphrontFormStaticControl())->setLabel(pht('Key'))->setValue(phutil_tag('strong', array(), $key)));
     $form->appendInstructions(pht('(If given an option, select that this key is "Time Based", not ' . '"Counter Based".)'));
     $form->appendInstructions(pht('After entering the key, the application should display a numeric ' . 'code. Enter that code below to confirm that you have configured ' . 'the authenticator correctly:'));
     $form->appendChild(id(new PHUIFormNumberControl())->setLabel(pht('TOTP Code'))->setName('totpcode')->setValue($code)->setError($e_code));
 }
开发者ID:endlessm,项目名称:phabricator,代码行数:54,代码来源:PhabricatorTOTPAuthFactor.php

示例14: newFile

 private function newFile(DiffusionRequest $drequest, $content)
 {
     $path = $drequest->getPath();
     $name = basename($path);
     $repository = $drequest->getRepository();
     $repository_phid = $repository->getPHID();
     $file = PhabricatorFile::buildFromFileDataOrHash($content, array('name' => $name, 'ttl' => time() + phutil_units('48 hours in seconds'), 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE));
     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
     $file->attachToObject($repository_phid);
     unset($unguarded);
     return $file;
 }
开发者ID:modernfactory,项目名称:phabricator,代码行数:12,代码来源:DiffusionFileContentQueryConduitAPIMethod.php

示例15: handleRequest

 public function handleRequest(AphrontRequest $request)
 {
     $show_prototypes = PhabricatorEnv::getEnvConfig('phabricator.show-prototypes');
     if (!$show_prototypes) {
         throw new Exception(pht('Show prototypes is disabled.
       Set `phabricator.show-prototypes` to `true` to use the image proxy'));
     }
     $viewer = $request->getViewer();
     $img_uri = $request->getStr('uri');
     // Validate the URI before doing anything
     PhabricatorEnv::requireValidRemoteURIForLink($img_uri);
     $uri = new PhutilURI($img_uri);
     $proto = $uri->getProtocol();
     if (!in_array($proto, array('http', 'https'))) {
         throw new Exception(pht('The provided image URI must be either http or https'));
     }
     // Check if we already have the specified image URI downloaded
     $cached_request = id(new PhabricatorFileExternalRequest())->loadOneWhere('uriIndex = %s', PhabricatorHash::digestForIndex($img_uri));
     if ($cached_request) {
         return $this->getExternalResponse($cached_request);
     }
     $ttl = PhabricatorTime::getNow() + phutil_units('7 days in seconds');
     $external_request = id(new PhabricatorFileExternalRequest())->setURI($img_uri)->setTTL($ttl);
     $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
     // Cache missed so we'll need to validate and download the image
     try {
         // Rate limit outbound fetches to make this mechanism less useful for
         // scanning networks and ports.
         PhabricatorSystemActionEngine::willTakeAction(array($viewer->getPHID()), new PhabricatorFilesOutboundRequestAction(), 1);
         $file = PhabricatorFile::newFromFileDownload($uri, array('viewPolicy' => PhabricatorPolicies::POLICY_NOONE, 'canCDN' => true));
         if (!$file->isViewableImage()) {
             $mime_type = $file->getMimeType();
             $engine = new PhabricatorDestructionEngine();
             $engine->destroyObject($file);
             $file = null;
             throw new Exception(pht('The URI "%s" does not correspond to a valid image file, got ' . 'a file with MIME type "%s". You must specify the URI of a ' . 'valid image file.', $uri, $mime_type));
         } else {
             $file->save();
         }
         $external_request->setIsSuccessful(true)->setFilePHID($file->getPHID())->save();
         unset($unguarded);
         return $this->getExternalResponse($external_request);
     } catch (HTTPFutureHTTPResponseStatus $status) {
         $external_request->setIsSuccessful(false)->setResponseMessage($status->getMessage())->save();
         return $this->getExternalResponse($external_request);
     } catch (Exception $ex) {
         // Not actually saving the request in this case
         $external_request->setResponseMessage($ex->getMessage());
         return $this->getExternalResponse($external_request);
     }
 }
开发者ID:endlessm,项目名称:phabricator,代码行数:51,代码来源:PhabricatorFileImageProxyController.php


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