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


PHP UserFactory::getInstance方法代碼示例

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


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

示例1: invoke

 public function invoke()
 {
     $return = "";
     if (!isset($_GET['method'])) {
         $return = '{ "error": "No se envió un método" }';
     } else {
         switch ($_GET['method']) {
             case 'register':
                 $_SESSION["user"] = UserFactory::getInstance()->register($_GET['email'], $_GET['password'], 3);
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $return = json_encode($_SESSION["user"]->getUserData());
                 } else {
                     $return = '{ "logged": false, "error": "Ya existe un usuario registrado con ese email" }';
                 }
                 break;
             case 'create':
                 $name = $_GET['name'];
                 $email = $_GET['email'];
                 $type = $_GET['type'];
                 $password = $_GET['password'];
                 $user = UserFactory::getInstance()->create($email, $name, $password, $type);
                 if (isset($user) && $user) {
                     $return = '{ "status": "ok", "message": "Se creó el usuario" }';
                 } else {
                     $return = '{ "logged": false, "error": "Ya existe un usuario registrado con ese email" }';
                 }
                 break;
             case 'login':
                 $_SESSION["user"] = UserFactory::getInstance()->login($_GET['email'], $_GET['password']);
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $return = json_encode($_SESSION["user"]->getUserData());
                 } else {
                     $return = '{ "logged": false, "error": "Error de email / password" }';
                 }
                 break;
             case 'users':
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $uq = $_SESSION["user"]->getUserQueries();
                     $rows = $uq->getUserList();
                     $result = $uq->fetch_all($rows);
                     /*$result = array();
                       while ($row = $rows->fetch_assoc()) {
                           array_push($result, $row);
                       }
                       $rows->free();*/
                     //$result = $rows->fetch_all(MYSQLI_ASSOC);
                     $return = json_encode($result);
                     //$rows->free();
                 } else {
                     $return = '{ "logged": false, "error": "Error obteniendo los usuarios" }';
                 }
                 break;
             case 'user':
                 if (isset($_SESSION["user"]) && $_SESSION["user"] && isset($_GET["id"])) {
                     $rows = $_SESSION["user"]->getUserQueries()->getUserById($_GET["id"]);
                     /*$result = array();
                       while ($row = $rows->fetch_assoc()) {
                           array_push($result, $row);
                       }
                       $rows->free();
                       $return = json_encode($result);*/
                     $result = $rows->fetch_object(MYSQLI_ASSOC);
                     $return = json_encode($result);
                     $rows->free();
                 } else {
                     $return = '{ "logged": false, "error": "Error obteniendo el usuario" }';
                 }
                 break;
             case 'update':
                 if (isset($_SESSION["user"]) && $_SESSION["user"] && isset($_GET["id"])) {
                     $email = $_GET["email"];
                     $id = $_GET["id"];
                     $name = $_GET["name"];
                     $password = $_GET["password"];
                     $active = $_GET["active"];
                     $type = $_GET["type"];
                     $rows = $_SESSION["user"]->getUserQueries()->updateUser($email, $id, $name, $password, $active, $type);
                     $return = json_encode($rows);
                 } else {
                     $return = '{ "logged": false, "error": "Error actualizando el usuario" }';
                 }
                 break;
             case 'toggle':
                 if (isset($_SESSION["user"]) && $_SESSION["user"] && isset($_GET["id"])) {
                     $id = $_GET["id"];
                     $active = $_GET["active"];
                     $rows = $_SESSION["user"]->getUserQueries()->toggleUser($id, $active);
                     $return = json_encode($rows);
                 } else {
                     $return = '{ "logged": false, "error": "Error actualizando el usuario" }';
                 }
                 break;
             case 'check':
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $return = json_encode($_SESSION["user"]->getUserData());
                 } else {
                     $return = '{ "logged": false, "error": "No se ha iniciado sesión" }';
                 }
                 break;
             case 'logout':
//.........這裏部分代碼省略.........
開發者ID:CookieQuartet,項目名稱:eventosmdp,代碼行數:101,代碼來源:UserController.php

示例2: session_start

<?php

include_once 'User.php';
include_once 'userAdmin/UserAdmin.php';
include_once 'userGeneral/UserGeneral.php';
include_once 'userPublisher/UserPublisher.php';
include_once 'userType/UserTypeEnum.php';
include_once 'UserFactory.php';
session_start();
include_once './UserController.php';
if (!isset($_SESSION["userFactory"])) {
    $_SESSION["userFactory"] = UserFactory::getInstance();
}
$controller = new UserController($_SESSION["userFactory"]);
$controller->invoke();
開發者ID:CookieQuartet,項目名稱:eventosmdp,代碼行數:15,代碼來源:UserAPI.php

示例3: getUserByID

        return self::$instance;
    }
    // End Singleton Methods
    public function getUserByID($id)
    {
        $db = DB::getInstance();
        $result = $db->query("SELECT ID, Name, Email, Access FROM User WHERE ID = ?", array($id));
        if (empty($result) || count($result) != 1) {
            return FALSE;
        }
        // Idiot Check - We should only have 1 user for that ID
        $user = new User();
        $result = $result[0];
        foreach ($result as $key => $value) {
            $user->{$key} = $value;
        }
        return $user;
    }
}
Config::$dbuser = 'db';
Config::$dbpass = 'db';
Config::$dbhost = 'localhost';
Config::$dbname = 'test';
// now pretend this is in a controller
$userfactory = UserFactory::getInstance();
$user = $userfactory->getUserByID(1);
if ($user->isAdmin()) {
    echo "Woot! you're an admin!";
} else {
    echo "You're a pleb";
}
開發者ID:hemantshekhawat,項目名稱:Snippets,代碼行數:31,代碼來源:basicmvc.php


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