本文整理汇总了PHP中Workflow::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Workflow::init方法的具体用法?PHP Workflow::init怎么用?PHP Workflow::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Workflow
的用法示例。
在下文中一共展示了Workflow::init方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public static function run($scope, $query)
{
self::$enterprise = 'enterprise' === $scope;
if (' ' !== $query[0]) {
return '';
}
$query = ltrim($query);
self::$query = $query;
self::$parts = $parts = explode(' ', $query);
Workflow::init(self::$enterprise, $query);
if (Workflow::checkUpdate()) {
self::addUpdateCommands();
return Workflow::getItemsAsXml();
}
if (self::$enterprise && !Workflow::getBaseUrl()) {
self::addEnterpriseUrlCommand();
return Workflow::getItemsAsXml();
}
if (!Workflow::getAccessToken() || !(self::$user = Workflow::requestApi('/user'))) {
self::addLoginCommands();
return Workflow::getItemsAsXml();
}
Workflow::stopServer();
$isSystem = isset($query[0]) && $query[0] == '>';
$isMy = 'my' == $parts[0] && isset($parts[1]);
$isUser = isset($query[0]) && $query[0] == '@';
$isRepo = false;
$queryUser = null;
if ($isUser) {
$queryUser = ltrim($parts[0], '@');
} elseif (($pos = strpos($parts[0], '/')) !== false) {
$queryUser = substr($parts[0], 0, $pos);
$isRepo = true;
}
if ($isSystem) {
self::addSystemCommands();
Workflow::sortItems();
} else {
if ($isMy) {
self::addMyCommands();
} elseif ($isUser && isset($parts[1])) {
self::addUserSubCommands($queryUser);
} elseif (!$isUser && $isRepo && isset($parts[1])) {
self::addRepoSubCommands();
} else {
self::addDefaultCommands($isUser, $isRepo, $queryUser);
}
Workflow::sortItems();
if ($query) {
if (!$isUser && $isRepo && isset($parts[1])) {
$repoQuery = substr($query, strlen($parts[0]) + 1);
Workflow::addItem(Item::create()->title("Search '{$parts['0']}' for '{$repoQuery}'")->icon('search')->arg('/' . $parts[0] . '/search?q=' . urlencode($repoQuery))->autocomplete(false), false);
}
$path = $isUser ? $queryUser : 'search?q=' . urlencode($query);
$name = self::$enterprise ? 'GitHub Enterprise' : 'GitHub';
Workflow::addItem(Item::create()->title("Search {$name} for '{$query}'")->icon('search')->arg('/' . $path)->autocomplete(false), false);
}
}
return Workflow::getItemsAsXml();
}
示例2: run
public static function run($query)
{
self::$query = $query;
self::$parts = $parts = explode(' ', $query);
Workflow::init($query);
if (Workflow::checkUpdate()) {
self::addUpdateCommands();
return Workflow::getItemsAsXml();
}
if (!Workflow::getConfig('access_token') || !(self::$user = Workflow::requestGithubApi('/user'))) {
self::addLoginCommands();
return Workflow::getItemsAsXml();
}
Workflow::stopServer();
$isSystem = isset($query[0]) && $query[0] == '>';
$isMy = 'my' == $parts[0] && isset($parts[1]);
$isUser = isset($query[0]) && $query[0] == '@';
$isRepo = false;
$queryUser = null;
if ($isUser) {
$queryUser = ltrim($parts[0], '@');
} elseif (($pos = strpos($parts[0], '/')) !== false) {
$queryUser = substr($parts[0], 0, $pos);
$isRepo = true;
}
if ($isSystem) {
self::addSystemCommands();
Workflow::sortItems();
} else {
if ($isMy) {
self::addMyCommands();
} elseif ($isUser && isset($parts[1])) {
self::addUserSubCommands($queryUser);
} elseif (!$isUser && $isRepo && isset($parts[1])) {
self::addRepoSubCommands();
} else {
self::addDefaultCommands($isUser, $isRepo, $queryUser);
}
Workflow::sortItems();
if ($query) {
if (!$isUser && $isRepo && isset($parts[1])) {
$repoQuery = substr($query, strlen($parts[0]) + 1);
Workflow::addItem(Item::create()->title("Search '{$parts['0']}' for '{$repoQuery}'")->icon('search')->arg('https://github.com/' . $parts[0] . '/search?q=' . urlencode($repoQuery))->autocomplete(false), false);
}
$path = $isUser ? $queryUser : 'search?q=' . urlencode($query);
Workflow::addItem(Item::create()->title("Search GitHub for '{$query}'")->icon('search')->arg('https://github.com/' . $path)->autocomplete(false), false);
}
}
return Workflow::getItemsAsXml();
}
示例3:
<?php
if (preg_match('/\\.(?:png|jpg|jpeg|gif)$/', $_SERVER['REQUEST_URI'])) {
return false;
}
require 'workflow.php';
Workflow::init();
if (!isset($_GET['access_token'])) {
echo 'FAILURE (missing access_token parameter)!';
exit;
}
Workflow::setConfig('access_token', $_GET['access_token']);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>alfred-github-workflow</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background: #999;
font-family: 'Helvetica Neue', sans-serif;
font-size: 14pt;
}
div {
padding-top: 200px;
width: 450px;
示例4: trim
require 'workflow.php';
$query = trim($argv[1]);
if ('>' !== $query[0] && 0 !== strpos($query, 'e >')) {
if ('.git' == substr($query, -4)) {
$query = 'github-mac://openRepo/' . substr($query, 0, -4);
}
exec('osascript -e "open location \\"' . $query . '\\""');
return;
}
$enterprise = 0 === strpos($query, 'e ');
if ($enterprise) {
$query = substr($query, 2);
}
$parts = explode(' ', $query);
Workflow::init($enterprise);
switch ($parts[1]) {
case 'enterprise-url':
Workflow::setConfig('enterprise_url', rtrim($parts[2], '/'));
exec('osascript -e "tell application \\"Alfred 2\\" to search \\"ghe \\""');
break;
case 'enterprise-reset':
Workflow::removeConfig('enterprise_url');
Workflow::removeConfig('enterprise_access_token');
Workflow::deleteCache();
break;
case 'login':
if (isset($parts[2]) && $parts[2]) {
Workflow::setAccessToken($parts[2]);
echo 'Successfully logged in';
} elseif (!$enterprise) {
示例5: ltrim
<?php
require 'workflow.php';
$query = ltrim($argv[1]);
$parts = explode(' ', $query);
Workflow::init($query);
if (Workflow::checkUpdate()) {
$cmds = array('update' => 'There is an update for this Alfred workflow', 'deactivate autoupdate' => 'Deactivate auto updating this Alfred Workflow');
foreach ($cmds as $cmd => $desc) {
Workflow::addItem(Item::create()->prefix('gh ')->title('> ' . $cmd)->subtitle($desc)->arg('> ' . str_replace(' ', '-', $cmd))->randomUid(), false);
}
print Workflow::getItemsAsXml();
exit;
}
if (!Workflow::getConfig('user') || !($users = Workflow::requestCacheJson('https://github.com/command_bar/users', 'results')) && !Workflow::requestCache('https://github.com/settings/profile')) {
Workflow::removeConfig('user');
$user = null;
if (count($parts) > 1 && $parts[0] == '>' && $parts[1] == 'login' && isset($parts[2])) {
$user = $parts[2];
}
Workflow::addItem(Item::create()->prefix('gh ')->title('> login ' . $user)->subtitle('Log in to GitHub')->arg('> login ' . $user)->valid((bool) $user, '<user>'));
print Workflow::getItemsAsXml();
return;
}
$isSystem = isset($query[0]) && $query[0] == '>';
$isMy = 'my' == $parts[0] && isset($parts[1]);
$isUser = isset($query[0]) && $query[0] == '@';
$isRepo = false;
$queryUser = null;
if ($isUser) {
$queryUser = ltrim($parts[0], '@');