本文整理汇总了PHP中Terminus\Session类的典型用法代码示例。如果您正苦于以下问题:PHP Session类的具体用法?PHP Session怎么用?PHP Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAliases
/**
* Requests API data and returns aliases
*
* @return string
*/
private function getAliases()
{
$request = new Request();
$user = new User();
$path = 'drush_aliases';
$method = 'GET';
$response = $request->request('users', Session::getValue('user_id'), $path, $method);
eval(str_replace('<?php', '', $response['data']->drush_aliases));
$formatted_aliases = substr($response['data']->drush_aliases, 0, -1);
$sites_object = new Sites();
$sites = $sites_object->all();
foreach ($sites as $site) {
$environments = $site->environments->all();
foreach ($environments as $environment) {
$key = $site->get('name') . '.' . $environment->get('id');
if (isset($aliases[$key])) {
break;
}
try {
$formatted_aliases .= PHP_EOL . " \$aliases['{$key}'] = ";
$formatted_aliases .= $this->constructAlias($environment);
} catch (TerminusException $e) {
continue;
}
}
}
$formatted_aliases .= PHP_EOL;
return $formatted_aliases;
}
示例2: __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();
}
}
示例3: loggedIn
/**
* Determines if user is logged in
*
* @return [boolean] True if user is logged in
*/
public static function loggedIn()
{
if (Session::instance()->getValue('session', false) === false) {
throw new TerminusException('Please login first with `terminus auth login`');
}
return true;
}
示例4: 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);
}
}
示例5: 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.');
}
}
示例6: whoami
/**
* Find out what user you are logged in as.
*/
public function whoami()
{
if (Session::getValue('user_uuid')) {
$this->output()->outputValue(Session::getValue('user_uuid'), 'You are authenticated as');
} else {
$this->failure('You are not logged in.');
}
}
示例7: __construct
/**
* Object constructor
*
* @param [stdClass] $attributes Attributes of this model
* @param [array] $options Options to set as $this->key
* @return [User] $this
*/
public function __construct($attributes, $options = array())
{
if (!isset($options['id'])) {
$options['id'] = Session::getValue('user_uuid');
}
parent::__construct($attributes, $options);
$this->workflows = new Workflows(array('owner' => $this));
$this->instruments = new Instruments(array('user' => $this));
$this->setProfile();
}
示例8: 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());
}
示例9: __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'));
}
示例10: 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);
}
示例11: 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!");
}
}
示例12: __construct
public function __construct($id = null)
{
if (null === $id) {
$this->id = Session::getValue('user_uuid');
} else {
$this->id = $id;
}
$this->getProfile();
self::$instance = $this;
return $this;
}
示例13: fetch_user_organizations
public function fetch_user_organizations()
{
$response = Terminus_Command::paged_request('users/' . Session::getValue('user_uuid') . '/memberships/organizations');
$data = array();
foreach ($response['data'] as $membership) {
if ($membership->role != 'unprivileged') {
$data[$membership->id] = $membership->organization->profile->name;
}
}
return $data;
}
示例14: 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);
}
示例15: __construct
public function __construct($id = null)
{
if (null === $id) {
$this->id = Session::getValue('user_uuid');
} else {
$this->id = $id;
}
$this->workflows = new Workflows(array('owner' => $this, 'owner_type' => 'user'));
$this->getProfile();
self::$instance = $this;
return $this;
}