CrossPHP
  • Namespace
  • Class
  • Download

Namespaces

  • Cross
    • Auth
    • Cache
      • Driver
      • Request
    • Core
    • DB
      • Connecter
      • Drivers
      • SQLAssembler
    • Exception
    • Http
    • I
    • Lib
      • Document
    • Module
    • MVC
    • Runtime
  • None

Classes

  • Cross\Auth\CookieAuth
  • Cross\Auth\SessionAuth
  • Cross\Cache\Driver\FileCacheDriver
  • Cross\Cache\Driver\MemcacheDriver
  • Cross\Cache\Driver\RedisDriver
  • Cross\Cache\Request\FileCache
  • Cross\Cache\Request\Memcache
  • Cross\Cache\Request\RedisCache
  • Cross\Cache\RequestCache
  • Cross\Core\Annotate
  • Cross\Core\Application
  • Cross\Core\ArrayMap
  • Cross\Core\Config
  • Cross\Core\CrossArray
  • Cross\Core\Delegate
  • Cross\Core\FrameBase
  • Cross\Core\Helper
  • Cross\Core\HttpAuth
  • Cross\Core\Loader
  • Cross\Core\Rest
  • Cross\Core\Router
  • Cross\DB\Connecter\BaseConnecter
  • Cross\DB\Connecter\MySQLConnecter
  • Cross\DB\Connecter\PgSQLConnecter
  • Cross\DB\Connecter\SQLiteConnecter
  • Cross\DB\DBFactory
  • Cross\DB\Drivers\CouchDriver
  • Cross\DB\Drivers\MongoDriver
  • Cross\DB\Drivers\PDOSqlDriver
  • Cross\DB\SQLAssembler\MySQLAssembler
  • Cross\DB\SQLAssembler\PgSQLAssembler
  • Cross\DB\SQLAssembler\SQLAssembler
  • Cross\DB\SQLAssembler\SQLiteAssembler
  • Cross\Http\Request
  • Cross\Http\Response
  • Cross\Lib\Array2XML
  • Cross\Lib\Document\CallTree
  • Cross\Lib\Document\CallTreeToHTML
  • Cross\Lib\Document\HTML
  • Cross\Lib\StringToPHPStream
  • Cross\Module\SQLModule
  • Cross\MVC\Controller
  • Cross\MVC\Module
  • Cross\MVC\View
  • Cross\Runtime\ClosureContainer

Interfaces

  • Cross\I\CacheInterface
  • Cross\I\HttpAuthInterface
  • Cross\I\PDOConnecter
  • Cross\I\RequestCacheInterface
  • Cross\I\RouterInterface
  • Cross\I\SqlInterface

Exceptions

  • Cross\Exception\CacheException
  • Cross\Exception\CoreException
  • Cross\Exception\CrossException
  • Cross\Exception\FrontException

Functions

  • ascLogo
  • line
  • tBody
  • th
  • tHead
 1 <?php
 2 /**
 3  * Cross - a micro PHP 5 framework
 4  *
 5  * @link        http://www.crossphp.com
 6  * @license     MIT License
 7  */
 8 
 9 namespace Cross\Core;
10 
11 use Cross\Auth\CookieAuth;
12 use Cross\Auth\SessionAuth;
13 use Cross\Exception\CoreException;
14 use Cross\I\HttpAuthInterface;
15 use ReflectionClass;
16 
17 /**
18  * @author wonli <wonli@live.com>
19  * Class HttpAuth
20  * @package Cross\Core
21  */
22 class HttpAuth
23 {
24     /**
25      * @var CookieAuth|SessionAuth|HttpAuthInterface|object
26      */
27     static $obj;
28 
29     /**
30      * 创建用于会话管理的对象
31      *
32      * @param string|object $type
33      * <pre>
34      *  type 默认为字符串(COOKIE|SESSION|包含命名空间的类的路径)
35      *  也可以是一个实现了HttpAuthInterface接口的对象
36      * </pre>
37      *
38      * @param string $auth_key 指定加密key
39      * @return CookieAuth|SessionAuth|HttpAuthInterface|object
40      * @throws CoreException
41      */
42     public static function factory($type = 'COOKIE', $auth_key = '')
43     {
44         if (!self::$obj) {
45             if (is_string($type)) {
46                 if (strcasecmp($type, 'cookie') == 0) {
47                     self::$obj = new CookieAuth($auth_key);
48                 } elseif (strcasecmp($type, 'session') == 0) {
49                     self::$obj = new SessionAuth($auth_key);
50                 } else {
51                     try {
52                         $object = new ReflectionClass($type);
53                         if ($object->implementsInterface('Cross\I\HttpAuthInterface')) {
54                             self::$obj = $object->newInstance();
55                         } else {
56                             throw new CoreException('会话管理类必须实现HttpAuthInterface接口');
57                         }
58                     } catch (\Exception $e) {
59                         throw new CoreException('Reflection ' . $e->getMessage());
60                     }
61                 }
62             } elseif (is_object($type)) {
63                 if ($type instanceof HttpAuthInterface) {
64                     self::$obj = $type;
65                 } else {
66                     throw new CoreException('会话管理类必须实现HttpAuthInterface接口');
67                 }
68             } else {
69                 throw new CoreException('无法识别的会话管理类');
70             }
71         }
72         return self::$obj;
73     }
74 }
75 
CrossPHP API documentation generated by ApiGen