-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from stripe/ob-use-traits
Use traits for API operations methods
- Loading branch information
Showing
37 changed files
with
253 additions
and
1,375 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
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,22 @@ | ||
<?php | ||
|
||
namespace Stripe\ApiOperations; | ||
|
||
/** | ||
* Trait for listable resources. Adds a `all()` static method to the class. | ||
* | ||
* This trait should only be applied to classes that derive from ApiResource. | ||
*/ | ||
trait All | ||
{ | ||
/** | ||
* @param array|null $params | ||
* @param array|string|null $opts | ||
* | ||
* @return Collection of ApiResources | ||
*/ | ||
public static function all($params = null, $opts = null) | ||
{ | ||
return self::_all($params, $opts); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Stripe\ApiOperations; | ||
|
||
/** | ||
* Trait for creatable resources. Adds a `create()` static method to the class. | ||
* | ||
* This trait should only be applied to classes that derive from ApiResource. | ||
*/ | ||
trait Create | ||
{ | ||
/** | ||
* @param array|null $params | ||
* @param array|string|null $options | ||
* | ||
* @return ApiResource The created resource. | ||
*/ | ||
public static function create($params = null, $options = null) | ||
{ | ||
return self::_create($params, $options); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
namespace Stripe\ApiOperations; | ||
|
||
/** | ||
* Trait for deletable resources. Adds a `delete()` method to the class. | ||
* | ||
* This trait should only be applied to classes that derive from ApiResource. | ||
*/ | ||
trait Delete | ||
{ | ||
/** | ||
* @param array|null $params | ||
* @param array|string|null $opts | ||
* | ||
* @return ApiResource The deleted resource. | ||
*/ | ||
public function delete($params = null, $opts = null) | ||
{ | ||
return $this->_delete($params, $opts); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Stripe\ApiOperations; | ||
|
||
/** | ||
* Trait for retrievable resources. Adds a `retrieve()` static method to the | ||
* class. | ||
* | ||
* This trait should only be applied to classes that derive from ApiResource. | ||
*/ | ||
trait Retrieve | ||
{ | ||
/** | ||
* @param array|string $id The ID of the API resource to retrieve, | ||
* or an options array containing an `id` key. | ||
* @param array|string|null $opts | ||
* | ||
* @return ApiResource | ||
*/ | ||
public static function retrieve($id, $opts = null) | ||
{ | ||
return self::_retrieve($id, $opts); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace Stripe\ApiOperations; | ||
|
||
/** | ||
* Trait for updatable resources. Adds an `update()` static method and a | ||
* `save()` method to the class. | ||
* | ||
* This trait should only be applied to classes that derive from ApiResource. | ||
*/ | ||
trait Update | ||
{ | ||
/** | ||
* @param string $id The ID of the resource to update. | ||
* @param array|null $params | ||
* @param array|string|null $options | ||
* | ||
* @return ApiResource The updated resource. | ||
*/ | ||
public static function update($id, $params = null, $options = null) | ||
{ | ||
return self::_update($id, $params, $options); | ||
} | ||
|
||
/** | ||
* @param array|string|null $options | ||
* | ||
* @return ApiResource The saved resource. | ||
*/ | ||
public function save($options = null) | ||
{ | ||
return $this->_save($options); | ||
} | ||
} |
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
Oops, something went wrong.