本文整理汇总了PHP中coalesce函数的典型用法代码示例。如果您正苦于以下问题:PHP coalesce函数的具体用法?PHP coalesce怎么用?PHP coalesce使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了coalesce函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render($hidden = true)
{
$app = $this->app;
$yaml = $this->yaml;
$html = '';
$filters = coalesce($yaml['filters']);
if (!$filters) {
return '';
}
foreach ($filters as $filter) {
$type = element('type', $filter);
$custom = element('custom', $filter);
$attributes = element('attributes', $filter);
$permission = element('permission', $filter);
if ($permission && !$app['acl']->allow($permission)) {
continue;
}
if ($custom) {
$class = element('class', $custom);
$action = element('action', $custom);
$response = call_user_func_array([$class, $action], [$app]);
$html .= coalesce($response['html']);
} else {
$html .= $this->{$type}($attributes);
}
}
return $html . $this->renderHidden($hidden);
}
示例2: execute
public function execute(PhutilArgumentParser $args)
{
$commits = $this->loadCommits($args, 'commits');
if (!$commits) {
throw new PhutilArgumentUsageException('Specify one or more commits to resolve users for.');
}
$console = PhutilConsole::getConsole();
foreach ($commits as $commit) {
$repo = $commit->getRepository();
$name = $repo->formatCommitName($commit->getCommitIdentifier());
$console->writeOut("%s\n", pht('Examining commit %s...', $name));
$ref = id(new DiffusionLowLevelCommitQuery())->setRepository($repo)->withIdentifier($commit->getCommitIdentifier())->execute();
$author = $ref->getAuthor();
$console->writeOut("%s\n", pht('Raw author string: %s', coalesce($author, 'null')));
if ($author !== null) {
$handle = $this->resolveUser($commit, $author);
if ($handle) {
$console->writeOut("%s\n", pht('Phabricator user: %s', $handle->getFullName()));
} else {
$console->writeOut("%s\n", pht('Unable to resolve a corresponding Phabricator user.'));
}
}
$committer = $ref->getCommitter();
$console->writeOut("%s\n", pht('Raw committer string: %s', coalesce($committer, 'null')));
if ($committer !== null) {
$handle = $this->resolveUser($commit, $committer);
if ($handle) {
$console->writeOut("%s\n", pht('Phabricator user: %s', $handle->getFullName()));
} else {
$console->writeOut("%s\n", pht('Unable to resolve a corresponding Phabricator user.'));
}
}
}
return 0;
}
示例3: view
public function view($idOrNodeName = null)
{
if (!($this->Node = $this->Node->findNode(coalesce($idOrNodeName, @$this->params['name'], @$this->params['id'])))) {
return false;
}
$this->data->set('Node', $this->Node);
// add pagetitle and keywords to metatags
$this->data->set('pageTitle', $this->Node->getText('headline') . ' - ' . AppController::NAME);
if ($tags = $this->Node->getText('tags')) {
$this->AppMetaTags->keywords->prependFromArray(preg_split('/[\\s]+/i', $tags));
}
// check if node has any children
if ($this->Node->level == 2) {
$this->Node->unbind('MediaFile');
$this->Node->bind('FirstImage', 'hasOne', array('class' => 'MediaImage'));
}
// find children of the node
if ($this->Node->hasChildren() && ($ChildNodes = $this->Node->tree(0, 0))) {
$this->data->set('ChildNodes', $ChildNodes);
}
// custom template
if (!$this->Node->isEmpty('template')) {
if ($this->Node->get('template') != 'view') {
return $this->action($this->Node->get('template'), $this->params);
} else {
if ($SubMenu = $this->Node->findByName('Projects')) {
$this->data->set('SubMenu', $SubMenu->tree(1, 0));
}
}
}
return true;
}
示例4: main
protected function main()
{
global $argv;
// get desired job name from console argument list
$jobname = coalesce(@$argv[1], false);
$jobname = preg_replace('@[^A-Z0-9a-z_-]@i', '', $jobname);
if (empty($jobname)) {
$this->console->out('AppConsole');
$this->console->out('----------');
$availableJobs = $this->availableJobs();
if (empty($availableJobs)) {
$this->console->quit('No tasks found.');
}
foreach ($availableJobs as $index => $jobname) {
$this->console->out(sprintf('[%s] %s', str_pad($index + 1, strlen(count($availableJobs)), ' ', STR_PAD_LEFT), $jobname));
}
$result = trim($this->console->read('Please choose job:')) - 1;
if (empty($availableJobs[$result])) {
$this->console->quit('invalid job selected');
}
$jobname = $availableJobs[$result];
}
try {
$task = $this->loadTask($jobname, array_slice($argv, 1));
} catch (AppConsoleControllerTaskNotFoundException $e) {
$this->console->quit(sprintf('Unable to open task "%s"', $jobname));
}
return true;
}
示例5: __construct
/**
* Construct an instance of a StyleConfig.
*
* @param string $name
* @param string $description
* @param null $finder
*/
public function __construct($name = 'chroma', $description = 'Chroma default configuration', $finder = null)
{
parent::__construct($name, $description);
$this->finder = coalesce($finder, $this->makeFinder());
$this->level(FixerInterface::NONE_LEVEL);
$this->fixers(['encoding', 'short_tag', 'braces', 'elseif', 'eof_ending', 'function_call_space', 'function_declaration', 'indentation', 'line_after_namespace', 'linefeed', 'lowercase_constants', 'lowercase_keywords', 'method_argument_space', 'multiple_use', 'parenthesis', 'php_closing_tag', 'trailing_spaces', 'visibility', 'duplicate_semicolon', 'extra_empty_lines', 'multiline_array_trailing_comma', 'new_with_braces', 'object_operator', 'operators_spaces', 'remove_lines_between_uses', 'return', 'single_array_no_trailing_comma', 'spaces_before_semicolon', 'spaces_cast', 'standardize_not_equal', 'ternary_spaces', 'whitespacy_lines', 'concat_with_spaces', 'multiline_spaces_before_semicolon', 'short_array_syntax', 'remove_leading_slash_use', 'phpdoc_order', 'unused_use', 'single_quote', 'single_blank_line_before_namespace', 'spaces_before_semicolon', 'trim_array_spaces', 'phpdoc_var_without_name', 'phpdoc_to_comment', 'phpdoc_short_description', 'phpdoc_scalar', 'phpdoc_no_empty_return', 'phpdoc_no_access', 'no_empty_lines_after_phpdocs', 'no_blank_lines_after_class_opening', 'join_function_fixer', 'blankline_after_open_tag', 'unalign_double_arrow', 'unalign_equals', 'short_echo_tag', 'php4_constructor']);
}
示例6: body
public function body($message = 'No Matching Records Found.')
{
$app = $this->app;
$yaml = $this->yaml;
$records = $this->getRecords();
$datas = [];
foreach ($records as $record) {
$record = (array) $record;
$cnt = 0;
foreach ($yaml['listing'] as $value) {
$body = $value['body'];
$permission = element('permission', $value);
$custom = element('custom', $body);
$row = element('row', $body);
$align = element('align', $body);
$actions = element('actions', $body);
$label = coalesce($record[$row]);
if ($permission && !$app['acl']->allow($permission)) {
continue;
}
if ($custom) {
$class = element('class', $custom);
$action = element('action', $custom);
$label = call_user_func_array([$class, $action], [$app, $record]);
} elseif ($actions) {
$label = $this->renderActions($actions);
}
$temp[$cnt++] = ['row' => $label, 'align' => $align];
}
$datas[] = $temp;
}
return $app['twig']->render('grid/listing/body.html', ['datas' => $datas, 'message' => $message]);
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$class = $input->getArgument('class');
$total = $input->getArgument('total');
$fs = new Filesystem();
$output = Output::style($output);
$filename = getcwd() . "/database/seeds/{$class}.php";
$helper = $this->getHelper('question');
if (!$fs->exists($filename)) {
$output->writeln('<error>The seeder class does not exits.</error>');
return;
}
$output->writeln('<highlight>Running seeder file:</highlight>');
$output->writeln("<info>{$filename}</info>");
$question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (Y/n):</question> ', false);
if (!$helper->ask($input, $output, $question)) {
return;
}
include_once __DIR__ . '/../Factory.php';
include_once __DIR__ . '/../Seeder.php';
include_once $filename;
$instance = new $class();
$instance->inject($output, $this->app, coalesce($total, 1));
$instance->init();
$instance->run();
}
示例8: newFromParts
public static function newFromParts(PhabricatorUser $viewer, $year, $month, $day, $time = null, $enabled = true)
{
$value = new AphrontFormDateControlValue();
$value->viewer = $viewer;
list($value->valueDate, $value->valueTime) = $value->getFormattedDateFromParts($year, $month, $day, coalesce($time, '12:00 AM'));
$value->valueEnabled = $enabled;
return $value;
}
示例9: renderCommitMessageValue
public function renderCommitMessageValue(array $handles)
{
$id = coalesce($this->revisionID, $this->getObject()->getID());
if (!$id) {
return null;
}
return PhabricatorEnv::getProductionURI('/D' . $id);
}
示例10: getFullNameForChangeType
public static function getFullNameForChangeType($type)
{
static $types = null;
if ($types === null) {
$types = array(self::TYPE_ADD => pht('Added'), self::TYPE_CHANGE => pht('Modified'), self::TYPE_DELETE => pht('Deleted'), self::TYPE_MOVE_AWAY => pht('Moved Away'), self::TYPE_COPY_AWAY => pht('Copied Away'), self::TYPE_MOVE_HERE => pht('Moved Here'), self::TYPE_COPY_HERE => pht('Copied Here'), self::TYPE_MULTICOPY => pht('Deleted After Multiple Copy'), self::TYPE_MESSAGE => pht('Commit Message'), self::TYPE_CHILD => pht('Contents Modified'));
}
return idx($types, coalesce($type, '?'), pht('Unknown'));
}
示例11: cp_fetch_site_info
function cp_fetch_site_info($site_id = 0)
{
static $info;
if (!isset($info)) {
$rsSites = CSite::GetByID(coalesce($site_id, SITE_ID));
$info = $rsSites->Fetch();
}
return $info;
}
示例12: __construct
public function __construct($isCritical, $body, array $to = array(), array $from = array(), $subject = NULL, array $files = array())
{
parent::__construct($isCritical);
$this->to = $to ? $to : array(cp_get_site_email());
$this->from = $from ? $from : array("noreply@{$_SERVER['HTTP_HOST']}");
$this->subject = @coalesce($subject, 'Сообщение на ' . $_SERVER['HTTP_HOST']);
$this->body_template = $body;
$this->files = $files;
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/php-mailer/PHPMailerAutoload.php';
$this->mailer = new \PHPMailer();
}
示例13: getText
public function getText($varname, $default = null)
{
$languageId = I18n::locale();
$languageModelName = 'Text' . ucFirst(substr($languageId, 0, 2));
if (!isset($this->{$languageModelName})) {
$languageModelName = 'Text' . ucfirst(substr(Registry::get('I18n.language'), 0, 2));
}
if ($this->{$languageModelName} instanceof Model && $this->{$languageModelName}->hasField($varname)) {
return coalesce($this->{$languageModelName}->get($varname), $default, false);
}
}
示例14: make
public function make()
{
$app = $this->app;
$html = $this->html;
foreach ($this->yaml as $menu) {
if (!isset($menu['submenu'])) {
$html .= $app['twig']->render('menus/parent.html', ['title' => coalesce($menu['title']), 'url' => coalesce($menu['url']), 'icon' => coalesce($menu['icon'])]);
} else {
$html .= $app['twig']->render('menus/child.html', ['title' => coalesce($menu['title']), 'icon' => coalesce($menu['icon']), 'submenu' => coalesce($menu['submenu'])]);
}
}
$this->html = $html;
}
示例15: translateString
function translateString($originalString)
{
$langCode = coalesce(@$GLOBALS['SETTINGS']['language'], 'en');
if (!$langCode && !$GLOBALS['SETTINGS']['advanced']['languageDeveloperMode']) {
return $originalString;
}
// skip if no language defined
static $translation = array();
// get language dirs
list($defaultLangDir, $adminLangDir, $pluginLangDir) = _languageFiles_getDirs();
$isAdminMenu = in_array(@$_REQUEST['menu'], array('admin', 'database', '_codeGenerator'));
if ($pluginLangDir) {
$tryDirs = array($pluginLangDir, $adminLangDir, $defaultLangDir);
} elseif ($isAdminMenu) {
$tryDirs = array($adminLangDir, $defaultLangDir);
} else {
$tryDirs = array($defaultLangDir);
}
$targetLangDir = $tryDirs[0];
// first dir to try and where language strings are added
// load/cache language file and return translation
$langFile = "{$langCode}.php";
foreach ($tryDirs as $thisDir) {
$thisFilepath = "{$thisDir}/{$langFile}";
// load/cache file
if (!array_key_exists($thisFilepath, $translation)) {
$translation[$thisFilepath] = _languageFile_load($thisFilepath);
}
// load string
if (array_key_exists($originalString, $translation[$thisFilepath])) {
// return translation
$string = $translation[$thisFilepath][$originalString];
if ($langCode == 'd|e|b|u|g') {
$string = preg_replace("/(?<=\\w)(\\w)/", "|\\1", $string);
}
// added in v2.50
return $langCode ? $string : $originalString;
// v2.53 - if 'default' language selected, return original text here if translation found. If no translation found, return original string below so string can be added to files.
}
}
// if not found, add string if in developer mode and return original
if ($GLOBALS['SETTINGS']['advanced']['languageDeveloperMode']) {
_languageFiles_addString($defaultLangDir, $targetLangDir, $originalString);
}
if ($langCode == 'd|e|b|u|g') {
$originalString = preg_replace("/(?<=\\w)(\\w)/", "|\\1", $originalString);
}
// added in v2.50
return $originalString;
}