title: PHP Handling complex requests through single entry point app
body: <p>I have been developing a Sports Management website with user, roster, and schedule management using PHP and JS. This app has about 15 database tables to work with altogether. Recently I learned I was doing something majorly wrong: I was using individual PHP scripts as their own "apps". </p>
  
  <p>Example: Individual scripts app</p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>var params = {
     action : 'addGame',
     date : 'someday',
     hometeam : 1,
     awayteam : 2
  }
  $.post('/php/scheduler.php', params);
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>class Scheduler extends TableManager{
  
      public function addGame($date, $hometeam, $awayteam){
         // do sql stuff
      }
  
      public function doAction($request){
          switch($request){
              case "addGame":
                   return $this-&gt;addGame($_REQUEST['date'], $_REQUEST['hometeam'], $_REQUEST['awayteam'];
                   break;
          }
      }
  
      }
  
  if(isset($_REQUEST['action'])){
     $scheduler = new Scheduler();
     $scheduler-&gt;doAction($_REQUEST['action']);
  }
  </code></pre>
  
  <p>I learned that writing a proper PHP  application means there should be a single "app" where all requests are routed. This is fine and I've done this - but now I face unknown territory. If I have 15 tables, and they all have a few very specific functions (they all <code>extend TableManager</code> to provide basic table functions, but some are obviously more specific) how can I write a request processor in my main <code>App</code> that handles requests for every table, without getting insanely complex?</p>
  
  <p>Example: Single entry point app</p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>var params = {
     action : 'addGame',
     table : 'scheduler',
     date : 'someday',
     hometeam : 1,
     awayteam : 2
  }
  $.post('/php/app.php', params);
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>class App {
  
     private $scheduleTable;
  
     public function createTable($name){
          switch($name){
              case "scheduler":
                 $this-&gt;scheduleTable = new Scheduler();
                 break;
          } 
     }
  
     public doAction($request){
       switch($request){
              case "addGame":
                   $this-&gt;createTable('scheduler');
                   return $this-&gt;scheduleTable-&gt;addGame($_REQUEST['date'], $_REQUEST['hometeam'], $_REQUEST['awayteam'];
                   break;
          }
     }
  
  }
  
  if(isset($_REQUEST['action'])){
     $app = new App();
     $app -&gt;doAction($_REQUEST['action']);
  }
  </code></pre>
  
  <p>Now I need to start using complex and bloated switch statements, as my tables all inherit <code>TableManager</code> and thus do many of the same actions, but also have unique functions. I'll need to <code>switch</code> on the incoming <code>action</code>, and then <code>switch</code> on the <code>table</code>. Not to mention all of the other features that this <code>App</code> will have (user system, for one). Is the only answer to write a massive switch statement?</p>