当前位置: 首页>>代码示例>>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;未经允许,请勿转载。