本文整理汇总了PHP中PhabricatorFile::newFromFileData方法的典型用法代码示例。如果您正苦于以下问题:PHP PhabricatorFile::newFromFileData方法的具体用法?PHP PhabricatorFile::newFromFileData怎么用?PHP PhabricatorFile::newFromFileData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhabricatorFile
的用法示例。
在下文中一共展示了PhabricatorFile::newFromFileData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(ConduitAPIRequest $request)
{
$viewer = $request->getUser();
$file_phid = $request->getValue('filePHID');
$file = $this->loadFileByPHID($viewer, $file_phid);
$start = $request->getValue('byteStart');
$data = $request->getValue('data');
$encoding = $request->getValue('dataEncoding');
switch ($encoding) {
case 'base64':
$data = $this->decodeBase64($data);
break;
case null:
break;
default:
throw new Exception(pht('Unsupported data encoding.'));
}
$length = strlen($data);
$chunk = $this->loadFileChunkForUpload($viewer, $file, $start, $start + $length);
// NOTE: These files have a view policy which prevents normal access. They
// are only accessed through the storage engine.
$chunk_data = PhabricatorFile::newFromFileData($data, array('name' => $file->getMonogram() . '.chunk-' . $chunk->getID(), 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE));
$chunk->setDataFilePHID($chunk_data->getPHID())->save();
$missing = $this->loadAnyMissingChunk($viewer, $file);
if (!$missing) {
$file->setIsPartial(0)->save();
}
return null;
}
示例2: saveFile
public function saveFile($path, $name)
{
$data = $this->readFile($path);
$file = PhabricatorFile::newFromFileData($data, array('name' => $name));
$file->setName($name);
$file->save();
return $file;
}
示例3: execute
protected function execute(ConduitAPIRequest $request)
{
$data = $request->getValue('data_base64');
$name = $request->getValue('name');
$data = base64_decode($data, $strict = true);
$user = $request->getUser();
$file = PhabricatorFile::newFromFileData($data, array('name' => $name, 'authorPHID' => $user->getPHID()));
return $file->getPHID();
}
示例4: generateTestFile
private function generateTestFile(PhabricatorUser $actor)
{
$engine = new PhabricatorTestStorageEngine();
$data = Filesystem::readRandomCharacters(64);
$params = array('name' => 'test.' . $actor->getPHID(), 'viewPolicy' => $actor->getPHID(), 'authorPHID' => $actor->getPHID(), 'storageEngines' => array($engine));
$file = PhabricatorFile::newFromFileData($data, $params);
$file->save();
return $file;
}
示例5: generate
public function generate()
{
$author_phid = $this->loadPhabrictorUserPHID();
$dimension = 1 << rand(5, 12);
$image = id(new PhabricatorLipsumMondrianArtist())->generate($dimension, $dimension);
$file = PhabricatorFile::newFromFileData($image, array('name' => 'rand-' . rand(1000, 9999)));
$file->setAuthorPHID($author_phid);
$file->setMimeType('image/jpeg');
return $file->save();
}
示例6: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$data = file_get_contents('php://input');
$name = $request->getStr('name');
$file = PhabricatorFile::newFromFileData($data, array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID()));
$view = new AphrontAttachedFileView();
$view->setFile($file);
return id(new AphrontAjaxResponse())->setContent(array('id' => $file->getID(), 'phid' => $file->getPHID(), 'html' => $view->render(), 'uri' => $file->getBestURI()));
}
示例7: execute
protected function execute(ConduitAPIRequest $request)
{
$viewer = $request->getUser();
$name = $request->getValue('name');
$can_cdn = $request->getValue('canCDN');
$view_policy = $request->getValue('viewPolicy');
$data = $request->getValue('data_base64');
$data = $this->decodeBase64($data);
$file = PhabricatorFile::newFromFileData($data, array('name' => $name, 'authorPHID' => $viewer->getPHID(), 'viewPolicy' => $view_policy, 'canCDN' => $can_cdn, 'isExplicitUpload' => true));
return $file->getPHID();
}
示例8: handleRequest
public function handleRequest(AphrontRequest $request)
{
$viewer = $request->getViewer();
$color_map = PhabricatorFilesComposeIconBuiltinFile::getAllColors();
$icon_map = $this->getIconMap();
if ($request->isFormPost()) {
$project_phid = $request->getStr('projectPHID');
if ($project_phid) {
$project = id(new PhabricatorProjectQuery())->setViewer($viewer)->withPHIDs(array($project_phid))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne();
if (!$project) {
return new Aphront404Response();
}
}
$icon = $request->getStr('icon');
$color = $request->getStr('color');
$composer = id(new PhabricatorFilesComposeIconBuiltinFile())->setIcon($icon)->setColor($color);
$data = $composer->loadBuiltinFileData();
$file = PhabricatorFile::newFromFileData($data, array('name' => $composer->getBuiltinDisplayName(), 'profile' => true, 'canCDN' => true));
if ($project_phid) {
$edit_uri = '/project/manage/' . $project->getID() . '/';
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())->setTransactionType(PhabricatorProjectTransaction::TYPE_IMAGE)->setNewValue($file->getPHID());
$editor = id(new PhabricatorProjectTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true);
$editor->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri);
} else {
$content = array('phid' => $file->getPHID());
return id(new AphrontAjaxResponse())->setContent($content);
}
}
$value_color = head_key($color_map);
$value_icon = head_key($icon_map);
require_celerity_resource('people-profile-css');
$buttons = array();
foreach ($color_map as $color => $info) {
$quip = idx($info, 'quip');
$buttons[] = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip compose-select-color', 'style' => 'margin: 0 8px 8px 0', 'meta' => array('color' => $color, 'tip' => $quip)), id(new PHUIIconView())->addClass('compose-background-' . $color));
}
$icons = array();
foreach ($icon_map as $icon => $spec) {
$quip = idx($spec, 'quip');
$icons[] = javelin_tag('button', array('class' => 'grey profile-image-button', 'sigil' => 'has-tooltip compose-select-icon', 'style' => 'margin: 0 8px 8px 0', 'meta' => array('icon' => $icon, 'tip' => $quip)), id(new PHUIIconView())->setIcon($icon)->addClass('compose-icon-bg'));
}
$dialog_id = celerity_generate_unique_node_id();
$color_input_id = celerity_generate_unique_node_id();
$icon_input_id = celerity_generate_unique_node_id();
$preview_id = celerity_generate_unique_node_id();
$preview = id(new PHUIIconView())->setID($preview_id)->addClass('compose-background-' . $value_color)->setIcon($value_icon)->addClass('compose-icon-bg');
$color_input = javelin_tag('input', array('type' => 'hidden', 'name' => 'color', 'value' => $value_color, 'id' => $color_input_id));
$icon_input = javelin_tag('input', array('type' => 'hidden', 'name' => 'icon', 'value' => $value_icon, 'id' => $icon_input_id));
Javelin::initBehavior('phabricator-tooltips');
Javelin::initBehavior('icon-composer', array('dialogID' => $dialog_id, 'colorInputID' => $color_input_id, 'iconInputID' => $icon_input_id, 'previewID' => $preview_id, 'defaultColor' => $value_color, 'defaultIcon' => $value_icon));
return $this->newDialog()->setFormID($dialog_id)->setClass('compose-dialog')->setTitle(pht('Compose Image'))->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Choose Background Color')))->appendChild($buttons)->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Choose Icon')))->appendChild($icons)->appendChild(phutil_tag('div', array('class' => 'compose-header'), pht('Preview')))->appendChild($preview)->appendChild($color_input)->appendChild($icon_input)->addCancelButton('/')->addSubmitButton(pht('Save Image'));
}
示例9: generate
public function generate()
{
$authorphid = $this->loadPhabrictorUserPHID();
$language = $this->generateLanguage();
$content = $this->generateContent($language);
$title = $this->generateTitle($language);
$paste_file = PhabricatorFile::newFromFileData($content, array('name' => $title, 'mime-type' => 'text/plain; charset=utf-8', 'authorPHID' => $authorphid));
$policy = $this->generatePolicy();
$filephid = $paste_file->getPHID();
$parentphid = $this->loadPhabrictorPastePHID();
$paste = id(new PhabricatorPaste())->setParentPHID($parentphid)->setAuthorPHID($authorphid)->setTitle($title)->setLanguage($language)->setViewPolicy($policy)->setFilePHID($filephid)->save();
return $paste;
}
示例10: execute
protected function execute(ConduitAPIRequest $request)
{
$data = $request->getValue('data_base64');
$name = $request->getValue('name');
$can_cdn = $request->getValue('canCDN');
$view_policy = $request->getValue('viewPolicy');
$user = $request->getUser();
$data = base64_decode($data, $strict = true);
if (!$view_policy) {
$view_policy = PhabricatorPolicies::getMostOpenPolicy();
}
$file = PhabricatorFile::newFromFileData($data, array('name' => $name, 'authorPHID' => $user->getPHID(), 'viewPolicy' => $view_policy, 'canCDN' => $can_cdn, 'isExplicitUpload' => true));
return $file->getPHID();
}
示例11: execute
protected function execute(ConduitAPIRequest $request)
{
$content = $request->getValue('content');
$title = $request->getValue('title');
$language = $request->getValue('language');
if (!strlen($content)) {
throw new ConduitException('ERR-NO-PASTE');
}
$title = nonempty($title, 'Masterwork From Distant Lands');
$language = nonempty($language, '');
$user = $request->getUser();
$paste_file = PhabricatorFile::newFromFileData($content, array('name' => $title, 'mime-type' => 'text/plain; charset=utf-8', 'authorPHID' => $user->getPHID()));
$paste = new PhabricatorPaste();
$paste->setTitle($title);
$paste->setLanguage($language);
$paste->setFilePHID($paste_file->getPHID());
$paste->setAuthorPHID($user->getPHID());
$paste->save();
return $this->buildPasteInfoDictionary($paste);
}
示例12: testAES256Storage
public function testAES256Storage()
{
$engine = new PhabricatorTestStorageEngine();
$key_name = 'test.abcd';
$key_text = 'abcdefghijklmnopABCDEFGHIJKLMNOP';
PhabricatorKeyring::addKey(array('name' => $key_name, 'type' => 'aes-256-cbc', 'material.base64' => base64_encode($key_text)));
$format = id(new PhabricatorFileAES256StorageFormat())->selectMasterKey($key_name);
$data = 'The cow jumped over the full moon.';
$params = array('name' => 'test.dat', 'storageEngines' => array($engine), 'format' => $format);
$file = PhabricatorFile::newFromFileData($data, $params);
// We should have a file stored as AES256.
$format_key = $format->getStorageFormatKey();
$this->assertEqual($format_key, $file->getStorageFormat());
$this->assertEqual($data, $file->loadFileData());
// The actual raw data in the storage engine should be encrypted. We
// can't really test this, but we can make sure it's not the same as the
// input data.
$raw_data = $engine->readFile($file->getStorageHandle());
$this->assertTrue($data !== $raw_data);
}
示例13: processCreateRequest
private function processCreateRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$fork = $request->getInt('fork');
$error_view = null;
$e_text = true;
$new_paste = new PhabricatorPaste();
$new_paste_text = null;
$new_paste_language = PhabricatorEnv::getEnvConfig('pygments.dropdown-default');
if ($request->isFormPost()) {
$errors = array();
$text = $request->getStr('text');
if (!strlen($text)) {
$e_text = 'Required';
$errors[] = 'The paste may not be blank.';
} else {
$e_text = null;
}
$parent_phid = $request->getStr('parent');
if ($parent_phid) {
$parent = id(new PhabricatorPaste())->loadOneWhere('phid = %s', $parent_phid);
if ($parent) {
$new_paste->setParentPHID($parent->getPHID());
}
}
$title = $request->getStr('title');
$new_paste->setTitle($title);
$new_paste_language = $request->getStr('language');
if (!$errors) {
if ($new_paste_language == 'infer') {
// If it's infer, store an empty string. Otherwise, store the
// language name. We do this so we can refer to 'infer' elsewhere
// in the code (such as default value) while retaining backwards
// compatibility with old posts with no language stored.
$new_paste_language = '';
}
$new_paste->setLanguage($new_paste_language);
$new_paste_file = PhabricatorFile::newFromFileData($text, array('name' => $title, 'mime-type' => 'text/plain; charset=utf-8', 'authorPHID' => $user->getPHID()));
$new_paste->setFilePHID($new_paste_file->getPHID());
$new_paste->setAuthorPHID($user->getPHID());
$new_paste->save();
return id(new AphrontRedirectResponse())->setURI('/P' . $new_paste->getID());
} else {
$error_view = new AphrontErrorView();
$error_view->setErrors($errors);
$error_view->setTitle('A problem has occurred!');
}
} else {
if ($fork) {
$fork_paste = id(new PhabricatorPaste())->load($fork);
if ($fork_paste) {
$new_paste->setTitle('Fork of ' . $fork_paste->getID() . ': ' . $fork_paste->getTitle());
$fork_file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $fork_paste->getFilePHID());
$new_paste_text = $fork_file->loadFileData();
$new_paste_language = nonempty($fork_paste->getLanguage(), 'infer');
$new_paste->setParentPHID($fork_paste->getPHID());
}
}
}
$this->setErrorView($error_view);
$this->setErrorText($e_text);
$this->setPasteText($new_paste_text);
$new_paste->setLanguage($new_paste_language);
$this->setPaste($new_paste);
}
示例14: setDefaultProfilePicture
private function setDefaultProfilePicture(PhabricatorProject $project)
{
if ($project->isMilestone()) {
return;
}
$compose_color = $project->getDisplayIconComposeColor();
$compose_icon = $project->getDisplayIconComposeIcon();
$builtin = id(new PhabricatorFilesComposeIconBuiltinFile())->setColor($compose_color)->setIcon($compose_icon);
$data = $builtin->loadBuiltinFileData();
$file = PhabricatorFile::newFromFileData($data, array('name' => $builtin->getBuiltinDisplayName(), 'profile' => true, 'canCDN' => true));
$project->setProfileImagePHID($file->getPHID())->save();
}
示例15: processRequest
public function processRequest()
{
$request = $this->getRequest();
$user = $request->getUser();
$paste = new PhabricatorPaste();
$error_view = null;
$e_text = true;
$fork = $request->getInt('fork');
$paste_text = null;
$paste_parent = null;
if ($request->isFormPost()) {
$errors = array();
$title = $request->getStr('title');
$paste_language = $request->getStr('language');
$text = $request->getStr('text');
if (!strlen($text)) {
$e_text = 'Required';
$errors[] = 'The paste may not be blank.';
} else {
$e_text = null;
}
$parent = id(new PhabricatorPaste())->loadOneWhere('phid = %s', $request->getStr('parent'));
if ($parent) {
$paste->setParentPHID($parent->getPHID());
}
$paste->setTitle($title);
if (!$errors) {
if ($paste_language == 'infer') {
// If it's infer, store an empty string. Otherwise, store the
// language name. We do this so we can refer to 'infer' elsewhere
// in the code (such as default value) while retaining backwards
// compatibility with old posts with no language stored.
$paste_language = '';
}
$paste->setLanguage($paste_language);
$paste_file = PhabricatorFile::newFromFileData($text, array('name' => $title, 'mime-type' => 'text/plain; charset=utf-8', 'authorPHID' => $user->getPHID()));
$paste->setFilePHID($paste_file->getPHID());
$paste->setAuthorPHID($user->getPHID());
$paste->save();
return id(new AphrontRedirectResponse())->setURI('/P' . $paste->getID());
} else {
$error_view = new AphrontErrorView();
$error_view->setErrors($errors);
$error_view->setTitle('A problem has occurred!');
}
} else {
if ($fork) {
$fork_paste = id(new PhabricatorPaste())->load($fork);
if ($fork_paste) {
$paste->setTitle('Fork of ' . $fork_paste->getID() . ': ' . $fork_paste->getTitle());
$fork_file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $fork_paste->getFilePHID());
$paste_text = $fork_file->loadFileData();
$paste_language = nonempty($fork_paste->getLanguage(), 'infer');
$paste_parent = $fork_paste->getPHID();
}
} else {
$paste_language = PhabricatorEnv::getEnvConfig('pygments.dropdown-default');
}
}
$form = new AphrontFormView();
$available_languages = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
asort($available_languages);
$language_select = id(new AphrontFormSelectControl())->setLabel('Language')->setName('language')->setValue($paste_language)->setOptions($available_languages);
$form->setUser($user)->setAction($request->getRequestURI()->getPath())->addHiddenInput('parent', $paste_parent)->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setValue($paste->getTitle())->setName('title'))->appendChild($language_select)->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Text')->setError($e_text)->setValue($paste_text)->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setName('text'))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/paste/')->setValue('Create Paste'));
$panel = new AphrontPanelView();
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
$panel->setHeader('Create a Paste');
$panel->appendChild($form);
return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Paste Creation', 'tab' => 'create'));
}