本文整理汇总了PHP中PhabricatorOwnersPackage::initializeNewPackage方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorOwnersPackage::initializeNewPackage方法的具体用法?PHP PhabricatorOwnersPackage::initializeNewPackage怎么用?PHP PhabricatorOwnersPackage::initializeNewPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorOwnersPackage
的用法示例。
在下文中一共展示了PhabricatorOwnersPackage::initializeNewPackage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testObjectListQuery
public function testObjectListQuery()
{
$user = $this->generateNewTestUser();
$name = $user->getUsername();
$phid = $user->getPHID();
$result = $this->parseObjectList("@{$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList("{$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList("{$name}, {$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList("@{$name}, {$name}");
$this->assertEqual(array($phid), $result);
$result = $this->parseObjectList('');
$this->assertEqual(array(), $result);
$result = $this->parseObjectList("{$name}!", array(), false, array('!'));
$this->assertEqual(array(array('phid' => $phid, 'suffixes' => array('!' => '!'))), $result);
$package = PhabricatorOwnersPackage::initializeNewPackage($user)->setName(pht('Query Test Package'))->save();
$package_phid = $package->getPHID();
$package_mono = $package->getMonogram();
$result = $this->parseObjectList("{$package_mono} Any Ignored Text");
$this->assertEqual(array($package_phid), $result);
$result = $this->parseObjectList("{$package_mono} Any Text, {$name}");
$this->assertEqual(array($package_phid, $phid), $result);
$result = $this->parseObjectList("{$package_mono} Any Text!, {$name}", array(), false, array('!'));
$this->assertEqual(array(array('phid' => $package_phid, 'suffixes' => array('!' => '!')), array('phid' => $phid, 'suffixes' => array())), $result);
// Expect failure when loading a user if objects must be of type "DUCK".
$caught = null;
try {
$result = $this->parseObjectList("{$name}", array('DUCK'));
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertTrue($caught instanceof Exception);
// Expect failure when loading an invalid object.
$caught = null;
try {
$result = $this->parseObjectList('invalid');
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertTrue($caught instanceof Exception);
// Expect failure when loading ANY invalid object, by default.
$caught = null;
try {
$result = $this->parseObjectList("{$name}, invalid");
} catch (Exception $ex) {
$caught = $ex;
}
$this->assertTrue($caught instanceof Exception);
// With partial results, this should load the valid user.
$result = $this->parseObjectList("{$name}, invalid", array(), true);
$this->assertEqual(array($phid), $result);
}
示例2: newEditableObject
protected function newEditableObject()
{
return PhabricatorOwnersPackage::initializeNewPackage($this->getViewer());
}
示例3: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getUser();
$id = $request->getURIData('id');
if ($id) {
$package = id(new PhabricatorOwnersPackageQuery())->setViewer($viewer)->withIDs(array($id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW))->needOwners(true)->executeOne();
if (!$package) {
return new Aphront404Response();
}
$is_new = false;
} else {
$package = PhabricatorOwnersPackage::initializeNewPackage($viewer);
$is_new = true;
}
$e_name = true;
$v_name = $package->getName();
$v_owners = mpull($package->getOwners(), 'getUserPHID');
$v_auditing = $package->getAuditingEnabled();
$v_description = $package->getDescription();
$v_status = $package->getStatus();
$errors = array();
if ($request->isFormPost()) {
$xactions = array();
$v_name = $request->getStr('name');
$v_owners = $request->getArr('owners');
$v_auditing = $request->getStr('auditing') == 'enabled';
$v_description = $request->getStr('description');
$v_status = $request->getStr('status');
$type_name = PhabricatorOwnersPackageTransaction::TYPE_NAME;
$type_owners = PhabricatorOwnersPackageTransaction::TYPE_OWNERS;
$type_auditing = PhabricatorOwnersPackageTransaction::TYPE_AUDITING;
$type_description = PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION;
$type_status = PhabricatorOwnersPackageTransaction::TYPE_STATUS;
$xactions[] = id(new PhabricatorOwnersPackageTransaction())->setTransactionType($type_name)->setNewValue($v_name);
$xactions[] = id(new PhabricatorOwnersPackageTransaction())->setTransactionType($type_owners)->setNewValue($v_owners);
$xactions[] = id(new PhabricatorOwnersPackageTransaction())->setTransactionType($type_auditing)->setNewValue($v_auditing);
$xactions[] = id(new PhabricatorOwnersPackageTransaction())->setTransactionType($type_description)->setNewValue($v_description);
if (!$is_new) {
$xactions[] = id(new PhabricatorOwnersPackageTransaction())->setTransactionType($type_status)->setNewValue($v_status);
}
$editor = id(new PhabricatorOwnersPackageTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true);
try {
$editor->applyTransactions($package, $xactions);
$id = $package->getID();
if ($is_new) {
$next_uri = '/owners/paths/' . $id . '/';
} else {
$next_uri = '/owners/package/' . $id . '/';
}
return id(new AphrontRedirectResponse())->setURI($next_uri);
} catch (AphrontDuplicateKeyQueryException $ex) {
$e_name = pht('Duplicate');
$errors[] = pht('Package name must be unique.');
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
$e_name = $ex->getShortMessage($type_name);
}
}
if ($is_new) {
$cancel_uri = '/owners/';
$title = pht('New Package');
$button_text = pht('Continue');
} else {
$cancel_uri = '/owners/package/' . $package->getID() . '/';
$title = pht('Edit Package');
$button_text = pht('Save Package');
}
$form = id(new AphrontFormView())->setUser($viewer)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setValue($v_name)->setError($e_name))->appendControl(id(new AphrontFormTokenizerControl())->setDatasource(new PhabricatorProjectOrUserDatasource())->setLabel(pht('Owners'))->setName('owners')->setValue($v_owners));
if (!$is_new) {
$form->appendChild(id(new AphrontFormSelectControl())->setLabel(pht('Status'))->setName('status')->setValue($v_status)->setOptions($package->getStatusNameMap()));
}
$form->appendChild(id(new AphrontFormSelectControl())->setName('auditing')->setLabel(pht('Auditing'))->setCaption(pht('With auditing enabled, all future commits that touch ' . 'this package will be reviewed to make sure an owner ' . 'of the package is involved and the commit message has ' . 'a valid revision, reviewed by, and author.'))->setOptions(array('disabled' => pht('Disabled'), 'enabled' => pht('Enabled')))->setValue($v_auditing ? 'enabled' : 'disabled'))->appendChild(id(new PhabricatorRemarkupControl())->setUser($viewer)->setLabel(pht('Description'))->setName('description')->setValue($v_description))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue($button_text));
$form_box = id(new PHUIObjectBoxView())->setHeaderText($title)->setFormErrors($errors)->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
if ($package->getID()) {
$crumbs->addTextCrumb($package->getName(), $this->getApplicationURI('package/' . $package->getID() . '/'));
$crumbs->addTextCrumb(pht('Edit'));
} else {
$crumbs->addTextCrumb(pht('New Package'));
}
return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $title));
}