code
stringlengths
15
9.96M
docstring
stringlengths
1
10.1k
func_name
stringlengths
1
124
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
6
186
url
stringlengths
50
236
license
stringclasses
4 values
public function withResponsibleUsers(array $responsible_phids) { $this->responsibles = $responsible_phids; return $this; }
Given a set of users, filter results to return only revisions they are responsible for (i.e., they are either authors or reviewers). @param array $responsible_phids List of user PHIDs. @return $this @task config
withResponsibleUsers
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
public function needActiveDiffs($need_active_diffs) { $this->needActiveDiffs = $need_active_diffs; return $this; }
Set whether or not the query should load the active diff for each revision. @param bool $need_active_diffs True to load and attach diffs. @return $this @task config
needActiveDiffs
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
public function needCommitPHIDs($need_commit_phids) { $this->needCommitPHIDs = $need_commit_phids; return $this; }
Set whether or not the query should load the associated commit PHIDs for each revision. @param bool $need_commit_phids True to load and attach diffs. @return $this @task config
needCommitPHIDs
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
public function needDiffIDs($need_diff_ids) { $this->needDiffIDs = $need_diff_ids; return $this; }
Set whether or not the query should load associated diff IDs for each revision. @param bool $need_diff_ids True to load and attach diff IDs. @return $this @task config
needDiffIDs
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
public function needHashes($need_hashes) { $this->needHashes = $need_hashes; return $this; }
Set whether or not the query should load associated commit hashes for each revision. @param bool $need_hashes True to load and attach commit hashes. @return $this @task config
needHashes
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
public function needReviewers($need_reviewers) { $this->needReviewers = $need_reviewers; return $this; }
Set whether or not the query should load associated reviewers. @param bool $need_reviewers True to load and attach reviewers. @return $this @task config
needReviewers
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
public function needReviewerAuthority($need_reviewer_authority) { $this->needReviewerAuthority = $need_reviewer_authority; return $this; }
Request information about the viewer's authority to act on behalf of each reviewer. In particular, they have authority to act on behalf of projects they are a member of. @param bool $need_reviewer_authority True to load and attach authority. @return $this @task config
needReviewerAuthority
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
protected function loadPage() { $data = $this->loadData(); $data = $this->didLoadRawRows($data); $table = $this->newResultObject(); return $table->loadAllFromArray($data); }
Execute the query as configured, returning matching @{class:DifferentialRevision} objects. @return list List of matching DifferentialRevision objects. @task exec
loadPage
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
private function buildJoinsClause(AphrontDatabaseConnection $conn) { $joins = array(); if ($this->paths) { $path_table = new DifferentialAffectedPath(); $joins[] = qsprintf( $conn, 'JOIN %R paths ON paths.revisionID = r.id', $path_table); } if ($this->commitHashes) { $joins[] = qsprintf( $conn, 'JOIN %T hash_rel ON hash_rel.revisionID = r.id', ArcanistDifferentialRevisionHash::TABLE_NAME); } if ($this->ccs) { $joins[] = qsprintf( $conn, 'JOIN %T e_ccs ON e_ccs.src = r.phid '. 'AND e_ccs.type = %s '. 'AND e_ccs.dst in (%Ls)', PhabricatorEdgeConfig::TABLE_NAME_EDGE, PhabricatorObjectHasSubscriberEdgeType::EDGECONST, $this->ccs); } if ($this->reviewers) { $joins[] = qsprintf( $conn, 'LEFT JOIN %T reviewer ON reviewer.revisionPHID = r.phid AND reviewer.reviewerStatus != %s AND reviewer.reviewerPHID in (%Ls)', id(new DifferentialReviewer())->getTableName(), DifferentialReviewerStatus::STATUS_RESIGNED, $this->reviewers); } if ($this->noReviewers) { $joins[] = qsprintf( $conn, 'LEFT JOIN %T no_reviewer ON no_reviewer.revisionPHID = r.phid AND no_reviewer.reviewerStatus != %s', id(new DifferentialReviewer())->getTableName(), DifferentialReviewerStatus::STATUS_RESIGNED); } if ($this->draftAuthors) { $joins[] = qsprintf( $conn, 'JOIN %T has_draft ON has_draft.srcPHID = r.phid AND has_draft.type = %s AND has_draft.dstPHID IN (%Ls)', PhabricatorEdgeConfig::TABLE_NAME_EDGE, PhabricatorObjectHasDraftEdgeType::EDGECONST, $this->draftAuthors); } $joins[] = $this->buildJoinClauseParts($conn); return $this->formatJoinClause($conn, $joins); }
@task internal
buildJoinsClause
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
protected function shouldGroupQueryResultRows() { if ($this->paths) { // (If we have exactly one repository and exactly one path, we don't // technically need to group, but it's simpler to always group.) return true; } if (count($this->ccs) > 1) { return true; } if (count($this->reviewers) > 1) { return true; } if (count($this->commitHashes) > 1) { return true; } if ($this->noReviewers) { return true; } return parent::shouldGroupQueryResultRows(); }
@task internal
shouldGroupQueryResultRows
php
phorgeit/phorge
src/applications/differential/query/DifferentialRevisionQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/query/DifferentialRevisionQuery.php
Apache-2.0
public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; }
@task config
setViewer
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function getViewer() { return $this->viewer; }
@task config
getViewer
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function setCommitMessageFields(array $fields) { assert_instances_of($fields, 'DifferentialCommitMessageField'); $fields = mpull($fields, null, 'getCommitMessageFieldKey'); $this->commitMessageFields = $fields; return $this; }
@task config
setCommitMessageFields
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function getCommitMessageFields() { return $this->commitMessageFields; }
@task config
getCommitMessageFields
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function setRaiseMissingFieldErrors($raise) { $this->raiseMissingFieldErrors = $raise; return $this; }
@task config
setRaiseMissingFieldErrors
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function getRaiseMissingFieldErrors() { return $this->raiseMissingFieldErrors; }
@task config
getRaiseMissingFieldErrors
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function setLabelMap(array $label_map) { $this->labelMap = $label_map; return $this; }
@task config
setLabelMap
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function setTitleKey($title_key) { $this->titleKey = $title_key; return $this; }
@task config
setTitleKey
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function setSummaryKey($summary_key) { $this->summaryKey = $summary_key; return $this; }
@task config
setSummaryKey
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function getErrors() { return $this->errors; }
@task parse
getErrors
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function getTransactions() { return $this->xactions; }
@task parse
getTransactions
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public static function normalizeFieldLabel($label) { return phutil_utf8_strtolower($label); }
@task support
normalizeFieldLabel
php
phorgeit/phorge
src/applications/differential/parser/DifferentialCommitMessageParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialCommitMessageParser.php
Apache-2.0
public function getMap() { return $this->map; }
Get the raw adjustment map.
getMap
php
phorgeit/phorge
src/applications/differential/parser/DifferentialLineAdjustmentMap.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialLineAdjustmentMap.php
Apache-2.0
public function addMapToChain(DifferentialLineAdjustmentMap $map) { if ($this->nextMapInChain) { $this->nextMapInChain->addMapToChain($map); } else { $this->nextMapInChain = $map; } return $this; }
Add a map to the end of the chain. When a line is mapped with @{method:mapLine}, it is mapped through all maps in the chain.
addMapToChain
php
phorgeit/phorge
src/applications/differential/parser/DifferentialLineAdjustmentMap.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialLineAdjustmentMap.php
Apache-2.0
public function mapLine($line, $is_end) { $nmap = $this->getNearestMap(); $deleted = false; $offset = false; if (isset($nmap[$line])) { $line_range = $nmap[$line]; if ($is_end) { $to_line = end($line_range); } else { $to_line = reset($line_range); } if ($to_line <= 0) { // If we're tracing the first line and this block is collapsing, // compute the offset from the top of the block. if (!$is_end && $this->isInverse) { $offset = 1; $cursor = $line - 1; while (isset($nmap[$cursor])) { $prev = $nmap[$cursor]; $prev = reset($prev); if ($prev == $to_line) { $offset++; } else { break; } $cursor--; } } $to_line = -$to_line; if (!$this->isInverse) { $deleted = true; } } $line = $to_line; } else { $line = $line + $this->finalOffset; } if ($this->nextMapInChain) { $chain = $this->nextMapInChain->mapLine($line, $is_end); list($chain_deleted, $chain_offset, $line) = $chain; $deleted = ($deleted || $chain_deleted); if ($chain_offset !== false) { if ($offset === false) { $offset = 0; } $offset += $chain_offset; } } return array($deleted, $offset, $line); }
Map a line across a change, or a series of changes. @param int $line Line to map @param bool $is_end True to map it as the end of a range. @return wild Spooky magic.
mapLine
php
phorgeit/phorge
src/applications/differential/parser/DifferentialLineAdjustmentMap.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialLineAdjustmentMap.php
Apache-2.0
private function buildNearestMap() { $map = $this->map; $nmap = array(); $nearest = 0; foreach ($map as $key => $value) { if ($value) { $nmap[$key] = $value; $nearest = end($value); } else { $nmap[$key][0] = -$nearest; } } if (isset($key)) { $this->finalOffset = ($nearest - $key); } else { $this->finalOffset = 0; } foreach (array_reverse($map, true) as $key => $value) { if ($value) { $nearest = reset($value); } else { $nmap[$key][1] = -$nearest; } } $this->nearestMap = $nmap; return $this; }
Build a derived map which maps deleted lines to the nearest valid line. This computes a "nearest line" map and a final-line offset. These derived maps allow us to map deleted code to the previous (or next) line which actually exists.
buildNearestMap
php
phorgeit/phorge
src/applications/differential/parser/DifferentialLineAdjustmentMap.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialLineAdjustmentMap.php
Apache-2.0
public function getHasAnyChanges() { return $this->getHasChanges('any'); }
Returns true if the hunks change anything, including whitespace.
getHasAnyChanges
php
phorgeit/phorge
src/applications/differential/parser/DifferentialHunkParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialHunkParser.php
Apache-2.0
public function reparseHunksForSpecialAttributes() { $rebuild_old = array(); $rebuild_new = array(); $old_lines = array_reverse($this->getOldLines()); $new_lines = array_reverse($this->getNewLines()); while (count($old_lines) || count($new_lines)) { $old_line_data = array_pop($old_lines); $new_line_data = array_pop($new_lines); if ($old_line_data) { $o_type = $old_line_data['type']; } else { $o_type = null; } if ($new_line_data) { $n_type = $new_line_data['type']; } else { $n_type = null; } // This line does not exist in the new file. if (($o_type != null) && ($n_type == null)) { $rebuild_old[] = $old_line_data; $rebuild_new[] = null; if ($new_line_data) { array_push($new_lines, $new_line_data); } continue; } // This line does not exist in the old file. if (($n_type != null) && ($o_type == null)) { $rebuild_old[] = null; $rebuild_new[] = $new_line_data; if ($old_line_data) { array_push($old_lines, $old_line_data); } continue; } $rebuild_old[] = $old_line_data; $rebuild_new[] = $new_line_data; } $this->setOldLines($rebuild_old); $this->setNewLines($rebuild_new); $this->updateChangeTypesForNormalization(); return $this; }
This function takes advantage of the parsing work done in @{method:parseHunksForLineData} and continues the struggle to hammer this data into something we can display to a user. In particular, this function re-parses the hunks to make them equivalent in length for easy rendering, adding `null` as necessary to pad the length. Anyhoo, this function is not particularly well-named but I try. NOTE: this function must be called after @{method:parseHunksForLineData}.
reparseHunksForSpecialAttributes
php
phorgeit/phorge
src/applications/differential/parser/DifferentialHunkParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialHunkParser.php
Apache-2.0
public function setRightSideCommentMapping($id, $is_new) { $this->rightSideChangesetID = $id; $this->rightSideAttachesToNewFile = $is_new; return $this; }
Configure which Changeset comments added to the right side of the visible diff will be attached to. The ID must be the ID of a real Differential Changeset. The complexity here is that we may show an arbitrary side of an arbitrary changeset as either the left or right part of a diff. This method allows the left and right halves of the displayed diff to be correctly mapped to storage changesets. @param id $id The Differential Changeset ID that comments added to the right side of the visible diff should be attached to. @param bool $is_new If true, attach new comments to the right side of the storage changeset. Note that this may be false, if the left side of some storage changeset is being shown as the right side of a display diff. @return $this
setRightSideCommentMapping
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
public function setLeftSideCommentMapping($id, $is_new) { $this->leftSideChangesetID = $id; $this->leftSideAttachesToNewFile = $is_new; return $this; }
See setRightSideCommentMapping(), but this sets information for the left side of the display diff.
setLeftSideCommentMapping
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
public function setRenderCacheKey($key) { $this->renderCacheKey = $key; return $this; }
Set a key for identifying this changeset in the render cache. If set, the parser will attempt to use the changeset render cache, which can improve performance for frequently-viewed changesets. By default, there is no render cache key and parsers do not use the cache. This is appropriate for rarely-viewed changesets. @param string $key Key for identifying this changeset in the render cache. @return $this
setRenderCacheKey
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
private function calculateGapsAndMask( $mask_force, $feedback_mask, $range_start, $range_len) { $lines_context = $this->getLinesOfContext(); $gaps = array(); $gap_start = 0; $in_gap = false; $base_mask = $this->visible + $mask_force + $feedback_mask; $base_mask[$range_start + $range_len] = true; for ($ii = $range_start; $ii <= $range_start + $range_len; $ii++) { if (isset($base_mask[$ii])) { if ($in_gap) { $gap_length = $ii - $gap_start; if ($gap_length <= $lines_context) { for ($jj = $gap_start; $jj <= $gap_start + $gap_length; $jj++) { $base_mask[$jj] = true; } } else { $gaps[] = array($gap_start, $gap_length); } $in_gap = false; } } else { if (!$in_gap) { $gap_start = $ii; $in_gap = true; } } } $gaps = array_reverse($gaps); $mask = $base_mask; return array($gaps, $mask); }
This function calculates a lot of stuff we need to know to display the diff: Gaps - compute gaps in the visible display diff, where we will render "Show more context" spacers. If a gap is smaller than the context size, we just display it. Otherwise, we record it into $gaps and will render a "show more context" element instead of diff text below. A given $gap is a tuple of $gap_line_number_start and $gap_length. Mask - compute the actual lines that need to be shown (because they are near changes lines, near inline comments, or the request has explicitly asked for them, i.e. resulting from the user clicking "show more"). The $mask returned is a sparsely populated dictionary of $visible_line_number => true. @return array($gaps, $mask)
calculateGapsAndMask
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
private function isCommentVisibleOnRenderedDiff( PhabricatorInlineComment $comment) { $changeset_id = $comment->getChangesetID(); $is_new = $comment->getIsNewFile(); if ($changeset_id == $this->rightSideChangesetID && $is_new == $this->rightSideAttachesToNewFile) { return true; } if ($changeset_id == $this->leftSideChangesetID && $is_new == $this->leftSideAttachesToNewFile) { return true; } return false; }
Determine if an inline comment will appear on the rendered diff, taking into consideration which halves of which changesets will actually be shown. @param PhabricatorInlineComment $comment Comment to test for visibility. @return bool True if the comment is visible on the rendered diff.
isCommentVisibleOnRenderedDiff
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
private function isCommentOnRightSideWhenDisplayed( PhabricatorInlineComment $comment) { if (!$this->isCommentVisibleOnRenderedDiff($comment)) { throw new Exception(pht('Comment is not visible on changeset!')); } $changeset_id = $comment->getChangesetID(); $is_new = $comment->getIsNewFile(); if ($changeset_id == $this->rightSideChangesetID && $is_new == $this->rightSideAttachesToNewFile) { return true; } return false; }
Determine if a comment will appear on the right side of the display diff. Note that the comment must appear somewhere on the rendered changeset, as per isCommentVisibleOnRenderedDiff(). @param PhabricatorInlineComment $comment Comment to test for display location. @return bool True for right, false for left.
isCommentOnRightSideWhenDisplayed
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
public function renderModifiedCoverage() { $na = phutil_tag('em', array(), '-'); $coverage = $this->getCoverage(); if (!$coverage) { return $na; } $covered = 0; $not_covered = 0; foreach ($this->new as $k => $new) { if ($new === null) { continue; } if (!$new['line']) { continue; } if (!$new['type']) { continue; } if (empty($coverage[$new['line'] - 1])) { continue; } switch ($coverage[$new['line'] - 1]) { case 'C': $covered++; break; case 'U': $not_covered++; break; } } if (!$covered && !$not_covered) { return $na; } return sprintf('%d%%', 100 * ($covered / ($covered + $not_covered))); }
Render "modified coverage" information; test coverage on modified lines. This synthesizes diff information with unit test information into a useful indicator of how well tested a change is.
renderModifiedCoverage
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
private function buildLineBackmaps() { $old_back = array(); $new_back = array(); foreach ($this->old as $ii => $old) { if ($old === null) { continue; } $old_back[$old['line']] = $old['line']; } foreach ($this->new as $ii => $new) { if ($new === null) { continue; } $new_back[$new['line']] = $new['line']; } $max_old_line = 0; $max_new_line = 0; foreach ($this->comments as $comment) { if ($this->isCommentOnRightSideWhenDisplayed($comment)) { $max_new_line = max($max_new_line, $comment->getLineNumber()); } else { $max_old_line = max($max_old_line, $comment->getLineNumber()); } } $cursor = 1; for ($ii = 1; $ii <= $max_old_line; $ii++) { if (empty($old_back[$ii])) { $old_back[$ii] = $cursor; } else { $cursor = $old_back[$ii]; } } $cursor = 1; for ($ii = 1; $ii <= $max_new_line; $ii++) { if (empty($new_back[$ii])) { $new_back[$ii] = $cursor; } else { $cursor = $new_back[$ii]; } } return array($old_back, $new_back); }
Build maps from lines comments appear on to actual lines.
buildLineBackmaps
php
phorgeit/phorge
src/applications/differential/parser/DifferentialChangesetParser.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/DifferentialChangesetParser.php
Apache-2.0
private function createSingleChange($old_lines, $new_lines, $changes) { return array( 0 => $this->createHunk(1, $old_lines, 1, $new_lines, $changes), ); }
Returns a change that consists of a single hunk, starting at line 1.
createSingleChange
php
phorgeit/phorge
src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/parser/__tests__/DifferentialHunkParserTestCase.php
Apache-2.0
private function markReviewerComments($object, array $xactions) { $acting_phid = $this->getActingAsPHID(); if (!$acting_phid) { return; } $diff = $this->getActiveDiff($object); if (!$diff) { return; } $has_comment = false; foreach ($xactions as $xaction) { if ($xaction->hasComment()) { $has_comment = true; break; } } if (!$has_comment) { return; } $reviewer_table = new DifferentialReviewer(); $conn = $reviewer_table->establishConnection('w'); queryfx( $conn, 'UPDATE %T SET lastCommentDiffPHID = %s WHERE revisionPHID = %s AND reviewerPHID = %s', $reviewer_table->getTableName(), $diff->getPHID(), $object->getPHID(), $acting_phid); }
When a reviewer makes a comment, mark the last revision they commented on. This allows us to show a hint to help authors and other reviewers quickly distinguish between reviewers who have participated in the discussion and reviewers who haven't been part of it.
markReviewerComments
php
phorgeit/phorge
src/applications/differential/editor/DifferentialTransactionEditor.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/editor/DifferentialTransactionEditor.php
Apache-2.0
protected function validateTransaction( PhabricatorLiskDAO $object, $type, array $xactions) { $errors = parent::validateTransaction($object, $type, $xactions); foreach ($xactions as $xaction) { switch ($type) { case DifferentialDiffTransaction::TYPE_DIFF_CREATE: $diff = clone $object; $diff = $this->updateDiffFromDict($diff, $xaction->getNewValue()); $adapter = $this->buildHeraldAdapter($diff, $xactions); $adapter->setContentSource($this->getContentSource()); $adapter->setIsNewObject($this->getIsNewObject()); $engine = new HeraldEngine(); $rules = $engine->loadRulesForAdapter($adapter); $rules = mpull($rules, null, 'getID'); $effects = $engine->applyRules($rules, $adapter); $action_block = DifferentialBlockHeraldAction::ACTIONCONST; $blocking_effect = null; foreach ($effects as $effect) { if ($effect->getAction() == $action_block) { $blocking_effect = $effect; break; } } if ($blocking_effect) { $rule = $blocking_effect->getRule(); $message = $effect->getTarget(); if (!strlen($message)) { $message = pht('(None.)'); } $errors[] = new PhabricatorApplicationTransactionValidationError( $type, pht('Rejected by Herald'), pht( "Creation of this diff was rejected by Herald rule %s.\n". " Rule: %s\n". "Reason: %s", $rule->getMonogram(), $rule->getName(), $message)); } break; } } return $errors; }
We run Herald as part of transaction validation because Herald can block diff creation for Differential diffs. Its important to do this separately so no Herald logs are saved; these logs could expose information the Herald rules are intended to block.
validateTransaction
php
phorgeit/phorge
src/applications/differential/editor/DifferentialDiffEditor.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/editor/DifferentialDiffEditor.php
Apache-2.0
protected function shouldApplyHeraldRules( PhabricatorLiskDAO $object, array $xactions) { return false; }
See @{method:validateTransaction}. The only Herald action is to block the creation of Diffs. We thus have to be careful not to save any data and do this validation very early.
shouldApplyHeraldRules
php
phorgeit/phorge
src/applications/differential/editor/DifferentialDiffEditor.php
https://github.com/phorgeit/phorge/blob/master/src/applications/differential/editor/DifferentialDiffEditor.php
Apache-2.0
public function getMonograms() { return array(); }
Extensions are allowed to register multi-character monograms. The name "Monogram" is actually a bit of a misnomer, but we're keeping it due to the history. @return array
getMonograms
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
public function isUnlisted() { return false; }
Return `true` if this application should never appear in application lists in the UI. Primarily intended for unit test applications or other pseudo-applications. Few applications should be unlisted. For most applications, use @{method:isLaunchable} to hide them from main launch views instead. @return bool True to remove application from UI lists.
isUnlisted
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
public function isLaunchable() { return true; }
Return `true` if this application is a normal application with a base URI and a web interface. Launchable applications can be pinned to the home page, and show up in the "Launcher" view of the Applications application. Making an application unlaunchable prevents pinning and hides it from this view. Usually, an application should be marked unlaunchable if: - it is available on every page anyway (like search); or - it does not have a web interface (like subscriptions); or - it is still pre-release and being intentionally buried. To hide applications more completely, use @{method:isUnlisted}. @return bool True if the application is launchable.
isLaunchable
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
public function isPinnedByDefault(PhabricatorUser $viewer) { return false; }
Return `true` if this application should be pinned by default. Users who have not yet set preferences see a default list of applications. @param PhabricatorUser $viewer User viewing the pinned application list. @return bool True if this application should be pinned by default.
isPinnedByDefault
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
final public function isFirstParty() { $where = id(new ReflectionClass($this))->getFileName(); $root = phutil_get_library_root('phabricator'); if (!Filesystem::isDescendant($where, $root)) { return false; } if (Filesystem::isDescendant($where, $root.'/extensions')) { return false; } return true; }
Returns true if an application is first-party and false otherwise. @return bool True if this application is first-party.
isFirstParty
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
public function getOverview() { return null; }
Get the Application Overview in raw Remarkup @return string|null
getOverview
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
public function getFlavorText() { return null; }
You can provide an optional piece of flavor text for the application. This is currently rendered in application launch views if the application has no status elements. @return string|null Flavor text. @task ui
getFlavorText
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
public function buildMainMenuItems( PhabricatorUser $user, ?PhabricatorController $controller = null) { return array(); }
Build items for the main menu. @param PhabricatorUser $user The viewing user. @param AphrontController $controller (optional) The current controller. May be null for special pages like 404, exception handlers, etc. @return list<PHUIListItemView> List of menu items. @task ui
buildMainMenuItems
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
final public static function isClassInstalled($class) { return self::getByClass($class)->isInstalled(); }
Determine if an application is installed, by application class name. To check if an application is installed //and// available to a particular viewer, user @{method:isClassInstalledForViewer}. @param string $class Application class name. @return bool True if the class is installed. @task meta
isClassInstalled
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
final public static function isClassInstalledForViewer( $class, PhabricatorUser $viewer) { if ($viewer->isOmnipotent()) { return true; } $cache = PhabricatorCaches::getRequestCache(); $viewer_fragment = $viewer->getCacheFragment(); $key = 'app.'.$class.'.installed.'.$viewer_fragment; $result = $cache->getKey($key); if ($result === null) { if (!self::isClassInstalled($class)) { $result = false; } else { $application = self::getByClass($class); if (!$application->canUninstall()) { // If the application can not be uninstalled, always allow viewers // to see it. In particular, this allows logged-out viewers to see // Settings and load global default settings even if the install // does not allow public viewers. $result = true; } else { $result = PhabricatorPolicyFilter::hasCapability( $viewer, self::getByClass($class), PhabricatorPolicyCapability::CAN_VIEW); } } $cache->setKey($key, $result); } return $result; }
Determine if an application is installed and available to a viewer, by application class name. To check if an application is installed at all, use @{method:isClassInstalled}. @param string $class Application class name. @param PhabricatorUser $viewer Viewing user. @return bool True if the class is installed for the viewer. @task meta
isClassInstalledForViewer
php
phorgeit/phorge
src/applications/base/PhabricatorApplication.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/PhabricatorApplication.php
Apache-2.0
protected function loadViewerHandles(array $phids) { return id(new PhabricatorHandleQuery()) ->setViewer($this->getRequest()->getUser()) ->withPHIDs($phids) ->execute(); }
WARNING: Do not call this in new code. @deprecated See "Handles Technical Documentation".
loadViewerHandles
php
phorgeit/phorge
src/applications/base/controller/PhabricatorController.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/controller/PhabricatorController.php
Apache-2.0
public function newDialog() { $submit_uri = new PhutilURI($this->getRequest()->getRequestURI()); $submit_uri = $submit_uri->getPath(); return id(new AphrontDialogView()) ->setViewer($this->getRequest()->getUser()) ->setSubmitURI($submit_uri); }
Create a new @{class:AphrontDialogView} with defaults filled in. @return AphrontDialogView New dialog.
newDialog
php
phorgeit/phorge
src/applications/base/controller/PhabricatorController.php
https://github.com/phorgeit/phorge/blob/master/src/applications/base/controller/PhabricatorController.php
Apache-2.0
final protected function getAtomSimilarIndex(DivinerAtom $atom) { $atoms = $this->getSimilarAtoms($atom); if (count($atoms) == 1) { return 0; } $index = 1; foreach ($atoms as $similar_atom) { if ($atom === $similar_atom) { return $index; } $index++; } throw new Exception(pht('Expected to find atom while disambiguating!')); }
If a book contains multiple definitions of some atom, like some function `f()`, we assign them an arbitrary (but fairly stable) order and publish them as `function/f/1/`, `function/f/2/`, etc., or similar.
getAtomSimilarIndex
php
phorgeit/phorge
src/applications/diviner/publisher/DivinerPublisher.php
https://github.com/phorgeit/phorge/blob/master/src/applications/diviner/publisher/DivinerPublisher.php
Apache-2.0
public static function getAtomizerVersion() { return 1; }
If you make a significant change to an atomizer, you can bump this version to drop all the old atom caches.
getAtomizerVersion
php
phorgeit/phorge
src/applications/diviner/atomizer/DivinerAtomizer.php
https://github.com/phorgeit/phorge/blob/master/src/applications/diviner/atomizer/DivinerAtomizer.php
Apache-2.0
public function getSortKey() { return implode( "\0", array( $this->getBook(), $this->getType(), $this->getContext(), $this->getName(), $this->getFile(), sprintf('%08d', $this->getLine()), )); }
Returns a sorting key which imposes an unambiguous, stable order on atoms.
getSortKey
php
phorgeit/phorge
src/applications/diviner/atom/DivinerAtom.php
https://github.com/phorgeit/phorge/blob/master/src/applications/diviner/atom/DivinerAtom.php
Apache-2.0
protected function getHashKey($hash) { return implode( '/', array( substr($hash, 0, 2), substr($hash, 2, 2), substr($hash, 4, 8), )); }
Convert a long-form hash key like `ccbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaN` into a shortened directory form, like `cc/bb/aaaaaaaaN`. In conjunction with @{class:PhutilDirectoryKeyValueCache}, this gives us nice directories inside `.divinercache` instead of a million hash files with huge names at the top level.
getHashKey
php
phorgeit/phorge
src/applications/diviner/cache/DivinerDiskCache.php
https://github.com/phorgeit/phorge/blob/master/src/applications/diviner/cache/DivinerDiskCache.php
Apache-2.0
public function withGhosts($ghosts) { $this->isGhost = $ghosts; return $this; }
Include or exclude "ghosts", which are symbols which used to exist but do not exist currently (for example, a function which existed in an older version of the codebase but was deleted). These symbols had PHIDs assigned to them, and may have other sorts of metadata that we don't want to lose (like comments or flags), so we don't delete them outright. They might also come back in the future: the change which deleted the symbol might be reverted, or the documentation might have been generated incorrectly by accident. In these cases, we can restore the original data. @param bool $ghosts @return $this
withGhosts
php
phorgeit/phorge
src/applications/diviner/query/DivinerAtomQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/diviner/query/DivinerAtomQuery.php
Apache-2.0
public function getMarkupFieldKey($field) { $content = $this->getMarkupText($field); return PhabricatorMarkupEngine::digestRemarkupContent($this, $content); }
Markup interface
getMarkupFieldKey
php
phorgeit/phorge
src/applications/ponder/storage/PonderAnswer.php
https://github.com/phorgeit/phorge/blob/master/src/applications/ponder/storage/PonderAnswer.php
Apache-2.0
public function isStatusClosed() { return PonderQuestionStatus::isQuestionStatusClosed($this->status); }
Check whenever this Question has whatever closed status @return bool
isStatusClosed
php
phorgeit/phorge
src/applications/ponder/storage/PonderQuestion.php
https://github.com/phorgeit/phorge/blob/master/src/applications/ponder/storage/PonderQuestion.php
Apache-2.0
public function getMarkupFieldKey($field) { $content = $this->getMarkupText($field); return PhabricatorMarkupEngine::digestRemarkupContent($this, $content); }
Markup interface
getMarkupFieldKey
php
phorgeit/phorge
src/applications/ponder/storage/PonderQuestion.php
https://github.com/phorgeit/phorge/blob/master/src/applications/ponder/storage/PonderQuestion.php
Apache-2.0
public static function isQuestionStatusClosed($status) { return in_array($status, self::getQuestionStatusClosedMap(), true); }
Check whenever a Ponder question status is Closed @param $status string @return bool
isQuestionStatusClosed
php
phorgeit/phorge
src/applications/ponder/constants/PonderQuestionStatus.php
https://github.com/phorgeit/phorge/blob/master/src/applications/ponder/constants/PonderQuestionStatus.php
Apache-2.0
private function setAnswer(PonderAnswer $answer) { $this->answer = $answer; return $this; }
This is used internally on @{method:applyInitialEffects} if a transaction of type PonderQuestionTransaction::TYPE_ANSWERS is in the mix. The value is set to the //last// answer in the transactions. Practically, one answer is given at a time in the application, though theoretically this is buggy. The answer is used in emails to generate proper links.
setAnswer
php
phorgeit/phorge
src/applications/ponder/editor/PonderQuestionEditor.php
https://github.com/phorgeit/phorge/blob/master/src/applications/ponder/editor/PonderQuestionEditor.php
Apache-2.0
public function setEnableAsyncRendering($enable) { $this->enableAsyncRendering = $enable; return $this; }
Allow the engine to render the panel via Ajax.
setEnableAsyncRendering
php
phorgeit/phorge
src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
https://github.com/phorgeit/phorge/blob/master/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
Apache-2.0
private function detectRenderingCycle(PhabricatorDashboardPanel $panel) { if ($this->parentPanelPHIDs === null) { throw new PhutilInvalidStateException('setParentPanelPHIDs'); } $max_depth = 4; if (count($this->parentPanelPHIDs) >= $max_depth) { throw new Exception( pht( 'To render more than %s levels of panels nested inside other '. 'panels, purchase a subscription to %s Gold.', new PhutilNumber($max_depth), PlatformSymbols::getPlatformServerName())); } if (in_array($panel->getPHID(), $this->parentPanelPHIDs)) { throw new Exception( pht( 'You awake in a twisting maze of mirrors, all alike. '. 'You are likely to be eaten by a graph cycle. '. 'Should you escape alive, you resolve to be more careful about '. 'putting dashboard panels inside themselves.')); } }
Detect graph cycles in panels, and deeply nested panels. This method throws if the current rendering stack is too deep or contains a cycle. This can happen if you embed layout panels inside each other, build a big stack of panels, or embed a panel in remarkup inside another panel. Generally, all of this stuff is ridiculous and we just want to shut it down. @param PhabricatorDashboardPanel $panel Panel being rendered. @return void
detectRenderingCycle
php
phorgeit/phorge
src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
https://github.com/phorgeit/phorge/blob/master/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
Apache-2.0
public function shouldRenderAsync() { return true; }
Should this panel pull content in over AJAX? Normally, panels use AJAX to render their content. This makes the page interactable sooner, allows panels to render in parallel, and prevents one slow panel from slowing everything down. However, some panels are very cheap to build (i.e., no expensive service calls or complicated rendering). In these cases overall performance can be improved by disabling async rendering so the panel rendering happens in the same process. @return bool True to enable asynchronous rendering when appropriate.
shouldRenderAsync
php
phorgeit/phorge
src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php
https://github.com/phorgeit/phorge/blob/master/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php
Apache-2.0
public function withArchived($archived) { $this->archived = $archived; return $this; }
Whether to get only the Archived (`true`), only the not Archived (`false`) or all (`null`). Default to `null` (no filter). @param null|bool $archived @return self
withArchived
php
phorgeit/phorge
src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php
Apache-2.0
public function renderCreatePaymentMethodForm( AphrontRequest $request, array $errors) { $ccform = id(new PhortuneCreditCardForm()) ->setSecurityAssurance( pht('This is a test payment provider.')) ->setUser($request->getUser()) ->setErrors($errors); Javelin::initBehavior( 'test-payment-form', array( 'formID' => $ccform->getFormID(), )); return $ccform->buildForm(); }
@task addmethod
renderCreatePaymentMethodForm
php
phorgeit/phorge
src/applications/phortune/provider/PhortuneTestPaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortuneTestPaymentProvider.php
Apache-2.0
public function canCreatePaymentMethods() { return false; }
@task addmethod
canCreatePaymentMethods
php
phorgeit/phorge
src/applications/phortune/provider/PhortunePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortunePaymentProvider.php
Apache-2.0
public function translateCreatePaymentMethodErrorCode($error_code) { throw new PhutilMethodNotImplementedException(); }
@task addmethod
translateCreatePaymentMethodErrorCode
php
phorgeit/phorge
src/applications/phortune/provider/PhortunePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortunePaymentProvider.php
Apache-2.0
public function getCreatePaymentMethodErrorMessage($error_code) { throw new PhutilMethodNotImplementedException(); }
@task addmethod
getCreatePaymentMethodErrorMessage
php
phorgeit/phorge
src/applications/phortune/provider/PhortunePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortunePaymentProvider.php
Apache-2.0
public function validateCreatePaymentMethodToken(array $token) { throw new PhutilMethodNotImplementedException(); }
@task addmethod
validateCreatePaymentMethodToken
php
phorgeit/phorge
src/applications/phortune/provider/PhortunePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortunePaymentProvider.php
Apache-2.0
public function createPaymentMethodFromRequest( AphrontRequest $request, PhortunePaymentMethod $method, array $token) { throw new PhutilMethodNotImplementedException(); }
@task addmethod
createPaymentMethodFromRequest
php
phorgeit/phorge
src/applications/phortune/provider/PhortunePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortunePaymentProvider.php
Apache-2.0
public function renderCreatePaymentMethodForm( AphrontRequest $request, array $errors) { throw new PhutilMethodNotImplementedException(); }
@task addmethod
renderCreatePaymentMethodForm
php
phorgeit/phorge
src/applications/phortune/provider/PhortunePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortunePaymentProvider.php
Apache-2.0
protected function executeCharge( PhortunePaymentMethod $method, PhortuneCharge $charge) { $this->loadStripeAPILibraries(); $price = $charge->getAmountAsCurrency(); $secret_key = $this->getSecretKey(); $params = array( 'amount' => $price->getValueInUSDCents(), 'currency' => $price->getCurrency(), 'customer' => $method->getMetadataValue('stripe.customerID'), 'description' => $charge->getPHID(), 'capture' => true, ); $stripe_charge = Stripe_Charge::create($params, $secret_key); $id = $stripe_charge->id; if (!$id) { throw new Exception(pht('Stripe charge call did not return an ID!')); } $charge->setMetadataValue('stripe.chargeID', $id); $charge->save(); }
@phutil-external-symbol class Stripe_Charge @phutil-external-symbol class Stripe_CardError @phutil-external-symbol class Stripe_Account
executeCharge
php
phorgeit/phorge
src/applications/phortune/provider/PhortuneStripePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortuneStripePaymentProvider.php
Apache-2.0
public function createPaymentMethodFromRequest( AphrontRequest $request, PhortunePaymentMethod $method, array $token) { $this->loadStripeAPILibraries(); $secret_key = $this->getSecretKey(); $stripe_token = $token['stripeCardToken']; // First, make sure the token is valid. $info = id(new Stripe_Token())->retrieve($stripe_token, $secret_key); $account_phid = $method->getAccountPHID(); $author_phid = $method->getAuthorPHID(); $params = array( 'card' => $stripe_token, 'description' => $account_phid.':'.$author_phid, ); // Then, we need to create a Customer in order to be able to charge // the card more than once. We create one Customer for each card; // they do not map to PhortuneAccounts because we allow an account to // have more than one active card. try { $customer = Stripe_Customer::create($params, $secret_key); } catch (Stripe_CardError $ex) { $display_exception = $this->newDisplayExceptionFromCardError($ex); if ($display_exception) { throw $display_exception; } throw $ex; } $card = $info->card; $method ->setBrand($card->brand) ->setLastFourDigits($card->last4) ->setExpires($card->exp_year, $card->exp_month) ->setMetadata( array( 'type' => 'stripe.customer', 'stripe.customerID' => $customer->id, 'stripe.cardToken' => $stripe_token, )); }
@phutil-external-symbol class Stripe_Token @phutil-external-symbol class Stripe_Customer
createPaymentMethodFromRequest
php
phorgeit/phorge
src/applications/phortune/provider/PhortuneStripePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortuneStripePaymentProvider.php
Apache-2.0
public function getCreatePaymentMethodErrorMessage($error_code) { $short_code = $this->getStripeShortErrorCode($error_code); if (!$short_code) { return null; } switch ($short_code) { case 'error:incorrect_number': $error_key = 'number'; $message = pht('Invalid or incorrect credit card number.'); break; case 'error:incorrect_cvc': $error_key = 'cvc'; $message = pht('Card CVC is invalid or incorrect.'); break; $error_key = 'exp'; $message = pht('Card expiration date is invalid or incorrect.'); break; case 'error:invalid_expiry_month': case 'error:invalid_expiry_year': case 'error:invalid_cvc': case 'error:invalid_number': // NOTE: These should be translated into Phortune error codes earlier, // so we don't expect to receive them here. They are listed for clarity // and completeness. If we encounter one, we treat it as an unknown // error. break; case 'error:invalid_amount': case 'error:missing': case 'error:card_declined': case 'error:expired_card': case 'error:duplicate_transaction': case 'error:processing_error': default: // NOTE: These errors currently don't receive a detailed message. // NOTE: We can also end up here with "http:nnn" messages. // TODO: At least some of these should have a better message, or be // translated into common errors above. break; } return null; }
See https://stripe.com/docs/api#errors for more information on possible errors.
getCreatePaymentMethodErrorMessage
php
phorgeit/phorge
src/applications/phortune/provider/PhortuneStripePaymentProvider.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/provider/PhortuneStripePaymentProvider.php
Apache-2.0
public function assertInRange($minimum, $maximum) { if ($minimum !== null && $maximum !== null) { $min = self::newFromString($minimum); $max = self::newFromString($maximum); if ($min->value > $max->value) { throw new Exception( pht( 'Range (%s - %s) is not valid!', $min->formatForDisplay(), $max->formatForDisplay())); } } if ($minimum !== null) { $min = self::newFromString($minimum); if ($min->value > $this->value) { throw new Exception( pht( 'Minimum allowed amount is %s.', $min->formatForDisplay())); } } if ($maximum !== null) { $max = self::newFromString($maximum); if ($max->value < $this->value) { throw new Exception( pht( 'Maximum allowed amount is %s.', $max->formatForDisplay())); } } return $this; }
Assert that a currency value lies within a range. Throws if the value is not between the minimum and maximum, inclusive. In particular, currency values can be negative (to represent a debt or credit), so checking against zero may be useful to make sure a value has the expected sign. @param string|null Currency string, or null to skip check. @param string|null Currency string, or null to skip check. @return $this
assertInRange
php
phorgeit/phorge
src/applications/phortune/currency/PhortuneCurrency.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/currency/PhortuneCurrency.php
Apache-2.0
private function loadSubscription() { $viewer = PhabricatorUser::getOmnipotentUser(); $data = $this->getTaskData(); $subscription_phid = idx($data, 'subscriptionPHID'); $subscription = id(new PhortuneSubscriptionQuery()) ->setViewer($viewer) ->withPHIDs(array($subscription_phid)) ->executeOne(); if (!$subscription) { throw new PhabricatorWorkerPermanentFailureException( pht( 'Failed to load subscription with PHID "%s".', $subscription_phid)); } return $subscription; }
Load the subscription to generate an invoice for. @return PhortuneSubscription The subscription to invoice.
loadSubscription
php
phorgeit/phorge
src/applications/phortune/worker/PhortuneSubscriptionWorker.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/worker/PhortuneSubscriptionWorker.php
Apache-2.0
private function getBillingPeriodRange(PhortuneSubscription $subscription) { $data = $this->getTaskData(); $last_epoch = idx($data, 'trigger.last-epoch'); if (!$last_epoch) { // If this is the first time the subscription is firing, use the // creation date as the start of the billing period. $last_epoch = $subscription->getDateCreated(); } $this_epoch = idx($data, 'trigger.this-epoch'); if (!$last_epoch || !$this_epoch) { throw new PhabricatorWorkerPermanentFailureException( pht('Subscription is missing billing period information.')); } $period_length = ($this_epoch - $last_epoch); if ($period_length <= 0) { throw new PhabricatorWorkerPermanentFailureException( pht( 'Subscription has invalid billing period.')); } if (empty($data['manual'])) { if (PhabricatorTime::getNow() < $this_epoch) { throw new Exception( pht( 'Refusing to generate a subscription invoice for a billing period '. 'which ends in the future.')); } } return array($last_epoch, $this_epoch); }
Get the start and end epoch timestamps for this billing period. @param PhortuneSubscription The subscription being billed. @return pair<int, int> Beginning and end of the billing range.
getBillingPeriodRange
php
phorgeit/phorge
src/applications/phortune/worker/PhortuneSubscriptionWorker.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/worker/PhortuneSubscriptionWorker.php
Apache-2.0
public function withInvoices($invoices) { $this->invoices = $invoices; return $this; }
Include or exclude carts which represent invoices with payments due. @param bool `true` to select invoices; `false` to exclude invoices. @return $this
withInvoices
php
phorgeit/phorge
src/applications/phortune/query/PhortuneCartQuery.php
https://github.com/phorgeit/phorge/blob/master/src/applications/phortune/query/PhortuneCartQuery.php
Apache-2.0
protected function roll($n, $d, $bonus = 0) { $sum = 0; for ($ii = 0; $ii < $n; $ii++) { $sum += mt_rand(1, $d); } $sum += $bonus; return $sum; }
Roll `n` dice with `d` sides each, then add `bonus` and return the sum.
roll
php
phorgeit/phorge
src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
https://github.com/phorgeit/phorge/blob/master/src/applications/lipsum/generator/PhabricatorTestDataGenerator.php
Apache-2.0
public static function saveImageDataInAnyFormat($data, $preferred_mime = '') { $preferred = null; switch ($preferred_mime) { case 'image/gif': $preferred = self::saveImageDataAsGIF($data); break; case 'image/png': $preferred = self::saveImageDataAsPNG($data); break; } if ($preferred !== null) { return $preferred; } $data = self::saveImageDataAsJPG($data); if ($data !== null) { return $data; } $data = self::saveImageDataAsPNG($data); if ($data !== null) { return $data; } $data = self::saveImageDataAsGIF($data); if ($data !== null) { return $data; } throw new Exception(pht('Failed to save image data into any format.')); }
Save an image resource to a string representation suitable for storage or transmission as an image file. Optionally, you can specify a preferred MIME type like `"image/png"`. Generally, you should specify the MIME type of the original file if you're applying file transformations. The MIME type may not be honored if Phabricator can not encode images in the given format (based on available extensions), but can save images in another format. @param resource $data GD image resource. @param string $preferred_mime (optional) Preferred mime type. @return string Bytes of an image file. @task save
saveImageDataInAnyFormat
php
phorgeit/phorge
src/applications/files/PhabricatorImageTransformer.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/PhabricatorImageTransformer.php
Apache-2.0
private static function saveImageDataAsPNG($image) { if (!function_exists('imagepng')) { return null; } // NOTE: Empirically, the highest compression level (9) seems to take // up to twice as long as the default compression level (6) but produce // only slightly smaller files (10% on avatars, 3% on screenshots). ob_start(); $result = imagepng($image, null, 6); $output = ob_get_clean(); if (!$result) { return null; } return $output; }
Save an image in PNG format, returning the file data as a string. @param resource $image GD image resource. @return string|null PNG file as a string, or null on failure. @task save
saveImageDataAsPNG
php
phorgeit/phorge
src/applications/files/PhabricatorImageTransformer.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/PhabricatorImageTransformer.php
Apache-2.0
private static function saveImageDataAsGIF($image) { if (!function_exists('imagegif')) { return null; } ob_start(); $result = imagegif($image); $output = ob_get_clean(); if (!$result) { return null; } return $output; }
Save an image in GIF format, returning the file data as a string. @param resource $image GD image resource. @return string|null GIF file as a string, or null on failure. @task save
saveImageDataAsGIF
php
phorgeit/phorge
src/applications/files/PhabricatorImageTransformer.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/PhabricatorImageTransformer.php
Apache-2.0
private static function saveImageDataAsJPG($image) { if (!function_exists('imagejpeg')) { return null; } ob_start(); $result = imagejpeg($image); $output = ob_get_clean(); if (!$result) { return null; } return $output; }
Save an image in JPG format, returning the file data as a string. @param resource $image GD image resource. @return string|null JPG file as a string, or null on failure. @task save
saveImageDataAsJPG
php
phorgeit/phorge
src/applications/files/PhabricatorImageTransformer.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/PhabricatorImageTransformer.php
Apache-2.0
public function getMonogram() { return 'F'.$this->getID(); }
Get file monogram in the format of "F123" @return string
getMonogram
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function deleteFileDataIfUnused( PhabricatorFileStorageEngine $engine, $engine_identifier, $handle) { // Check to see if any files are using storage. $usage = id(new PhabricatorFile())->loadAllWhere( 'storageEngine = %s AND storageHandle = %s LIMIT 1', $engine_identifier, $handle); // If there are no files using the storage, destroy the actual storage. if (!$usage) { try { $engine->deleteFile($handle); } catch (Exception $ex) { // In the worst case, we're leaving some data stranded in a storage // engine, which is not a big deal. phlog($ex); } } }
Destroy stored file data if there are no remaining files which reference it.
deleteFileDataIfUnused
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function getFileDataIterator($begin = null, $end = null) { $engine = $this->instantiateStorageEngine(); $format = $this->newStorageFormat(); $iterator = $engine->getRawFileDataIterator( $this, $begin, $end, $format); return $iterator; }
Return an iterable which emits file content bytes. @param int $begin (optional) Offset for the start of data. @param int $end (optional) Offset for the end of data. @return Iterable Iterable object which emits requested data.
getFileDataIterator
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function getURI() { return $this->getInfoURI(); }
Get file URI in the format of "/F123" @return string
getURI
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function getViewURI() { if (!$this->getPHID()) { throw new Exception( pht('You must save a file before you can generate a view URI.')); } return $this->getCDNURI('data'); }
Get file view URI in the format of https://phorge.example.com/file/data/foo/PHID-FILE-bar/filename @return string
getViewURI
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function getCDNURI($request_kind) { if (($request_kind !== 'data') && ($request_kind !== 'download')) { throw new Exception( pht( 'Unknown file content request kind "%s".', $request_kind)); } $name = self::normalizeFileName($this->getName()); $name = phutil_escape_uri($name); $parts = array(); $parts[] = 'file'; $parts[] = $request_kind; // If this is an instanced install, add the instance identifier to the URI. // Instanced configurations behind a CDN may not be able to control the // request domain used by the CDN (as with AWS CloudFront). Embedding the // instance identity in the path allows us to distinguish between requests // originating from different instances but served through the same CDN. $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); if (phutil_nonempty_string($instance)) { $parts[] = '@'.$instance; } $parts[] = $this->getSecretKey(); $parts[] = $this->getPHID(); $parts[] = $name; $path = '/'.implode('/', $parts); // If this file is only partially uploaded, we're just going to return a // local URI to make sure that Ajax works, since the page is inevitably // going to give us an error back. if ($this->getIsPartial()) { return PhabricatorEnv::getURI($path); } else { return PhabricatorEnv::getCDNURI($path); } }
Get file view URI in the format of https://phorge.example.com/file/data/foo/PHID-FILE-bar/filename or https://phorge.example.com/file/download/foo/PHID-FILE-bar/filename @return string
getCDNURI
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function getInfoURI() { return '/'.$this->getMonogram(); }
Get file info URI in the format of "/F123" @return string
getInfoURI
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function getDownloadURI() { return $this->getCDNURI('download'); }
Get file view URI in the format of https://phorge.example.com/file/download/foo/PHID-FILE-bar/filename @return string
getDownloadURI
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function isViewableInBrowser() { return ($this->getViewableMimeType() !== null); }
Whether the file can be viewed in a browser @return bool True if MIME type of the file is listed in the files.viewable-mime-types setting
isViewableInBrowser
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function isViewableImage() { if (!$this->isViewableInBrowser()) { return false; } $mime_map = PhabricatorEnv::getEnvConfig('files.image-mime-types'); $mime_type = $this->getMimeType(); return idx($mime_map, $mime_type); }
Whether the file is an image viewable in the browser @return bool True if MIME type of the file is listed in the files.image-mime-types setting and file is viewable in the browser
isViewableImage
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function isAudio() { if (!$this->isViewableInBrowser()) { return false; } $mime_map = PhabricatorEnv::getEnvConfig('files.audio-mime-types'); $mime_type = $this->getMimeType(); return idx($mime_map, $mime_type); }
Whether the file is an audio file @return bool True if MIME type of the file is listed in the files.audio-mime-types setting and file is viewable in the browser
isAudio
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function isVideo() { if (!$this->isViewableInBrowser()) { return false; } $mime_map = PhabricatorEnv::getEnvConfig('files.video-mime-types'); $mime_type = $this->getMimeType(); return idx($mime_map, $mime_type); }
Whether the file is a video file @return bool True if MIME type of the file is listed in the files.video-mime-types setting and file is viewable in the browser
isVideo
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function isPDF() { if (!$this->isViewableInBrowser()) { return false; } $mime_map = array( 'application/pdf' => 'application/pdf', ); $mime_type = $this->getMimeType(); return idx($mime_map, $mime_type); }
Whether the file is a PDF file @return bool True if MIME type of the file is application/pdf and file is viewable in the browser
isPDF
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public function getViewableMimeType() { $mime_map = PhabricatorEnv::getEnvConfig('files.viewable-mime-types'); $mime_type = $this->getMimeType(); $mime_parts = explode(';', $mime_type); $mime_type = trim(reset($mime_parts)); return idx($mime_map, $mime_type); }
Whether the file is listed as a viewable MIME type @return bool True if MIME type of the file is listed in the files.viewable-mime-types setting
getViewableMimeType
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0
public static function loadBuiltin(PhabricatorUser $user, $name) { $builtin = id(new PhabricatorFilesOnDiskBuiltinFile()) ->setName($name); $key = $builtin->getBuiltinFileKey(); return idx(self::loadBuiltins($user, array($builtin)), $key); }
Convenience wrapper for @{method:loadBuiltins}. @param PhabricatorUser $user Viewing user. @param string $name Single builtin name to load. @return PhabricatorFile Corresponding builtin file.
loadBuiltin
php
phorgeit/phorge
src/applications/files/storage/PhabricatorFile.php
https://github.com/phorgeit/phorge/blob/master/src/applications/files/storage/PhabricatorFile.php
Apache-2.0