Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
SharedDocuments.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 
7 namespace Dcp\Core;
8 /**
9  * Manage Shared documents through the global array $gdocs
10  */
12 {
13  protected static $limit = MAXGDOCS;
14  /**
15  * @return int
16  */
17  public static function getLimit()
18  {
19  return self::$limit;
20  }
21  /**
22  * @param int $limit
23  * @throws \Dcp\Exception
24  */
25  public static function setLimit($limit)
26  {
27  if (!is_int($limit)) {
28  throw new \Dcp\Exception("SharedDocuments limit must be a integer");
29  }
30  self::$limit = $limit;
31  }
32  /**
33  * Retrieve object from key identifier
34  * @param string $key document identifier
35  * @return \Doc|null
36  */
37  public static function &get($key)
38  {
39  global $gdocs;
40  if (!isset($gdocs)) {
41  $gdocs = array();
42  }
43  $null = null;
44  if ($key === '' or $key === null or (!is_scalar($key))) {
45  return $null;
46  }
47  if ($gdocs && array_key_exists($key, $gdocs)) {
48  return $gdocs[$key];
49  }
50  return $null;
51  }
52 
53  /**
54  * Add or update an object
55  * @param string $key object identifier
56  * @param \Doc $item object to add or update
57  * @param bool $force set to true to add without limits
58  * @return bool
59  */
60  public static function set($key, &$item, $force = false)
61  {
62  global $gdocs;
63  if (!isset($gdocs)) {
64  $gdocs = array();
65  }
66  if ($key === '' or $key === null or (!is_scalar($key))) {
67  return false;
68  }
69  if (count($gdocs) < self::$limit || $force === true) {
70  $gdocs[$key] = & $item;
71  return true;
72  }
73 
74  return false;
75  }
76  /**
77  * Unset object
78  * @param string $key object identifier
79  * @return bool
80  */
81  public static function remove($key)
82  {
83  global $gdocs;
84  if (!isset($gdocs)) {
85  $gdocs = array();
86  }
87  if ($key === '' or $key === null or (!is_scalar($key))) {
88  return false;
89  }
90  unset($gdocs[$key]);
91  return true;
92  }
93  /**
94  * unset all objects referenced in shared object
95  * @return bool
96  */
97  public static function clear()
98  {
99  global $gdocs;
100  $gdocs = array();
101  return true;
102  }
103  /**
104  * Return all keys referenced in shared object
105  * @return array referenced keys returns
106  */
107  public static function getKeys()
108  {
109  global $gdocs;
110  if (!isset($gdocs)) {
111  $gdocs = array();
112  }
113  return array_keys($gdocs);
114  }
115  /**
116  * Verify if a key is referenced in shared object
117  * @param string $key object identifier
118  * @return bool
119  */
120  public static function exists($key)
121  {
122  global $gdocs;
123  if (!isset($gdocs)) {
124  $gdocs = array();
125  }
126  return array_key_exists($key, $gdocs);
127  }
128  /**
129  * Verify if a key is referenced in cached and object is same as item object
130  * @param string $key object identifier
131  * @param \Doc $item object item
132  * @return bool true if $key and item match
133  */
134  public static function isShared($key, &$item)
135  {
136  global $gdocs;
137  if (!isset($gdocs)) {
138  $gdocs = array();
139  }
140  if ($key === '' or $key === null or (!is_scalar($key))) {
141  return false;
142  }
143  return (isset($gdocs[$key]) && $gdocs[$key] === $item);
144  }
145 }
static isShared($key, &$item)
static set($key, &$item, $force=false)
$force
const MAXGDOCS
Definition: Class.Doc.php:51
$null
← centre documentaire © anakeen