本文整理汇总了PHP中Terminus\Session::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getUser方法的具体用法?PHP Session::getUser怎么用?PHP Session::getUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terminus\Session
的用法示例。
在下文中一共展示了Session::getUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Object constructor
*
* @param array $options Options to set as $this->key
*/
public function __construct($options = array())
{
parent::__construct($options);
if (!isset($this->user)) {
$this->user = Session::getUser();
}
}
示例2: delete
/**
* Delete a machine token from your account
*
* ## OPTIONS
* [--machine-token-id=<id>]
* : UUID or name of the site you want to delete
*
* [--force]
* : to skip the confirmations
*/
public function delete($args, $assoc_args)
{
$user = Session::getUser();
$id = $assoc_args['machine-token-id'];
if (empty($id)) {
$this->failure('You must specify a machine token id to delete.');
}
// Find the token
$machine_token = $user->machine_tokens->get($assoc_args['machine-token-id']);
if (empty($machine_token)) {
$this->failure('There are no machine tokens with the id {id}.', array('id' => $id));
}
$name = $machine_token->get('device_name');
if (!isset($assoc_args['force']) && !Terminus::getConfig('yes')) {
//If the force option isn't used, we'll ask you some annoying questions
Input::confirm(array('message' => 'Are you sure you want to delete %s?', 'context' => $name));
}
$this->log()->info('Deleting {name} ...', array('name' => $name));
$response = $machine_token->delete();
if ($response['status_code'] == 200) {
$this->log()->info('Deleted {name}!', array('name' => $name));
} else {
$this->failure('There was an problem deleting the machine token.');
}
}
示例3: aliases
/**
* Print and save drush aliases
*
* ## OPTIONS
*
* [--print]
* : print aliases to screen
*
* [--location=<location>]
* : Specify the the full path, including the filename, to the alias file
* you wish to create. Without this option a default of
* '~/.drush/pantheon.aliases.drushrc.php' will be used.
*/
public function aliases($args, $assoc_args)
{
$user = Session::getUser();
$print = $this->input()->optional(array('key' => 'print', 'choices' => $assoc_args, 'default' => false));
$location = $this->input()->optional(array('key' => 'location', 'choices' => $assoc_args, 'default' => getenv('HOME') . '/.drush/pantheon.aliases.drushrc.php'));
if (is_dir($location)) {
$message = 'Please provide a full path with filename,';
$message .= ' e.g. {location}/pantheon.aliases.drushrc.php';
$this->failure($message, compact('location'));
}
$file_exists = file_exists($location);
// Create the directory if it doesn't yet exist
$dirname = dirname($location);
if (!is_dir($dirname)) {
mkdir($dirname, 0700, true);
}
$content = $user->getAliases();
$h = fopen($location, 'w+');
fwrite($h, $content);
fclose($h);
chmod($location, 0700);
$message = 'Pantheon aliases created';
if ($file_exists) {
$message = 'Pantheon aliases updated';
}
if (strpos($content, 'array') === false) {
$message .= ', although you have no sites';
}
$this->log()->info($message);
if ($print) {
$aliases = str_replace(array('<?php', '?>'), '', $content);
$this->output()->outputDump($aliases);
}
}
示例4: all
/**
* Show a list of your instruments on Pantheon
*
* @subcommand list
*/
public function all($args, $assoc_args)
{
$user = Session::getUser();
$instruments = $user->instruments->all();
$data = array();
foreach ($instruments as $id => $instrument) {
$data[] = array('label' => $instrument->get('label'), 'id' => $instrument->get('id'));
}
$this->output()->outputRecordList($data);
}
示例5: console
/**
* Instantiate a console within Terminus
*
* ## OPTIONS
*
* [--site=<site>]
* : name of site to load
*
* @subcommand console
*/
public function console($args, $assoc_args)
{
$user = Session::getUser();
if (isset($assoc_args['site'])) {
$sitename = $assoc_args['site'];
$site_id = $this->sitesCache->findId($sitename);
$site = new Site($site_id);
}
eval(\Psy\sh());
}
示例6: __construct
/**
* Object constructor
*
* @param object $attributes Attributes of this model
* @param array $options Options to set as $this->key
*/
public function __construct($attributes = null, array $options = array())
{
parent::__construct($attributes, $options);
if (!isset($this->user)) {
$this->user = Session::getUser();
}
$this->site_memberships = new OrganizationSiteMemberships(array('organization' => $this, 'owner' => $this, 'owner_type' => 'organization'));
$this->user_memberships = new OrganizationUserMemberships(array('organization' => $this, 'owner' => $this, 'owner_type' => 'organization'));
$this->workflows = new Workflows(array('owner' => $this, 'owner_type' => 'organization'));
}
示例7: all
/**
* Show a list of your organizations on Pantheon
*
* @subcommand list
*/
public function all($args, $assoc_args)
{
$user = Session::getUser();
$data = array();
$organizations = $user->getOrganizations();
foreach ($organizations as $id => $org) {
$org_data = $org->get('organization');
$data[] = array('name' => $org_data->profile->name, 'id' => $org->get('id'));
}
$this->output()->outputRecordList($data);
}
示例8: hello
/**
* Say hello
*/
public function hello($args, $assoc_args)
{
if (Session::getValue('user_uuid')) {
$user = Session::getUser();
$user->fetch();
$data = $user->serialize();
$this->log()->info("Hello, {name}!", array('name' => $data['firstname']));
} else {
$this->log()->info("Hello, Anonymous!");
}
}
示例9: delete
/**
* Delete a machine token from your account
*
* ## OPTIONS
* [--machine-token-id=<id>]
* : UUID or name of the site you want to delete
*
* [--force]
* : to skip the confirmations
*/
public function delete($args, $assoc_args)
{
$user = Session::getUser();
$id = $assoc_args['machine-token-id'];
if (empty($id)) {
$this->failure('You must specify a machine token id to delete.');
}
// Find the token
$machine_token = $user->machine_tokens->get($assoc_args['machine-token-id']);
if (empty($machine_token)) {
$this->failure('There are no machine tokens with the id {id}.', array('id' => $id));
}
$name = $machine_token->get('device_name');
$this->input()->confirm(['message' => 'Are you sure you want to delete %s?', 'context' => $name, 'args' => $assoc_args]);
$this->log()->info('Deleting {name} ...', array('name' => $name));
$response = $machine_token->delete();
if ($response['status_code'] == 200) {
$this->log()->info('Deleted {name}!', array('name' => $name));
} else {
$this->failure('There was an problem deleting the machine token.');
}
}
示例10: __construct
/**
* Instantiates the collection, sets param members as properties
*
* @param array $options To be set to $this->key
* @return Sites
*/
public function __construct(array $options = array())
{
parent::__construct($options);
$this->sites_cache = new SitesCache();
$this->user = Session::getUser();
}
示例11: orgList
/**
* Returns an array listing organizaitions applicable to user
*
* @param array $arg_options Elements as follow:
* bool allow_none True to allow the "none" option
* @return array A list of organizations
*/
private function orgList(array $arg_options = [])
{
$default_options = ['allow_none' => true];
$options = array_merge($default_options, $arg_options);
$org_list = [];
if ($options['allow_none']) {
$org_list = ['-' => 'None'];
}
$user = Session::getUser();
$organizations = $user->organizations->all();
foreach ($organizations as $id => $org) {
$org_data = $org->get('organization');
$org_list[$org->get('id')] = $org_data->profile->name;
}
return $org_list;
}
示例12: logInViaMachineToken
/**
* Execute the login based on a machine token
*
* @param string[] $args Elements as follow:
* string token Machine token to initiate login with
* string email Email address to locate token with
* @return bool True if login succeeded
* @throws TerminusException
*/
public function logInViaMachineToken($args)
{
if (isset($args['token'])) {
$token = $args['token'];
} elseif (isset($args['email'])) {
$token = $this->tokens_cache->findByEmail($args['email'])['token'];
if (!$token) {
throw new TerminusException('No machine token for "{email}" found.', compact('email'), 1);
}
$this->logger->info('Found a machine token for "{email}".', ['email' => $args['email']]);
}
$options = array('headers' => array('Content-type' => 'application/json'), 'form_params' => array('machine_token' => $token, 'client' => 'terminus'));
$this->logger->info('Logging in via machine token');
$response = $this->request->request('authorize', '', '', 'POST', $options);
if (!$response || !isset($response['status_code']) || $response['status_code'] != '200') {
throw new TerminusException('The provided machine token is not valid.', [], 1);
}
$data = $response['data'];
$this->setInstanceData($response['data']);
$user = Session::getUser();
$user->fetch();
$user_data = $user->serialize();
$this->logger->info('Logged in as {email}.', ['email' => $user_data['email']]);
if (isset($args['token'])) {
$this->tokens_cache->add(['email' => $user_data['email'], 'token' => $token]);
}
return true;
}
示例13: isOrgAccessible
/**
* Checks to ensure user can access the given organization
*
* @param string $org_id Organization name or UUID
* @return bool True if this organization is accessible
*/
private function isOrgAccessible($org_id)
{
$user = Session::getUser();
$org = $user->organizations->get($org_id);
$is_ok = is_object($org);
return $is_ok;
}
示例14: whoami
/**
* Find out what user you are logged in as.
*/
public function whoami()
{
if (Session::getValue('user_uuid')) {
$user = Session::getUser();
$user->fetch();
$data = $user->serialize();
$this->output()->outputRecord($data);
} else {
$this->failure('You are not logged in.');
}
}
示例15: console
/**
* Instantiate a console within Terminus
*
* ## OPTIONS
*
* [--site=<site>]
* : name of site to load
*
* @subcommand console
*/
public function console($args, $assoc_args)
{
$user = Session::getUser();
if (isset($assoc_args['site'])) {
$site = $this->sites->get($this->input()->siteName(array('args' => $assoc_args)));
}
eval(\Psy\sh());
}