Exemplo n.º 1
0
 /**
  * Traverse the controllers based on the path
  *
  * @param  array $controllers
  * @param  int $depth
  * @return string
  */
 protected function traverseControllers($controllers, $depth = 0)
 {
     $next = $depth + 1;
     // If the path stem exists in the controllers, the traverse it
     if ($this->request->getPath($depth) != '' && array_key_exists('/' . $this->request->getPath($depth), $controllers)) {
         $this->basePath .= '/' . $this->request->getPath($depth);
         // If the next level is an array, traverse it
         if (is_array($controllers['/' . $this->request->getPath($depth)])) {
             return $this->traverseControllers($controllers['/' . $this->request->getPath($depth)], $next);
             // Else, return the controller class name
         } else {
             return isset($controllers['/' . $this->request->getPath($depth)]) ? $controllers['/' . $this->request->getPath($depth)] : null;
         }
         // Else check for the root '/' path
     } else {
         if (array_key_exists('/', $controllers)) {
             $this->basePath .= '/';
             // If the next level is an array, traverse it
             if (is_array($controllers['/'])) {
                 return $this->traverseControllers($controllers['/'], $next);
                 // Else, return the controller class name
             } else {
                 return isset($controllers['/']) ? $controllers['/'] : null;
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Dispatch the controller based on the action
  *
  * @param  string $action
  * @throws \Pop\Mvc\Exception
  * @return \Pop\Mvc\Controller
  */
 public function dispatch($action = 'index')
 {
     if (method_exists($this, $action)) {
         if (null !== $this->project->logger()) {
             $this->project->log("Dispatch ['" . get_class($this) . "']->" . $action . "\t" . $this->request->getRequestUri() . "\t" . $this->request->getFullUri(), time());
         }
         $this->{$action}();
     } else {
         throw new Exception('That action is not defined in the controller.');
     }
 }
Exemplo n.º 3
0
 /**
  * Get query string
  *
  * @param  mixed  $omit
  * @return string
  */
 public function getQueryString($omit = null)
 {
     if (null !== $omit && !is_array($omit)) {
         $omit = [$omit];
     }
     $get = $this->request->getQuery();
     $query = [];
     foreach ($get as $key => $value) {
         if (!isset($query[$key]) && !in_array($key, $omit)) {
             $query[$key] = $value;
         }
     }
     return count($query) > 0 ? http_build_query($query) : '';
 }
Exemplo n.º 4
0
 private function isValidRequest()
 {
     $result = false;
     if (null !== $this->request->getHeader('Authorization') && null !== $this->request->getHeader('User-Agent')) {
         $token = base64_decode($this->request->getHeader('Authorization'));
         $ua = $this->request->getHeader('User-Agent');
         if (stripos($ua, 'curl') === false) {
             if (substr($token, 0, 12) == 'phire-stats-') {
                 if (is_numeric(substr($token, 13))) {
                     $result = true;
                 }
             }
         }
     }
     return $result;
 }
Exemplo n.º 5
0
<?php

require_once '../../bootstrap.php';
use Pop\Http\Request;
try {
    $request = new Request();
    switch ($request->getMethod()) {
        case 'GET':
            print_r($request->getQuery());
            break;
        case 'POST':
            print_r($request->getPost());
            break;
        case 'PUT':
            print_r($request->getPut());
            break;
        case 'PATCH':
            print_r($request->getPatch());
            break;
        case 'DELETE':
            print_r($request->getDelete());
            break;
    }
} catch (\Exception $e) {
    echo $e->getMessage();
}
Exemplo n.º 6
0
 private function parsePostData()
 {
     $data = ['address' => $this->request->getPost('ftp_address'), 'username' => $this->request->getPost('ftp_username'), 'password' => $this->request->getPost('ftp_password'), 'root' => $this->request->getPost('ftp_root'), 'pasv' => (bool) $this->request->getPost('use_pasv'), 'ssl' => (bool) $this->request->getPost('protocol'), 'base_path' => $this->request->getPost('base_path'), 'app_path' => $this->request->getPost('app_path'), 'content_path' => $this->request->getPost('content_path')];
     return $data;
 }
Exemplo n.º 7
0
 public function testIp()
 {
     $_SERVER['HTTP_X_FORWARDED_FOR'] = '255.255.255.255';
     $r = new Request();
     $this->assertEquals('255.255.255.255', $r->getIp(true));
     $_SERVER['HTTP_CLIENT_IP'] = '123.123.123.123';
     $r = new Request();
     $this->assertEquals('123.123.123.123', $r->getIp(true));
     unset($_SERVER['HTTP_X_FORWARDED_FOR']);
     unset($_SERVER['HTTP_CLIENT_IP']);
     $_SERVER['REMOTE_ADDR'] = '123.123.123.123';
     $r = new Request();
     $this->assertEquals('123.123.123.123', $r->getIp());
 }