Advertisement
gasaichan

php_action_selector_for_restful_api

Mar 28th, 2019
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1.     public function select_action() {
  2.  
  3.         /**
  4.          * uri_units[1] => api
  5.          * uri_units[2] => auth / stores
  6.          * uri_units[3] => store_id / tag
  7.          * uri_units[4] => components / tag_name
  8.          * uri_units[5] => component_id
  9.          */
  10.  
  11.             switch ($this->uri_units[2]) {
  12.                 case "auth":
  13.                     // Authorize user
  14.                     $this->action = "Authorization";
  15.                     break;
  16.                 case "stores":
  17.                     switch ($this->method) {
  18.                         case "GET":
  19.                             if (isset($this->uri_units[3])) {
  20.                                 switch ($this->uri_units[3]) {
  21.                                     case "tag":
  22.                                         // Return all shops with provided tag_name
  23.                                         $this->action = "Return shops with provided tag";
  24.                                         break;
  25.                                     default:
  26.                                         if (isset($this->uri_units[4])) {
  27.                                             if (isset($this->uri_units[5])) {
  28.                                                 // Return component with provided id from provided shop id
  29.                                                 $this->action = "Return component with provided id from provided shop id";
  30.                                             } else {
  31.                                                 // Return all components from provided shop id
  32.                                                 $this->action = "Return all components from provided shop id";
  33.                                             }
  34.                                         } else {
  35.                                             // Return shop with provided shop id
  36.                                             $this->action = "Return shop with provided shop id";
  37.                                         }
  38.                                 }
  39.                             } else {
  40.                                 // Return all shops
  41.                                 $this->action = "Return all shops";
  42.                             }
  43.                             break;
  44.                         case "POST":
  45.                             if (isset($this->uri_units[3])) {
  46.                                 if (isset($this->uri_units[4])) {
  47.                                     // Add component
  48.                                     $this->action = "Add component";
  49.                                 } else {
  50.                                     // Edit shop
  51.                                     $this->action = "Edit shop";
  52.                                 }
  53.                             } else {
  54.                                 // Add new shop
  55.                                 $this->action = "Add new shop";
  56.                             }
  57.                             break;
  58.                         case "DELETE":
  59.                             if (isset($this->uri_units[4])) {
  60.                                 // Delete component
  61.                                 $this->action = "Delete component";
  62.                             } else {
  63.                                 $this->action = "Delete shop";
  64.                             }
  65.                     }
  66.             }
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement