示例#1
0
function callHook()
{
    global $url;
    global $default;
    global $controller;
    $queryString = array();
    if (!isset($url)) {
        $controller = $default['controller'];
        $action = $default['action'];
    } else {
        $url = routeURL($url);
        $urlArray = array();
        $urlArray = explode("/", $url);
        $urlArray = array_filter($urlArray);
        $controller = $urlArray[0];
        array_shift($urlArray);
        if (isset($urlArray[0])) {
            $action = $urlArray[0];
            array_shift($urlArray);
        } else {
            $action = 'index';
            // Default Action
        }
        $queryString = $urlArray;
    }
    $controllerName = ucfirst($controller) . 'Controller';
    // Check to see if the controller exists
    if (!file_exists('../application/controllers/' . $controllerName . '.php')) {
        if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') {
            // Serve up some JSON
            $dispatch = new Api();
            $dispatch->response('Endpoint not found', 404);
        } else {
            // Serve up some HTML
            $dispatch = new ErrorController();
            call_user_func_array(array($dispatch, 'notFound'), []);
            exit;
        }
    }
    $dispatch = new $controllerName($controller, $action);
    if ((int) method_exists($controllerName, $action)) {
        call_user_func_array(array($dispatch, "beforeAction"), $queryString);
        call_user_func_array(array($dispatch, $action), $queryString);
        call_user_func_array(array($dispatch, "afterAction"), $queryString);
    } else {
        // We should check the Accept header type to server up the correct 404
        if (isset($_SERVER['CONTENT_TYPE']) && $_SERVER['CONTENT_TYPE'] == 'application/json') {
            // Serve up some JSON
            $dispatch = new Api();
            $dispatch->response('Endpoint not found', 404);
        } else {
            // Serve up some HTML
            $dispatch = new ErrorController();
            call_user_func_array(array($dispatch, 'notFound'), []);
            exit;
        }
    }
}
示例#2
0
 public function getStoresAlgolia($coordinate)
 {
     $latitude = $this->getLatitude($coordinate);
     $longitude = $this->getLongitude($coordinate);
     $client = new \AlgoliaSearch\Client(APPLICATION_ID, API_KEY);
     $index = $client->initIndex(INDEX_STORES);
     $query = $index->search("", array("aroundLatLng" => "{$latitude},{$longitude}", "aroundRadius" => 1000));
     if ($this->validateNbHits($query)) {
         parent::response($response_code = 200, $this->arrayInformation($query));
     } else {
         parent::response($response_code = 404, array("stores" => 0, "message" => "Stores near not found"));
     }
 }
 /**
  * Remove auth token from cache
  * @return array
  */
 public function logout()
 {
     User::invalidateToken($this->token);
     return Api::response(['success' => true]);
 }
 public function __call($method, $parameters)
 {
     return Api::response(array('status' => false, 'error_code' => 404, 'error_string' => 'unknown method'), 404);
 }
示例#5
0
文件: routes.php 项目: agkunz/user
            // delete
            Route::delete('{id}', array("as" => "groups.destroy", "uses" => "Agkunz\\User\\GroupController@destroy"));
        });
    });
    // jesus please dear god don't use this
    Route::get("reset", array("as" => "dev.api.reset", "uses" => "Agkunz\\Api\\ApiController@reset"));
    // this is a work route to get your hmac
    Route::get('{email}', function ($email) {
        $key = Sentry::findUserByLogin($email)->getApiKey();
        $data = array('email' => $email, 'timestamp' => time());
        $hash_string = json_encode($data);
        $hmac = hash_hmac('sha256', $hash_string, $key);
        $data['hmac'] = $hmac;
        dd($data);
    });
});
Route::filter('apiauth', function () {
    if (!Api::authenticate()) {
        return Api::response(false);
    }
});
Route::filter('byroute', function () {
    if ($user = Config::get('user')) {
        if (!$user->hasPermission("superuser")) {
            if (!$user->hasPermission(Route::getCurrentRoute())) {
                MessageBag::add("error", "You don't have permission to use this route.");
                return Api::response(false);
            }
        }
    }
});