title: Slim v2 to Slim v3 Upgrade
body: <p>I have been using Slim v2 for my APIs and am thinking about upgrading to v3.
  Unfortunately I have limited experience and could use your help on a code example below.</p>
  
  <p>This is the login code:</p>
  
  <pre><code>$app-&gt;post('/register', function() use ($app) {
          // check for required params
          verifyRequiredParams(array('name', 'email', 'password'));
  
          $response = array();
  
          // reading post params
          $name = $app-&gt;request-&gt;post('name');
          $email = $app-&gt;request-&gt;post('email');
          $password = $app-&gt;request-&gt;post('password');
  
          // validating email address
          validateEmail($email);
  
          $db = new DbHandler();
          $res = $db-&gt;createUser($name, $email, $password);
  
          if ($res == USER_CREATED_SUCCESSFULLY) {
              $response["error"] = false;
              $response["message"] = "You are successfully registered";
          } else if ($res == USER_CREATE_FAILED) {
              $response["error"] = true;
              $response["message"] = "Oops! An error occurred while registereing";
          } else if ($res == USER_ALREADY_EXISTED) {
              $response["error"] = true;
              $response["message"] = "Sorry, this email already existed";
          }
          // echo json response
          echoRespnse(201, $response);
      });
  </code></pre>
  
  <p>Here is the validateEmail function:</p>
  
  <pre><code>function validateEmail($email) {
  $app = \Slim\Slim::getInstance();
  if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $response["error"] = true;
      $response["message"] = 'Email address is not valid';
      echoRespnse(400, $response);
      $app-&gt;stop();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>How do I get an Instance of app in Slim v3 to actually stop the app when input criteria are not met?
  I would appreciate it if you could give me an example with the help of my code.</p>
  
  <p>Thanks for the help!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The above issue was solved. Unfortunately, a new issue arose after checking my code.</p>
  
  <p>I have a middle layer to authenticate the user: </p>
  
  <pre><code>function authenticate(\Slim\Route $route) {
  // Getting request headers
  $headers = apache_request_headers();
  $response = array();
  $app = \Slim\Slim::getInstance();
  
  // Verifying Authorization Header
  if (isset($headers['Authorization'])) {
      //omitted code
  } else {
      // api key is missing in header
      $response["error"] = true;
      $response["message"] = "Api key is misssing";
      echoRespnse(400, $response);
      $app-&gt;stop();
  }
  </code></pre>
  
  <p>In my main code i implement function authenticate as follows:</p>
  
  <pre><code>$app-&gt;get('/tasks', 'authenticate', function() {
          global $user_id;
          $response = array();
          $db = new DbHandler();
  
         //ommit some code
  
          echoRespnse(200, $response);
      });
  </code></pre>
  
  <p>Would you know how to do this in Slim v3?
  I would really appreciate your help.</p>