當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Slim::getInstance方法代碼示例

本文整理匯總了PHP中Slim\Slim::getInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Slim::getInstance方法的具體用法?PHP Slim::getInstance怎麽用?PHP Slim::getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Slim\Slim的用法示例。


在下文中一共展示了Slim::getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: check_user_is_manager

 public static function check_user_is_manager()
 {
     BaseController::check_logged_in();
     if (!BaseController::get_user_logged_in()->manager) {
         Redirect::to(\Slim\Slim::getInstance()->urlFor('index'), array('message' => 'Sinulla ei ole oikeuksiä käyttää toimintoa!', 'error' => true));
     }
 }
開發者ID:laazz,項目名稱:talpa,代碼行數:7,代碼來源:base_controller.php

示例2: login

function login()
{
    $app = \Slim\Slim::getInstance();
    $json = decodeJsonOrFail($app->request->getBody());
    $user = User::where('username', '=', $json['username'])->where('password', '=', $json['password'])->firstOrFail();
    getUser($user->id);
}
開發者ID:MathiasBrandt,項目名稱:spcl-e2014-project,代碼行數:7,代碼來源:users.php

示例3: render

 /**
  * Sets response body of appended data to be json_encoded
  *
  * @param int $status
  * @param array|null $data
  * @return void
  */
 public function render($status = 200, $data = array())
 {
     $data = array_merge(array('status' => $status), $this->all(), is_array($data) ? $data : array());
     if (isset($data['flash']) && is_object($data['flash'])) {
         $flash = $this->data->flash->getMessages();
         if (count($flash)) {
             $data['flash'] = $flash;
         } else {
             unset($data['flash']);
         }
     }
     // Nettoyage des accents des chaines de caractère à afficher
     array_walk($data, function (&$value, $key) {
         if (is_string($value)) {
             $value = $this->ascii_to_entities($value);
         }
     });
     $app = \Slim\Slim::getInstance();
     $response = $app->response();
     $response->status($status);
     $response->header('Content-Encoding', 'UTF-8');
     $response->header('Access-Control-Allow-Origin', '*');
     $response->header('Access-Control-Allow-Methods', '*');
     $response->header('Content-Type', 'application/json;charset=UTF-8');
     $response->body(html_entity_decode(json_encode($data, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT)));
 }
開發者ID:pierreleplatois,項目名稱:sialab,代碼行數:33,代碼來源:JsonView.php

示例4: Authenticate

 public static function Authenticate($route)
 {
     $app = \Slim\Slim::getInstance();
     try {
         $args = $route->getParam('args');
         if ($args && in_array($args[0], array('login', 'register', 'getlookups'))) {
             return;
         }
     } catch (Exception $e) {
     }
     if ($app->auth->getUser()) {
         return;
     }
     $username = $app->request()->headers('PHP_AUTH_USER');
     $password = $app->request()->headers('PHP_AUTH_PW');
     if (false && isset($username) && isset($password)) {
         $rs = $app->orm->user->where(array('user_number' => $username, 'password ' => $password))->limit(1);
         if (count($rs)) {
             $user = $app->orm->toArray($rs)[0];
             if ($user) {
                 unset($user['password']);
                 $app->auth->setUser($user);
                 $app->session->set('_auth_', $app->auth->getUser());
                 return;
             }
         }
     } else {
         $user = $app->session->get('_auth_');
         if ($user) {
             $app->auth->setUser($user);
             return;
         }
     }
     $app->writeJSON(null, 401, 'Unauthorized');
 }
開發者ID:aodkrisda,項目名稱:mayotin,代碼行數:35,代碼來源:api.php

示例5: authenticate

function authenticate(\Slim\Route $route)
{
    $app = \Slim\Slim::getInstance();
    if (API_TOKEN != $_POST['token']) {
        $app->halt(401);
    }
}
開發者ID:aabsharpasha,項目名稱:schoolapp,代碼行數:7,代碼來源:index.php

示例6: query

 public function query($dql, $page_size = 10, $current_page = 1)
 {
     $app = Slim::getInstance();
     $query = $app->em->createQuery($dql)->setFirstResult($page_size * ($current_page - 1))->setMaxResults($page_size);
     $paginator = new Paginator($query);
     return $paginator;
 }
開發者ID:semplon,項目名稱:mabes,代碼行數:7,代碼來源:CommonBehavior.php

示例7: save_event

 /**
  * Save an event to the database. If an id is given, the existing event is
  * updated, if not a new one is created. The event will be stored in the
  * events table and all properties given as arrays are stored in the
  * accompanying junction table.
  *
  * @param $event - map of an event with the following keys
  *                 - title => the title of the event
  *                 - summary => the summary of the post mortem
  *                 - starttime => start time as unix timestamp
  *                 - endtime   => end time as unix timestamp
  *                 - statustime => status time as unix timestamp
  *                 - detecttime  => detect time as unix timestamp
  * @param $conn - PDO connection object, will be newly instantiated when
  *                null (default: null)
  *
  * @returns the event map including an "id" field on success and a map of the
  * form ( "id" => null, "error" => "an error message" ) on failure
  */
 static function save_event($event, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     if (is_null($conn)) {
         return array("id" => null, "error" => "Couldn't get connection object.");
     }
     $action = isset($event["id"]) ? self::ACTION_EDIT : self::ACTION_ADD;
     if ($action == self::ACTION_ADD) {
         $now = new DateTime(null, new DateTimeZone('UTC'));
         $event["created"] = $now->getTimestamp();
     }
     $event = Persistence::save_event($event, $conn);
     if (is_null($event["id"])) {
         return $event;
     }
     if ($action == self::ACTION_ADD) {
         $app = \Slim\Slim::getInstance();
         $env = $app->environment;
         $admin = $env['admin']['username'];
         $result = Postmortem::add_history($event["id"], $admin, $action);
     }
     // close connection and return
     $conn = null;
     return $event;
 }
開發者ID:nlsun,項目名稱:morgue,代碼行數:44,代碼來源:Postmortem.php

示例8: render

 public function render($status = 200, $data = NULL)
 {
     $app = \Slim\Slim::getInstance();
     $status = (int) $status;
     $response = $this->all();
     //add flash messages
     if (isset($this->data->flash) && is_object($this->data->flash)) {
         $flash = $this->data->flash->getMessages();
         if (count($flash)) {
             $response['flash'] = $flash;
         } else {
             unset($response['flash']);
         }
     }
     // if $response array contains only one scalar value, extract it
     if (isset($response[0]) && count($response) === 1 && is_scalar($response[0])) {
         $response = $response[0];
     }
     $app->response()->status($status);
     $app->response()->header('Content-Type', $this->contentType);
     $jsonp_callback = $app->request->get('callback', null);
     if ($jsonp_callback !== null) {
         $app->response()->body($jsonp_callback . '(' . json_encode($response, $this->encodingOptions) . ')');
     } else {
         $app->response()->body(json_encode($response, $this->encodingOptions));
     }
     $app->stop();
 }
開發者ID:tscheckenbach,項目名稱:slim-json-api,代碼行數:28,代碼來源:JsonApiView.php

示例9: fetch

 /**
  * Fetch an L10n content string
  *
  * @param $key      string  YAML key of the desired text string
  * @param $language string  Optionally override the desired language
  * @return mixed
  */
 public static function fetch($key, $language = null, $lower = false)
 {
     $app = \Slim\Slim::getInstance();
     $language = $language ? $language : Config::getCurrentLanguage();
     $value = $key;
     /*
     |--------------------------------------------------------------------------
     | Check for new language
     |--------------------------------------------------------------------------
     |
     | English is loaded by default. If requesting a language not already
     | cached, go grab it.
     |
     */
     if (!isset($app->config['_translations'][$language])) {
         $app->config['_translations'][$language] = YAML::parse(Config::getTranslation($language));
     }
     /*
     |--------------------------------------------------------------------------
     | Resolve translation
     |--------------------------------------------------------------------------
     |
     | If the set language is found and the key exists, return it. Falls back to
     | English, and then falls back to the slug-style key itself.
     |
     */
     if (array_get($app->config['_translations'][$language]['translations'], $value, false)) {
         $value = array_get($app->config['_translations'][$language]['translations'], $value);
     } else {
         $value = array_get($app->config['_translations']['en']['translations'], $value, $value);
     }
     return $lower ? strtolower($value) : $value;
 }
開發者ID:nob,項目名稱:joi,代碼行數:40,代碼來源:localization.php

示例10: getLoggedInMember

 /**
  * Checks to see if a user is currently logged in
  * 
  * @return Member|null
  */
 public static function getLoggedInMember()
 {
     // grab the cookie
     $app = \Slim\Slim::getInstance();
     $cookie = $app->getEncryptedCookie('stat_auth_cookie');
     if (strpos($cookie, ':') === false) {
         return null;
     }
     // break it into parts and create the Member object
     list($username, $hash) = explode(":", $cookie);
     $member = self::getMember($username);
     // was a Member object found?
     if ($member) {
         $hash = self::createHash($member);
         // compare the stored hash to a fresh one, do they match?
         if ($cookie === $hash) {
             // they match, Member is valid, extend lifetime
             $expire = $app->config['_cookies.lifetime'];
             $app->setEncryptedCookie('stat_auth_cookie', $cookie, $expire);
             // return the Member object
             return $member;
         }
     }
     // something above went wrong, return null
     return null;
 }
開發者ID:Synergy23,項目名稱:RealEstate,代碼行數:31,代碼來源:auth.php

示例11: getHandler

 public function getHandler($conn)
 {
     Context::clear();
     $app = \Slim\Slim::getInstance();
     $credentials = $conn->WebSocket->request->getQuery()->toArray();
     //
     // Aparently, this doesn't work as expected.
     //
     // set x-auth-token
     if (isset($credentials['X-Auth-Token'])) {
         $app->request->headers->set('X-Auth-Token', $credentials['X-Auth-Token']);
         unset($credentials['X-Auth-Token']);
     }
     // remove "/" and possible "ws/" from resource path
     $resource = str_replace("ws/", "", substr($conn->WebSocket->request->getPath(), 1));
     $hash = md5($resource . join(",", array_values($credentials)));
     if (!isset($this->handlers[$hash])) {
         if ($key = Model\AppKey::where('app_id', $credentials['X-App-Id'])->where('key', $credentials['X-App-Key'])->first()) {
             Context::setKey($key);
             $channel = Model\Module::channel($resource);
             if ($channel) {
                 $this->handlers[$hash] = $channel->compile();
             }
         }
     }
     return isset($this->handlers[$hash]) ? $this->handlers[$hash] : null;
 }
開發者ID:CFLOVEYR,項目名稱:hook,代碼行數:27,代碼來源:server.php

示例12: authenticate

/**
 * Adding Middle Layer to authenticate every request
 * Checking if the request has valid api key in the 'Authorization' header
 */
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'])) {
        $db = new DBHandler();
        // get the api key
        $apikey = $headers['Authorization'];
        // validating api key
        if (!$db->isValidApiKey($apikey)) {
            // api key is not present in users table
            $response["error"] = true;
            $response["message"] = "Zugriff verweigert! Falscher API-Key!";
            echoRespnse(401, $response);
            $app->stop();
        } else {
            global $userid;
            // get user primary key id
            $user = $db->getUserId($apikey);
            if ($user != NULL) {
                $userid = $user;
            }
        }
    } else {
        // api key is missing in header
        $response["error"] = true;
        $response["message"] = "Zugriff verweigert! API-Key fehlt!";
        echoRespnse(400, $response);
        $app->stop();
    }
}
開發者ID:dvogt23,項目名稱:KartApp-www,代碼行數:38,代碼來源:index.php

示例13: render

 /**
  * Renders the template.
  *
  * @param string $template The HTTP status code.
  * @param null $data Not used.
  * @return string|void
  */
 public function render($status, $data = null)
 {
     $app = \Slim\Slim::getInstance();
     $app->contentType('application/json');
     $app->expires(0);
     $app->response()->setStatus(intval($status));
     $response = ['status' => $status];
     $error = $this->data->get('error', false);
     switch ($status) {
         case 404:
             $error = $error ? $error : 'Resource not found';
             break;
         case 500:
             $error = $error ? $error : 'Server Error';
             break;
     }
     if ($error) {
         $response['error'] = $error;
     }
     $keys = $this->data->keys();
     unset($keys[array_search('flash', $keys)]);
     foreach ($keys as $key) {
         $response[$key] = $this->data->get($key);
     }
     $app->response()->body(json_encode($response, JSON_NUMERIC_CHECK));
 }
開發者ID:nextglory,項目名稱:CacoCloud,代碼行數:33,代碼來源:JsonView.php

示例14: checkAdminAuthorization

function checkAdminAuthorization()
{
    $app = \Slim\Slim::getInstance();
    if ($app->userHelper->checkAdminAuthorization() != true) {
        $app->halt(403, "You have to have admin rights.");
    }
}
開發者ID:V3N0m21,項目名稱:Uppu4,代碼行數:7,代碼來源:index.php

示例15: auth

function auth(){
   	
	$app2 = \Slim\Slim::getInstance();
        $req=$app2->request();
        $key=$req->get('key');
        $key=md5($key);
        if($key==''){
                $app2->render (401,array('msg'=>'Key incorrecto','error'=>'true'));
        }

        $conn = mysqli_connect('127.0.0.1','root','155070847','monitoreo');
        if (!$conn) {
                die("Connection failed: " . mysqli_connect_error());
        }
        $sql="select * from users where pass='".$key."'";

        $result = mysqli_query($conn,$sql);
        $row_cnt = mysqli_num_rows($result);

        if($row_cnt == 0)
                $app2->render (401,array('msg'=>'Key incorrecto','error'=>'true'));

	mysqli_close($conn);


}
開發者ID:norberfaraz,項目名稱:api-rest,代碼行數:26,代碼來源:auth.php


注:本文中的Slim\Slim::getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。