Skip to content

Commit

Permalink
Standardized function names across collections and models
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara McCutcheon committed Aug 31, 2016
1 parent 61b6065 commit d588402
Show file tree
Hide file tree
Showing 40 changed files with 238 additions and 248 deletions.
10 changes: 5 additions & 5 deletions php/Terminus/Collections/Backups.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function __construct($options = []) {
public function cancelBackupSchedule() {
$path_root = sprintf(
'sites/%s/environments/%s/backups/schedule',
$this->environment->site->get('id'),
$this->environment->get('id')
$this->environment->site->id,
$this->environment->id
);
$params = ['method' => 'delete',];
for ($day = 0; $day < 7; $day++) {
Expand Down Expand Up @@ -145,8 +145,8 @@ function($backup) use ($element) {
public function getBackupSchedule() {
$path = sprintf(
'sites/%s/environments/%s/backups/schedule',
$this->environment->site->get('id'),
$this->environment->get('id')
$this->environment->site->id,
$this->environment->id
);
$response = $this->request->request($path);
$response_data = (array)$response['data'];
Expand Down Expand Up @@ -192,7 +192,7 @@ public function getFinishedBackups($element) {
$message,
[
'site' => $this->environment->site->get('name'),
'env' => $this->environment->get('id')
'env' => $this->environment->id
],
1
);
Expand Down
7 changes: 2 additions & 5 deletions php/Terminus/Collections/OrganizationSiteMemberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public function create($site) {
* @return OrganizationSiteMembership
*/
public function get($id) {
if (empty($this->models)) {
$this->fetch();
}
$models = $this->models;
$models = $this->getMembers();
if (isset($models[$id])) {
return $models[$id];
} else {
Expand All @@ -77,7 +74,7 @@ public function get($id) {
public function getSite($site_id) {
if (is_null($membership = $this->get($site_id))) {
throw new TerminusException(
'This user does is not a member of an organization identified by {id}.',
'This user is not a member of an organization identified by {id}.',
['id' => $site_id,]
);
}
Expand Down
2 changes: 1 addition & 1 deletion php/Terminus/Collections/SiteAuthorizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SiteAuthorizations extends TerminusCollection {
/**
* @var string
*/
protected $collected_class = 'Terminus\Models\SiteAuthorizations';
protected $collected_class = 'Terminus\Models\SiteAuthorization';

/**
* Object constructor
Expand Down
2 changes: 1 addition & 1 deletion php/Terminus/Collections/SiteOrganizationMemberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($options = []) {
* @param string $role Role for supporting organization to take
* @return Workflow
**/
public function addMember($name, $role) {
public function create($name, $role) {
$workflow = $this->site->workflows->create(
'add_site_organization_membership',
['params' => ['organization_name' => $name, 'role' => $role,],]
Expand Down
2 changes: 1 addition & 1 deletion php/Terminus/Collections/SiteUserMemberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($options = []) {
* @param string $role Role to assign to the new user
* @return Workflow
**/
public function addMember($email, $role) {
public function create($email, $role) {
$workflow = $this->site->workflows->create(
'add_site_user_membership',
['params' => ['user_email' => $email, 'role' => $role,],]
Expand Down
4 changes: 1 addition & 3 deletions php/Terminus/Collections/SshKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public function deleteAll() {
*/
public function fetch(array $options = []) {
$results = $this->getCollectionData($options);
$data = (object)$results['data'];

foreach (get_object_vars($data) as $uuid => $ssh_key) {
foreach ($results['data'] as $uuid => $ssh_key) {
$model_data = (object)['id' => $uuid, 'key' => $ssh_key,];
$this->add($model_data);
}
Expand Down
27 changes: 1 addition & 26 deletions php/Terminus/Collections/TerminusCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,12 @@ abstract class TerminusCollection {
/**
* Instantiates the collection, sets param members as properties
*
* @param array $options To be set to $this->key
* @param array $options Options with which to configure this collection
*/
public function __construct(array $options = []) {
$this->request = new Request();
}

/**
* Handles requests for inaccessible properties
*
* @param string $property Name of property being requested
* @return mixed $this->$property
* @throws TerminusException
*/
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}

$trace = debug_backtrace();
throw new TerminusException(
'Undefined property $var->${property} in {file} on line {line}',
[
'property' => $property,
'file' => $trace[0]['file'],
'line' => $trace[0]['line']
],
1
);
return null;
}

/**
* Adds a model to this collection
*
Expand Down
23 changes: 1 addition & 22 deletions php/Terminus/Collections/UserOrganizationMemberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,12 @@ class UserOrganizationMemberships extends TerminusCollection {
/**
* Object constructor
*
* @param array $options Options to set as $this->key
* @param array $options Options with which to configure this collection
*/
public function __construct($options = []) {
parent::__construct($options);
$this->user = $options['user'];
$this->url = "users/{$this->user->id}/memberships/organizations";
}

/**
* Retrieves the matching organization from model members
*
* @param string $org ID or name of desired organization
* @return Organization $organization
* @throws TerminusException
*/
public function getOrganization($org) {
$memberships = $this->all();
foreach ($memberships as $membership) {
$organization = $membership->organization;
if (in_array($org, [$organization->id, $organization->get('name'),])) {
return $organization;
}
}
throw new TerminusException(
'This user is not a member of an organizaiton identified by {org}.',
compact('org')
);
}

}
2 changes: 1 addition & 1 deletion php/Terminus/Collections/Workflows.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Workflows extends TerminusCollection {
/**
* Instantiates the collection, sets param members as properties
*
* @param array $options To be set to $this->key
* @param array $options Options with which to configure this collection
*/
public function __construct(array $options = []) {
parent::__construct($options);
Expand Down
2 changes: 1 addition & 1 deletion php/Terminus/Commands/CliCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function info($args, $assoc_args) {
'php_binary_path' => $config['php'],
'php_version' => PHP_VERSION,
'php_ini' => get_cfg_var('cfg_file_path'),
'project_config_path' => $this->runner->getUserConfigDir(),
'project_config_path' => $config['config_dir'],
'terminus_path' => $config['root'],
'terminus_version' => $config['version'],
];
Expand Down
2 changes: 1 addition & 1 deletion php/Terminus/Commands/CommandWithSSH.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function getElements($args, $assoc_args) {
'env_id' => $env_id,
'command' => $args[0],
'server' => $this->getAppserverInfo(
['site' => $site->get('id'), 'environment' => $env_id,]
['site' => $site->id, 'environment' => $env_id,]
),
];
return $elements;
Expand Down
2 changes: 1 addition & 1 deletion php/Terminus/Commands/InstrumentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function all($args, $assoc_args) {
foreach ($instruments as $id => $instrument) {
$data[] = array(
'label' => $instrument->get('label'),
'id' => $instrument->get('id'),
'id' => $instrument->id,
);
}
if (empty($data)) {
Expand Down
2 changes: 1 addition & 1 deletion php/Terminus/Commands/MachineTokensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function index($args, $assoc_args) {
$data = array();
foreach ($machine_tokens as $id => $machine_token) {
$data[] = array(
'id' => $machine_token->get('id'),
'id' => $machine_token->id,
'device_name' => $machine_token->get('device_name'),
);
}
Expand Down
47 changes: 27 additions & 20 deletions php/Terminus/Commands/OrganizationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function all($args, $assoc_args) {
foreach ($organizations as $id => $org) {
$data[] = [
'name' => $org->get('profile')->name,
'id' => $org->get('id'),
'id' => $org->id,
];
}

Expand Down Expand Up @@ -121,9 +121,10 @@ public function team($args, $assoc_args) {
}

private function addMemberToTeam($assoc_args) {
$org = $this->user->org_memberships->getOrganization(
$this->input()->orgId(['args' => $assoc_args, 'allow_none' => false,])
$org_id = $this->input()->orgId(
['args' => $assoc_args, 'allow_none' => false,]
);
$org = $this->user->getOrganizations()[$org_id];

$email = $this->input()->string(
[
Expand All @@ -148,9 +149,10 @@ private function addMemberToTeam($assoc_args) {
}

private function removeMemberFromTeam($assoc_args) {
$org = $this->user->org_memberships->getOrganization(
$this->input()->orgId(['args' => $assoc_args, 'allow_none' => false,])
$org_id = $this->input()->orgId(
['args' => $assoc_args, 'allow_none' => false,]
);
$org = $this->user->getOrganizations()[$org_id];

$member = $this->input()->orgMember(
[
Expand All @@ -173,19 +175,20 @@ private function removeMemberFromTeam($assoc_args) {
* @return void
*/
private function addSiteToOrganization($assoc_args) {
$org = $this->user->org_memberships->getOrganization(
$this->input()->orgId(['args' => $assoc_args, 'allow_none' => false,])
$org_id = $this->input()->orgId(
['args' => $assoc_args, 'allow_none' => false,]
);
$site_memberships = $this->user->site_memberships->all();
$org = $this->user->getOrganizations()[$org_id];
$sites = $this->user->getSites();
$choices = array_combine(
array_map(
function ($membership) {
$site_name = $membership->site->get('name');
function ($site) {
$site_name = $site->get('name');
return $site_name;
},
$site_memberships
$sites
),
$site_memberships
$sites
);
$site = $this->sites->get(
$this->input()->siteName(
Expand Down Expand Up @@ -214,9 +217,10 @@ function ($membership) {
* @return array $data Data to display about sites in the organization
*/
private function listOrganizationalSites($assoc_args) {
$org = $this->user->org_memberships->getOrganization(
$this->input()->orgId(['args' => $assoc_args, 'allow_none' => false,])
$org_id = $this->input()->orgId(
['args' => $assoc_args, 'allow_none' => false,]
);
$org = $this->user->getOrganizations()[$org_id];

$tag = $this->input()->optional(
['key' => 'tag', 'choices' => $assoc_args,]
Expand Down Expand Up @@ -276,9 +280,10 @@ function ($membership) {
* @return void
*/
private function removeSiteFromOrganization($assoc_args) {
$org = $this->user->org_memberships->getOrganization(
$this->input()->orgId(['args' => $assoc_args, 'allow_none' => false,])
$org_id = $this->input()->orgId(
['args' => $assoc_args, 'allow_none' => false,]
);
$org = $this->user->getOrganizations()[$org_id];
$site_memberships = $org->site_memberships->all();
$choices = array_combine(
array_map(
Expand Down Expand Up @@ -325,9 +330,10 @@ function ($membership) {
* @return array $data Data to display about sites in the organization
*/
private function listOrganizationTeam($assoc_args) {
$org = $this->user->org_memberships->getOrganization(
$this->input()->orgId(['args' => $assoc_args, 'allow_none' => false,])
$org_id = $this->input()->orgId(
['args' => $assoc_args, 'allow_none' => false,]
);
$org = $this->user->getOrganizations()[$org_id];

$data = array_map(
function ($membership) {
Expand Down Expand Up @@ -356,9 +362,10 @@ function ($membership) {
* @return void
*/
private function setMemberRole($assoc_args) {
$org = $this->user->org_memberships->getOrganization(
$this->input()->orgId(['args' => $assoc_args, 'allow_none' => false,])
$org_id = $this->input()->orgId(
['args' => $assoc_args, 'allow_none' => false,]
);
$org = $this->user->getOrganizations()[$org_id];
$role_choices = ['unprivileged', 'admin'];

$member = $this->input()->orgMember(
Expand Down
Loading

0 comments on commit d588402

Please sign in to comment.