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 namespace Cross\Core;
  9 
 10 /**
 11  * @author wonli <wonli@live.com>
 12  * Class CrossArray
 13  * @package Cross\Core
 14  */
 15 class CrossArray
 16 {
 17     /**
 18      * @var array 数据
 19      */
 20     protected $data;
 21 
 22     /**
 23      * @var self
 24      */
 25     protected static $instance;
 26 
 27     /**
 28      * CrossArray
 29      *
 30      * @param array $data
 31      */
 32     private function __construct(array &$data)
 33     {
 34         $this->data = &$data;
 35     }
 36 
 37     /**
 38      * @param array $data
 39      * @param string $cache_key
 40      * @return CrossArray
 41      */
 42     static function init(array &$data, $cache_key = null)
 43     {
 44         if (null === $cache_key) {
 45             $cache_key = md5(json_encode($data));
 46         }
 47 
 48         if (!isset(self::$instance[$cache_key])) {
 49             self::$instance[$cache_key] = new self($data);
 50         }
 51 
 52         return self::$instance[$cache_key];
 53     }
 54 
 55     /**
 56      * 获取配置参数
 57      *
 58      * @param string $config
 59      * @param string|array $name
 60      * @return bool|string|array
 61      */
 62     function get($config, $name = '')
 63     {
 64         if (isset($this->data[$config])) {
 65             if ($name) {
 66                 if (is_array($name)) {
 67                     $result = array();
 68                     foreach ($name as $n) {
 69                         if (isset($this->data[$config][$n])) {
 70                             $result[$n] = $this->data[$config][$n];
 71                         }
 72                     }
 73                     return $result;
 74                 } elseif (isset($this->data[$config][$name])) {
 75                     return $this->data[$config][$name];
 76                 }
 77 
 78                 return false;
 79             }
 80 
 81             return $this->data[$config];
 82         }
 83         return false;
 84     }
 85 
 86     /**
 87      * 更新成员或赋值
 88      *
 89      * @param string $index
 90      * @param string|array $values
 91      * @return bool
 92      */
 93     function set($index, $values = '')
 94     {
 95         if (is_array($values)) {
 96             if (isset($this->data[$index])) {
 97                 $this->data[$index] = array_merge($this->data[$index], $values);
 98             } else {
 99                 $this->data[$index] = $values;
100             }
101         } else {
102             $this->data[$index] = $values;
103         }
104 
105         return true;
106     }
107 
108     /**
109      * 返回全部数据
110      *
111      * @param bool $obj 是否返回对象
112      * @return array|object
113      */
114     function getAll($obj = false)
115     {
116         if ($obj) {
117             return self::arrayToObject($this->data);
118         }
119 
120         return $this->data;
121     }
122 
123     /**
124      * 数组转对象
125      *
126      * @param $data
127      * @return object|string
128      */
129     static function arrayToObject($data)
130     {
131         if (is_array($data)) {
132             return (object)array_map('self::arrayToObject', $data);
133         } else {
134             return $data;
135         }
136     }
137 }
138 
CrossPHP API documentation generated by ApiGen