-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
844a2b9
commit 6c3b766
Showing
5 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Terminus\Collections; | ||
use Terminus\Request; | ||
use Terminus\Models\Binding; | ||
use \Terminus_Command; | ||
|
||
class Bindings { | ||
private $environment; | ||
private $models = array(); | ||
|
||
public function __construct($options = array()) { | ||
$this->environment = $options['environment']; | ||
|
||
return $this; | ||
} | ||
|
||
public function fetch() { | ||
$results = Terminus_Command::request("sites", $this->environment->site->getId(), "bindings", "GET"); | ||
|
||
foreach (get_object_vars($results['data']) as $id => $binding_data) { | ||
# Only include bindings for this environment | ||
if ($binding_data->environment == $this->environment->id) { | ||
$binding_data->id = $id; | ||
$this->models[$id] = new Binding($binding_data, array('collection' => $this)); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function get($id) { | ||
return array_key_exists($id, $this->models) ? $this->models[$id] : null; | ||
} | ||
|
||
public function all() { | ||
return array_values($this->models); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
namespace Terminus\Models; | ||
use \Terminus\Request; | ||
|
||
class Binding { | ||
public $id; | ||
public $attributes; | ||
public $collection; | ||
public $environment; | ||
|
||
public function __construct($attributes, $options = array()) { | ||
$this->id = $attributes->id; | ||
$this->attributes = $attributes; | ||
$this->collection = $options['collection']; | ||
$this->environment = $options['environment']; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters