クラス
Rest
Declares all REST routes
ソース ソース
ファイル: src/Routes/Rest.php
class Rest extends Router { /** * Master object * * @var Master */ private $master; /** * Instantiates `Router` * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param Master $master */ public function __construct(Master $master) { $this->master = $master; parent::__construct('/wcexwl', 'wcexwl_nonce_key', 'wcexwl_nonce_name'); } /** * Declares routes * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param WordPressRouteCollector $r * @return void */ public function declareRoutes(WordPressRouteCollector $r) { $r->addGroup('/v3', function (WordPressRouteCollector $r) { // REST handlers $item = new API\Item($this->master); $cart = new API\Cart($this->master); $wishlist = new API\Wishlist($this->master); $validation = new API\Validation($this->master); // route guards and middleware $isLoggedIn = [$validation, 'isLoggedIn']; $maybeClearCart = [$wishlist, 'maybeClearCart']; $beforeRouteEnter = [$this, 'beforeRouteEnter']; // REST routes $r->post('/item/addToWishlist', [$item, 'postToWishlist'], [$beforeRouteEnter]); $r->post('/cart/addToWishlist', [$cart, 'postToWishlistBySerial'], [$beforeRouteEnter]); $r->post('/cart/batchDelete', [$cart, 'batchDelete'], [$beforeRouteEnter]); $r->post('/wishlist/delete/{itemId}', [$wishlist, 'delete'], [$beforeRouteEnter, $isLoggedIn]); $r->post('/wishlist/batchDelete', [$wishlist, 'batchDelete'], [$beforeRouteEnter, $isLoggedIn]); $r->post('/wishlist/addToCart/{itemId}', [$wishlist, 'addToCart'], [$beforeRouteEnter, $isLoggedIn, $maybeClearCart]); $r->post('/wishlist/batchAddToCart', [$wishlist, 'batchAddToCart'], [$beforeRouteEnter, $isLoggedIn, $maybeClearCart]); }); } /** * Runs hook before every route * * @author Evan D Shaw <evandanielshaw@gmail.com> * @param array $args URI parameters * @param array $payload The array parsed from `json_encoded` data stored in `$_POST['payload']` * @return void */ public function beforeRouteEnter(array $args, array $payload) { /** * Fires before execution for every REST API route. * * @important * @param array $args URI parameters * @param array $payload The array parsed from `json_encoded` data stored in `$_POST['payload']` */ do_action('wcexwl_before_route_enter', $args, $payload); } }
- __construct — Instantiates Router
- beforeRouteEnter — Runs hook before every route
- declareRoutes — Declares routes