@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param boolean $verbose =false true: echo failed checks |
29 | 29 | * @return int number of failed checks |
30 | 30 | */ |
31 | - function check($verbose=false) |
|
31 | + function check($verbose = false) |
|
32 | 32 | { |
33 | 33 | // set us up as provider for Api\Cache class |
34 | 34 | $GLOBALS['egw_info']['server']['install_id'] = md5(microtime(true)); |
@@ -37,27 +37,27 @@ discard block |
||
37 | 37 | Api\Cache::$default_provider = get_class($this); |
38 | 38 | |
39 | 39 | $failed = 0; |
40 | - foreach(array( |
|
40 | + foreach (array( |
|
41 | 41 | Api\Cache::TREE => 'tree', |
42 | 42 | Api\Cache::INSTANCE => 'instance', |
43 | 43 | ) as $level => $label) |
44 | 44 | { |
45 | 45 | $locations = array(); |
46 | - foreach(array('string',123,true,false,null,array(),array(1,2,3)) as $data) |
|
46 | + foreach (array('string', 123, true, false, null, array(), array(1, 2, 3)) as $data) |
|
47 | 47 | { |
48 | 48 | $location = md5(microtime(true).$label.serialize($data)); |
49 | - $get_before_set = $this->get(array($level,__CLASS__,$location)); |
|
49 | + $get_before_set = $this->get(array($level, __CLASS__, $location)); |
|
50 | 50 | if (!is_null($get_before_set)) |
51 | 51 | { |
52 | 52 | if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
53 | 53 | ++$failed; |
54 | 54 | } |
55 | - if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
|
55 | + if (($set = $this->set(array($level, __CLASS__, $location), $data, 10)) !== true) |
|
56 | 56 | { |
57 | 57 | if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
58 | 58 | ++$failed; |
59 | 59 | } |
60 | - $get_after_set = $this->get(array($level,__CLASS__,$location)); |
|
60 | + $get_after_set = $this->get(array($level, __CLASS__, $location)); |
|
61 | 61 | if ($get_after_set !== $data) |
62 | 62 | { |
63 | 63 | if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | } |
66 | 66 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
67 | 67 | { |
68 | - $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
|
68 | + $mget_after_set = $this->mget(array($level, __CLASS__, array($location))); |
|
69 | 69 | if ($mget_after_set[$location] !== $data) |
70 | 70 | { |
71 | 71 | if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
72 | 72 | ++$failed; |
73 | 73 | } |
74 | 74 | } |
75 | - $add_after_set = $this->add(array($level,__CLASS__,$location), 'other-data'); |
|
75 | + $add_after_set = $this->add(array($level, __CLASS__, $location), 'other-data'); |
|
76 | 76 | if ($add_after_set !== false) |
77 | 77 | { |
78 | 78 | if ($verbose) echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
79 | 79 | ++$failed; |
80 | 80 | } |
81 | - if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
|
81 | + if (($delete = $this->delete(array($level, __CLASS__, $location))) !== true) |
|
82 | 82 | { |
83 | 83 | if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
84 | 84 | ++$failed; |
85 | 85 | } |
86 | - $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
|
86 | + $get_after_delete = $this->get(array($level, __CLASS__, $location)); |
|
87 | 87 | if (!is_null($get_after_delete)) |
88 | 88 | { |
89 | 89 | if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
94 | 94 | { |
95 | 95 | $locations[$location] = $data; |
96 | - $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
|
96 | + $mget_after_delete = $this->mget(array($level, __CLASS__, array($location))); |
|
97 | 97 | if (isset($mget_after_delete[$location])) |
98 | 98 | { |
99 | 99 | if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | $locations[$location] = $data; |
106 | 106 | } |
107 | - $add_after_delete = $this->add(array($level,__CLASS__,$location), $data, 10); |
|
107 | + $add_after_delete = $this->add(array($level, __CLASS__, $location), $data, 10); |
|
108 | 108 | if ($add_after_delete !== true) |
109 | 109 | { |
110 | 110 | if ($verbose) echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | else |
114 | 114 | { |
115 | - $get_after_add = $this->get(array($level,__CLASS__,$location)); |
|
115 | + $get_after_add = $this->get(array($level, __CLASS__, $location)); |
|
116 | 116 | if ($get_after_add !== $data) |
117 | 117 | { |
118 | 118 | if ($verbose) echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | } |
123 | 123 | // get all above in one request |
124 | 124 | $keys = array_keys($locations); |
125 | - $keys_bogus = array_merge(array('not-set'),array_keys($locations),array('not-set-too')); |
|
125 | + $keys_bogus = array_merge(array('not-set'), array_keys($locations), array('not-set-too')); |
|
126 | 126 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
127 | 127 | { |
128 | - $mget = $this->mget(array($level,__CLASS__,$keys)); |
|
129 | - $mget_bogus = $this->mget(array($level,__CLASS__,$keys_bogus)); |
|
128 | + $mget = $this->mget(array($level, __CLASS__, $keys)); |
|
129 | + $mget_bogus = $this->mget(array($level, __CLASS__, $keys_bogus)); |
|
130 | 130 | /* Api\Cache::getCache() gives a different result, as it does NOT use $level direkt |
131 | 131 | } |
132 | 132 | else |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | function flush(array $keys) |
162 | 162 | { |
163 | - unset($keys); // required by function signature |
|
163 | + unset($keys); // required by function signature |
|
164 | 164 | return false; |
165 | 165 | } |
166 | 166 | } |
@@ -49,18 +49,27 @@ discard block |
||
49 | 49 | $get_before_set = $this->get(array($level,__CLASS__,$location)); |
50 | 50 | if (!is_null($get_before_set)) |
51 | 51 | { |
52 | - if ($verbose) echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
|
52 | + if ($verbose) |
|
53 | + { |
|
54 | + echo "$label: get_before_set=".array2string($get_before_set)." != NULL\n"; |
|
55 | + } |
|
53 | 56 | ++$failed; |
54 | 57 | } |
55 | 58 | if (($set = $this->set(array($level,__CLASS__,$location), $data, 10)) !== true) |
56 | 59 | { |
57 | - if ($verbose) echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
|
60 | + if ($verbose) |
|
61 | + { |
|
62 | + echo "$label: set returned ".array2string($set)." !== TRUE\n"; |
|
63 | + } |
|
58 | 64 | ++$failed; |
59 | 65 | } |
60 | 66 | $get_after_set = $this->get(array($level,__CLASS__,$location)); |
61 | 67 | if ($get_after_set !== $data) |
62 | 68 | { |
63 | - if ($verbose) echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
|
69 | + if ($verbose) |
|
70 | + { |
|
71 | + echo "$label: get_after_set=".array2string($get_after_set)." !== ".array2string($data)."\n"; |
|
72 | + } |
|
64 | 73 | ++$failed; |
65 | 74 | } |
66 | 75 | if (is_a($this, 'EGroupware\Api\Cache\ProviderMultiple')) |
@@ -68,25 +77,37 @@ discard block |
||
68 | 77 | $mget_after_set = $this->mget(array($level,__CLASS__,array($location))); |
69 | 78 | if ($mget_after_set[$location] !== $data) |
70 | 79 | { |
71 | - if ($verbose) echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
|
80 | + if ($verbose) |
|
81 | + { |
|
82 | + echo "$label: mget_after_set['$location']=".array2string($mget_after_set[$location])." !== ".array2string($data)."\n"; |
|
83 | + } |
|
72 | 84 | ++$failed; |
73 | 85 | } |
74 | 86 | } |
75 | 87 | $add_after_set = $this->add(array($level,__CLASS__,$location), 'other-data'); |
76 | 88 | if ($add_after_set !== false) |
77 | 89 | { |
78 | - if ($verbose) echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
|
90 | + if ($verbose) |
|
91 | + { |
|
92 | + echo "$label: add_after_set=".array2string($add_after_set)."\n"; |
|
93 | + } |
|
79 | 94 | ++$failed; |
80 | 95 | } |
81 | 96 | if (($delete = $this->delete(array($level,__CLASS__,$location))) !== true) |
82 | 97 | { |
83 | - if ($verbose) echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
|
98 | + if ($verbose) |
|
99 | + { |
|
100 | + echo "$label: delete returned ".array2string($delete)." !== TRUE\n"; |
|
101 | + } |
|
84 | 102 | ++$failed; |
85 | 103 | } |
86 | 104 | $get_after_delete = $this->get(array($level,__CLASS__,$location)); |
87 | 105 | if (!is_null($get_after_delete)) |
88 | 106 | { |
89 | - if ($verbose) echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
|
107 | + if ($verbose) |
|
108 | + { |
|
109 | + echo "$label: get_after_delete=".array2string($get_after_delete)." != NULL\n"; |
|
110 | + } |
|
90 | 111 | ++$failed; |
91 | 112 | } |
92 | 113 | // prepare for mget of everything |
@@ -96,18 +117,27 @@ discard block |
||
96 | 117 | $mget_after_delete = $this->mget(array($level,__CLASS__,array($location))); |
97 | 118 | if (isset($mget_after_delete[$location])) |
98 | 119 | { |
99 | - if ($verbose) echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
|
120 | + if ($verbose) |
|
121 | + { |
|
122 | + echo "$label: mget_after_delete['$location']=".array2string($mget_after_delete[$location])." != NULL\n"; |
|
123 | + } |
|
100 | 124 | ++$failed; |
101 | 125 | } |
102 | 126 | } |
103 | - elseif (!is_null($data)) // emulation can NOT distinquish between null and not set |
|
127 | + elseif (!is_null($data)) |
|
128 | + { |
|
129 | + // emulation can NOT distinquish between null and not set |
|
104 | 130 | { |
105 | 131 | $locations[$location] = $data; |
106 | 132 | } |
133 | + } |
|
107 | 134 | $add_after_delete = $this->add(array($level,__CLASS__,$location), $data, 10); |
108 | 135 | if ($add_after_delete !== true) |
109 | 136 | { |
110 | - if ($verbose) echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
|
137 | + if ($verbose) |
|
138 | + { |
|
139 | + echo "$label: add_after_delete=".array2string($add_after_delete)."\n"; |
|
140 | + } |
|
111 | 141 | ++$failed; |
112 | 142 | } |
113 | 143 | else |
@@ -115,7 +145,10 @@ discard block |
||
115 | 145 | $get_after_add = $this->get(array($level,__CLASS__,$location)); |
116 | 146 | if ($get_after_add !== $data) |
117 | 147 | { |
118 | - if ($verbose) echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
|
148 | + if ($verbose) |
|
149 | + { |
|
150 | + echo "$label: get_after_add=".array2string($get_after_add)." !== ".array2string($data)."\n"; |
|
151 | + } |
|
119 | 152 | ++$failed; |
120 | 153 | } |
121 | 154 | } |
@@ -136,12 +169,18 @@ discard block |
||
136 | 169 | }*/ |
137 | 170 | if ($mget !== $locations) |
138 | 171 | { |
139 | - if ($verbose) echo "$label: mget=\n".array2string($mget)." !==\n".array2string($locations)."\n"; |
|
172 | + if ($verbose) |
|
173 | + { |
|
174 | + echo "$label: mget=\n".array2string($mget)." !==\n".array2string($locations)."\n"; |
|
175 | + } |
|
140 | 176 | ++$failed; |
141 | 177 | } |
142 | 178 | if ($mget_bogus !== $locations) |
143 | 179 | { |
144 | - if ($verbose) echo "$label: mget(".array2string($keys_bogus).")=\n".array2string($mget_bogus)." !==\n".array2string($locations)."\n"; |
|
180 | + if ($verbose) |
|
181 | + { |
|
182 | + echo "$label: mget(".array2string($keys_bogus).")=\n".array2string($mget_bogus)." !==\n".array2string($locations)."\n"; |
|
183 | + } |
|
145 | 184 | ++$failed; |
146 | 185 | } |
147 | 186 | } |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * "timeout" in ms, "retry" on node failure 0: no retry (default), 1: retry on set/add/delete, 2: allways retry |
58 | 58 | * "prefix" prefix for keys |
59 | 59 | */ |
60 | - function __construct(array $params=null) |
|
60 | + function __construct(array $params = null) |
|
61 | 61 | { |
62 | - $this->params = $params ? $params : array('localhost'); // some reasonable default |
|
62 | + $this->params = $params ? $params : array('localhost'); // some reasonable default |
|
63 | 63 | |
64 | 64 | if (isset($params['timeout'])) |
65 | 65 | { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | unset($params['prefix']); |
78 | 78 | } |
79 | 79 | |
80 | - check_load_extension('memcached',true); |
|
80 | + check_load_extension('memcached', true); |
|
81 | 81 | // using a persitent connection for identical $params |
82 | 82 | $this->memcache = new \Memcached(md5(serialize($params))); |
83 | 83 | |
@@ -103,18 +103,18 @@ discard block |
||
103 | 103 | if (!count($this->memcache->getServerList())) |
104 | 104 | { |
105 | 105 | $ok = false; |
106 | - foreach($params as $host_port) |
|
106 | + foreach ($params as $host_port) |
|
107 | 107 | { |
108 | - $parts = explode(':',$host_port); |
|
108 | + $parts = explode(':', $host_port); |
|
109 | 109 | $host = array_shift($parts); |
110 | - $port = $parts ? array_shift($parts) : 11211; // default port |
|
110 | + $port = $parts ? array_shift($parts) : 11211; // default port |
|
111 | 111 | |
112 | - $ok = $this->memcache->addServer($host,$port) || $ok; |
|
112 | + $ok = $this->memcache->addServer($host, $port) || $ok; |
|
113 | 113 | //error_log(__METHOD__."(".array2string($params).") memcache->addServer('$host',$port) = ".(int)$ok); |
114 | 114 | } |
115 | 115 | if (!$ok) |
116 | 116 | { |
117 | - throw new Exception (__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
117 | + throw new Exception(__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
118 | 118 | } |
119 | 119 | //error_log(__METHOD__."(".array2string($params).") creating new pool / persitent connection"); |
120 | 120 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param int $expiration =0 |
130 | 130 | * @return boolean true on success, false on error, incl. key already exists in cache |
131 | 131 | */ |
132 | - function add(array $keys,$data,$expiration=0) |
|
132 | + function add(array $keys, $data, $expiration = 0) |
|
133 | 133 | { |
134 | 134 | return $this->memcache->add(self::key($keys), $data, $expiration) || |
135 | 135 | // if we have multiple nodes, retry on error, but not on data exists |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param int $expiration =0 |
146 | 146 | * @return boolean true on success, false on error |
147 | 147 | */ |
148 | - function set(array $keys,$data,$expiration=0) |
|
148 | + function set(array $keys, $data, $expiration = 0) |
|
149 | 149 | { |
150 | 150 | return $this->memcache->set(self::key($keys), $data, $expiration) || |
151 | 151 | // if we have multiple nodes, retry on error |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | */ |
161 | 161 | function get(array $keys) |
162 | 162 | { |
163 | - if (($data = $this->memcache->get($key=self::key($keys))) === false && |
|
163 | + if (($data = $this->memcache->get($key = self::key($keys))) === false && |
|
164 | 164 | $this->memcache->getResultCode() !== \Memcached::RES_SUCCESS || |
165 | 165 | // if we have multiple nodes, retry on error, but not on not found |
166 | 166 | $this->retry > 1 && $this->memcache->getResultCode() !== \Memcached::RES_NOTFOUND && |
167 | - ($data = $this->memcache->get($key=self::key($keys))) === false && |
|
167 | + ($data = $this->memcache->get($key = self::key($keys))) === false && |
|
168 | 168 | $this->memcache->getResultCode() !== \Memcached::RES_SUCCESS) |
169 | 169 | { |
170 | 170 | //error_log(__METHOD__."(".array2string($keys).") key='$key' NOT found!".' $this->memcache->getResultCode()='.$this->memcache->getResultCode().')'); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | { |
185 | 185 | $locations = array_pop($keys); |
186 | 186 | $prefix = self::key($keys); |
187 | - foreach($locations as &$location) |
|
187 | + foreach ($locations as &$location) |
|
188 | 188 | { |
189 | 189 | $location = $prefix.'::'.$location; |
190 | 190 | } |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | return array(); |
197 | 197 | } |
198 | 198 | $ret = array(); |
199 | - $prefix_len = strlen($prefix)+2; |
|
200 | - foreach($multiple as $location => $data) |
|
199 | + $prefix_len = strlen($prefix) + 2; |
|
200 | + foreach ($multiple as $location => $data) |
|
201 | 201 | { |
202 | - $key = substr($location,$prefix_len); |
|
202 | + $key = substr($location, $prefix_len); |
|
203 | 203 | //error_log(__METHOD__."(".array2string($locations).") key='$key' found ".bytes($data)." bytes)."); |
204 | 204 | $ret[$key] = $data; |
205 | 205 | } |
@@ -227,6 +227,6 @@ discard block |
||
227 | 227 | */ |
228 | 228 | private function key(array $keys) |
229 | 229 | { |
230 | - return implode('::',$keys); |
|
230 | + return implode('::', $keys); |
|
231 | 231 | } |
232 | 232 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param int $expiration =0 |
39 | 39 | * @return boolean true on success, false on error, incl. key already exists in cache |
40 | 40 | */ |
41 | - function add(array $keys,$data,$expiration=0); |
|
41 | + function add(array $keys, $data, $expiration = 0); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Stores some data in the cache |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param int $expiration =0 |
49 | 49 | * @return boolean true on success, false on error |
50 | 50 | */ |
51 | - function set(array $keys,$data,$expiration=0); |
|
51 | + function set(array $keys, $data, $expiration = 0); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Get some data from the cache |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | $this->base_path = Api\Cache::get_system_config('temp_dir', false); |
53 | 53 | if (isset($this->base_path)) $this->base_path .= '/egw_cache'; |
54 | 54 | } |
55 | - if (!isset($this->base_path) || !file_exists($this->base_path) && !mkdir($this->base_path,0700,true)) |
|
55 | + if (!isset($this->base_path) || !file_exists($this->base_path) && !mkdir($this->base_path, 0700, true)) |
|
56 | 56 | { |
57 | - throw new Exception (__METHOD__."() can't create basepath $this->base_path!"); |
|
57 | + throw new Exception(__METHOD__."() can't create basepath $this->base_path!"); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | * @param int $expiration =0 |
67 | 67 | * @return boolean true on success, false on error, incl. key already exists in cache |
68 | 68 | */ |
69 | - function add(array $keys,$data,$expiration=0) |
|
69 | + function add(array $keys, $data, $expiration = 0) |
|
70 | 70 | { |
71 | 71 | // open only if file does NOT exist |
72 | - if (!($ret = fopen($fname=$this->filename($keys,true), 'x'))) |
|
72 | + if (!($ret = fopen($fname = $this->filename($keys, true), 'x'))) |
|
73 | 73 | { |
74 | 74 | // if file exists, check if it is expired |
75 | - if (file_exists($fname_expiration=$fname.self::EXPIRATION_EXTENSION) && |
|
75 | + if (file_exists($fname_expiration = $fname.self::EXPIRATION_EXTENSION) && |
|
76 | 76 | ($expiration = (int)file_get_contents($fname_expiration)) && |
77 | - filemtime($fname) < time()-$expiration) |
|
77 | + filemtime($fname) < time() - $expiration) |
|
78 | 78 | { |
79 | 79 | // open and truncate it |
80 | 80 | $ret = fopen($fname, 'w'); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | { |
87 | 87 | flock($ret, LOCK_EX); |
88 | 88 | $ok = fwrite($ret, serialize($data)); |
89 | - if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
89 | + if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION, (string)$expiration); |
|
90 | 90 | flock($ret, LOCK_UN); |
91 | 91 | fclose($ret); |
92 | 92 | $ret = $ok !== false; |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | * @param int $expiration =0 |
103 | 103 | * @return boolean true on success, false on error |
104 | 104 | */ |
105 | - function set(array $keys,$data,$expiration=0) |
|
105 | + function set(array $keys, $data, $expiration = 0) |
|
106 | 106 | { |
107 | - if (($ret = @file_put_contents($fname=$this->filename($keys,true),serialize($data),LOCK_EX) > 0)) |
|
107 | + if (($ret = @file_put_contents($fname = $this->filename($keys, true), serialize($data), LOCK_EX) > 0)) |
|
108 | 108 | { |
109 | - if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
109 | + if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION, (string)$expiration); |
|
110 | 110 | } |
111 | 111 | return $ret; |
112 | 112 | } |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | { |
124 | 124 | return null; |
125 | 125 | } |
126 | - if (file_exists($fname_expiration=$fname.self::EXPIRATION_EXTENSION) && |
|
126 | + if (file_exists($fname_expiration = $fname.self::EXPIRATION_EXTENSION) && |
|
127 | 127 | ($expiration = (int)file_get_contents($fname_expiration)) && |
128 | - filemtime($fname) < time()-$expiration) |
|
128 | + filemtime($fname) < time() - $expiration) |
|
129 | 129 | { |
130 | 130 | unlink($fname); |
131 | 131 | unlink($fname_expiration); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | //error_log(__METHOD__.'('.array2string($keys).") file_exists('$fname') == FALSE!"); |
148 | 148 | return false; |
149 | 149 | } |
150 | - if (file_exists($fname_expiration=$fname.self::EXPIRATION_EXTENSION)) |
|
150 | + if (file_exists($fname_expiration = $fname.self::EXPIRATION_EXTENSION)) |
|
151 | 151 | { |
152 | 152 | unlink($fname_expiration); |
153 | 153 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | return unlink($path); |
182 | 182 | } |
183 | - foreach(scandir($path) as $file) |
|
183 | + foreach (scandir($path) as $file) |
|
184 | 184 | { |
185 | 185 | if ($file == '.' || $file == '..') continue; |
186 | 186 | |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | * @param boolean $mkdir =false should we create the directory |
206 | 206 | * @return string |
207 | 207 | */ |
208 | - function filename(array $keys,$mkdir=false) |
|
208 | + function filename(array $keys, $mkdir = false) |
|
209 | 209 | { |
210 | - $fname = $this->base_path.'/'.str_replace(array(':','*'),'-',implode('/',$keys)); |
|
210 | + $fname = $this->base_path.'/'.str_replace(array(':', '*'), '-', implode('/', $keys)); |
|
211 | 211 | |
212 | - if ($mkdir && !file_exists($dirname=dirname($fname))) |
|
212 | + if ($mkdir && !file_exists($dirname = dirname($fname))) |
|
213 | 213 | { |
214 | - @mkdir($dirname,0700,true); |
|
214 | + @mkdir($dirname, 0700, true); |
|
215 | 215 | } |
216 | 216 | return $fname; |
217 | 217 | } |
@@ -50,7 +50,10 @@ discard block |
||
50 | 50 | else |
51 | 51 | { |
52 | 52 | $this->base_path = Api\Cache::get_system_config('temp_dir', false); |
53 | - if (isset($this->base_path)) $this->base_path .= '/egw_cache'; |
|
53 | + if (isset($this->base_path)) |
|
54 | + { |
|
55 | + $this->base_path .= '/egw_cache'; |
|
56 | + } |
|
54 | 57 | } |
55 | 58 | if (!isset($this->base_path) || !file_exists($this->base_path) && !mkdir($this->base_path,0700,true)) |
56 | 59 | { |
@@ -86,7 +89,10 @@ discard block |
||
86 | 89 | { |
87 | 90 | flock($ret, LOCK_EX); |
88 | 91 | $ok = fwrite($ret, serialize($data)); |
89 | - if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
92 | + if ((int)$expiration > 0) |
|
93 | + { |
|
94 | + file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
95 | + } |
|
90 | 96 | flock($ret, LOCK_UN); |
91 | 97 | fclose($ret); |
92 | 98 | $ret = $ok !== false; |
@@ -106,7 +112,10 @@ discard block |
||
106 | 112 | { |
107 | 113 | if (($ret = @file_put_contents($fname=$this->filename($keys,true),serialize($data),LOCK_EX) > 0)) |
108 | 114 | { |
109 | - if ((int)$expiration > 0) file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
115 | + if ((int)$expiration > 0) |
|
116 | + { |
|
117 | + file_put_contents($fname.self::EXPIRATION_EXTENSION,(string)$expiration); |
|
118 | + } |
|
110 | 119 | } |
111 | 120 | return $ret; |
112 | 121 | } |
@@ -182,17 +191,26 @@ discard block |
||
182 | 191 | } |
183 | 192 | foreach(scandir($path) as $file) |
184 | 193 | { |
185 | - if ($file == '.' || $file == '..') continue; |
|
194 | + if ($file == '.' || $file == '..') |
|
195 | + { |
|
196 | + continue; |
|
197 | + } |
|
186 | 198 | |
187 | 199 | $file = $path.'/'.$file; |
188 | 200 | |
189 | 201 | if (is_dir($file)) |
190 | 202 | { |
191 | - if (!self::rm_recursive($file)) return false; |
|
203 | + if (!self::rm_recursive($file)) |
|
204 | + { |
|
205 | + return false; |
|
206 | + } |
|
192 | 207 | } |
193 | 208 | else |
194 | 209 | { |
195 | - if (!unlink($file)) return false; |
|
210 | + if (!unlink($file)) |
|
211 | + { |
|
212 | + return false; |
|
213 | + } |
|
196 | 214 | } |
197 | 215 | } |
198 | 216 | return rmdir($path); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | if (!function_exists('apc_fetch')) // apc >= 3.0 |
48 | 48 | { |
49 | - throw new Exception (__METHOD__.'('.array2string($params).") No function apc_fetch()!"); |
|
49 | + throw new Exception(__METHOD__.'('.array2string($params).") No function apc_fetch()!"); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | // ancent APC (3.1.3) in Debian 6/Squezze has size in MB without a unit |
67 | 67 | if (is_numeric($size) && $size <= 1048576) $size .= 'M'; |
68 | 68 | |
69 | - switch(strtoupper(substr($size, -1))) |
|
69 | + switch (strtoupper(substr($size, -1))) |
|
70 | 70 | { |
71 | 71 | case 'G': |
72 | 72 | $size *= 1024; |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * @param int $expiration =0 |
93 | 93 | * @return boolean true on success, false on error, incl. key already exists in cache |
94 | 94 | */ |
95 | - function add(array $keys,$data,$expiration=0) |
|
95 | + function add(array $keys, $data, $expiration = 0) |
|
96 | 96 | { |
97 | - return apc_add(self::key($keys),$data,$expiration); |
|
97 | + return apc_add(self::key($keys), $data, $expiration); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param int $expiration =0 |
106 | 106 | * @return boolean true on success, false on error |
107 | 107 | */ |
108 | - function set(array $keys,$data,$expiration=0) |
|
108 | + function set(array $keys, $data, $expiration = 0) |
|
109 | 109 | { |
110 | - return apc_store(self::key($keys),$data,$expiration); |
|
110 | + return apc_store(self::key($keys), $data, $expiration); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function get(array $keys) |
120 | 120 | { |
121 | 121 | $success = null; |
122 | - $data = apc_fetch($key=self::key($keys),$success); |
|
122 | + $data = apc_fetch($key = self::key($keys), $success); |
|
123 | 123 | |
124 | 124 | if (!$success) |
125 | 125 | { |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | // APC >= 3.1.1, but also seems to be missing if apc is disabled eg. for cli |
153 | 153 | if (!class_exists('APCIterator')) |
154 | 154 | { |
155 | - if (function_exists('apc_clear_cache')) apc_clear_cache ('user'); |
|
155 | + if (function_exists('apc_clear_cache')) apc_clear_cache('user'); |
|
156 | 156 | |
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | //error_log(__METHOD__."(".array2string($keys).")"); |
160 | - foreach(new \APCIterator('user', $preg='/^'.preg_quote(self::key($keys).'/')) as $item) |
|
160 | + foreach (new \APCIterator('user', $preg = '/^'.preg_quote(self::key($keys).'/')) as $item) |
|
161 | 161 | { |
162 | 162 | //error_log(__METHOD__."(".array2string($keys).") preg='$preg': calling apc_delete('$item[key]')"); |
163 | 163 | apc_delete($item['key']); |
@@ -173,6 +173,6 @@ discard block |
||
173 | 173 | */ |
174 | 174 | private static function key(array $keys) |
175 | 175 | { |
176 | - return implode('::',$keys); |
|
176 | + return implode('::', $keys); |
|
177 | 177 | } |
178 | 178 | } |
@@ -44,10 +44,13 @@ discard block |
||
44 | 44 | */ |
45 | 45 | function __construct(array $params) |
46 | 46 | { |
47 | - if (!function_exists('apc_fetch')) // apc >= 3.0 |
|
47 | + if (!function_exists('apc_fetch')) |
|
48 | + { |
|
49 | + // apc >= 3.0 |
|
48 | 50 | { |
49 | 51 | throw new Exception (__METHOD__.'('.array2string($params).") No function apc_fetch()!"); |
50 | 52 | } |
53 | + } |
|
51 | 54 | } |
52 | 55 | |
53 | 56 | /** |
@@ -64,7 +67,10 @@ discard block |
||
64 | 67 | { |
65 | 68 | $size = ini_get('apc.shm_size'); |
66 | 69 | // ancent APC (3.1.3) in Debian 6/Squezze has size in MB without a unit |
67 | - if (is_numeric($size) && $size <= 1048576) $size .= 'M'; |
|
70 | + if (is_numeric($size) && $size <= 1048576) |
|
71 | + { |
|
72 | + $size .= 'M'; |
|
73 | + } |
|
68 | 74 | |
69 | 75 | switch(strtoupper(substr($size, -1))) |
70 | 76 | { |
@@ -152,7 +158,10 @@ discard block |
||
152 | 158 | // APC >= 3.1.1, but also seems to be missing if apc is disabled eg. for cli |
153 | 159 | if (!class_exists('APCIterator')) |
154 | 160 | { |
155 | - if (function_exists('apc_clear_cache')) apc_clear_cache ('user'); |
|
161 | + if (function_exists('apc_clear_cache')) |
|
162 | + { |
|
163 | + apc_clear_cache ('user'); |
|
164 | + } |
|
156 | 165 | |
157 | 166 | return false; |
158 | 167 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | * @param boolean $translated =true use translated name or english |
365 | 365 | * @return string |
366 | 366 | */ |
367 | - public static function get_full_name($code,$translated=true) |
|
367 | + public static function get_full_name($code, $translated = true) |
|
368 | 368 | { |
369 | 369 | if ($translated) |
370 | 370 | { |
@@ -383,36 +383,36 @@ discard block |
||
383 | 383 | */ |
384 | 384 | public static function country_code($name) |
385 | 385 | { |
386 | - if (!$name) return ''; // nothing to do |
|
386 | + if (!$name) return ''; // nothing to do |
|
387 | 387 | |
388 | 388 | if (strlen($name) == 2 && isset(self::$country_array[$name])) |
389 | 389 | { |
390 | - return $name; // $name is already a country-code |
|
390 | + return $name; // $name is already a country-code |
|
391 | 391 | } |
392 | 392 | |
393 | - if (($code = array_search(strtoupper($name),self::$country_array)) !== false) |
|
393 | + if (($code = array_search(strtoupper($name), self::$country_array)) !== false) |
|
394 | 394 | { |
395 | 395 | return $code; |
396 | 396 | } |
397 | 397 | if (!self::$countries_translated) self::_translate_countries(); |
398 | 398 | |
399 | - if (($code = array_search(strtoupper($name),self::$countries_translated)) !== false || |
|
400 | - ($code = array_search($name,self::$countries_translated)) !== false) |
|
399 | + if (($code = array_search(strtoupper($name), self::$countries_translated)) !== false || |
|
400 | + ($code = array_search($name, self::$countries_translated)) !== false) |
|
401 | 401 | { |
402 | 402 | return $code; |
403 | 403 | } |
404 | 404 | // search case-insensitive all translations for the english phrase of given country $name |
405 | 405 | // we do that to catch all possible cases of translations |
406 | - static $en_names = array(); // we do some caching to minimize db-accesses |
|
406 | + static $en_names = array(); // we do some caching to minimize db-accesses |
|
407 | 407 | if (isset($en_names[$name])) |
408 | 408 | { |
409 | 409 | $name = $en_names[$name]; |
410 | 410 | } |
411 | - elseif (($name_en = Translation::get_message_id($name,'common'))) |
|
411 | + elseif (($name_en = Translation::get_message_id($name, 'common'))) |
|
412 | 412 | { |
413 | 413 | $name = $en_names[$name] = strtoupper($name_en); |
414 | 414 | } |
415 | - if (($code = array_search(strtoupper($name),self::$country_array)) !== false) |
|
415 | + if (($code = array_search(strtoupper($name), self::$country_array)) !== false) |
|
416 | 416 | { |
417 | 417 | return $code; |
418 | 418 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | * @param boolean $translated =true use translated names or english |
426 | 426 | * @return array with 2-letter code => name pairs |
427 | 427 | */ |
428 | - public static function countries($translated=true) |
|
428 | + public static function countries($translated = true) |
|
429 | 429 | { |
430 | 430 | if ($translated) |
431 | 431 | { |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | |
448 | 448 | self::$countries_translated = self::$country_array; |
449 | 449 | // try to translate them and sort alphabetic |
450 | - foreach(self::$countries_translated as $k => $name) |
|
450 | + foreach (self::$countries_translated as $k => $name) |
|
451 | 451 | { |
452 | 452 | self::$countries_translated[$k] = lang($name); |
453 | 453 | } |
454 | 454 | |
455 | - if(class_exists('Collator') && class_exists('Locale')) |
|
455 | + if (class_exists('Collator') && class_exists('Locale')) |
|
456 | 456 | { |
457 | 457 | $col = new \Collator(Preferences::setlocale()); |
458 | 458 | $col->asort(self::$countries_translated); |
@@ -368,7 +368,10 @@ discard block |
||
368 | 368 | { |
369 | 369 | if ($translated) |
370 | 370 | { |
371 | - if (!self::$countries_translated) self::_translate_countries(); |
|
371 | + if (!self::$countries_translated) |
|
372 | + { |
|
373 | + self::_translate_countries(); |
|
374 | + } |
|
372 | 375 | |
373 | 376 | return self::$countries_translated[strtoupper($code)]; |
374 | 377 | } |
@@ -383,7 +386,11 @@ discard block |
||
383 | 386 | */ |
384 | 387 | public static function country_code($name) |
385 | 388 | { |
386 | - if (!$name) return ''; // nothing to do |
|
389 | + if (!$name) |
|
390 | + { |
|
391 | + return ''; |
|
392 | + } |
|
393 | + // nothing to do |
|
387 | 394 | |
388 | 395 | if (strlen($name) == 2 && isset(self::$country_array[$name])) |
389 | 396 | { |
@@ -394,7 +401,10 @@ discard block |
||
394 | 401 | { |
395 | 402 | return $code; |
396 | 403 | } |
397 | - if (!self::$countries_translated) self::_translate_countries(); |
|
404 | + if (!self::$countries_translated) |
|
405 | + { |
|
406 | + self::_translate_countries(); |
|
407 | + } |
|
398 | 408 | |
399 | 409 | if (($code = array_search(strtoupper($name),self::$countries_translated)) !== false || |
400 | 410 | ($code = array_search($name,self::$countries_translated)) !== false) |
@@ -429,7 +439,10 @@ discard block |
||
429 | 439 | { |
430 | 440 | if ($translated) |
431 | 441 | { |
432 | - if (!self::$countries_translated) self::_translate_countries(); |
|
442 | + if (!self::$countries_translated) |
|
443 | + { |
|
444 | + self::_translate_countries(); |
|
445 | + } |
|
433 | 446 | |
434 | 447 | return self::$countries_translated; |
435 | 448 | } |
@@ -443,7 +456,10 @@ discard block |
||
443 | 456 | */ |
444 | 457 | protected static function _translate_countries() |
445 | 458 | { |
446 | - if (self::$countries_translated) return; |
|
459 | + if (self::$countries_translated) |
|
460 | + { |
|
461 | + return; |
|
462 | + } |
|
447 | 463 | |
448 | 464 | self::$countries_translated = self::$country_array; |
449 | 465 | // try to translate them and sort alphabetic |
@@ -22,7 +22,7 @@ |
||
22 | 22 | /** |
23 | 23 | * Constructor |
24 | 24 | */ |
25 | - function __construct($primary='mail', $fallback='sql') |
|
25 | + function __construct($primary = 'mail', $fallback = 'sql') |
|
26 | 26 | { |
27 | 27 | parent::__construct($primary, $fallback); |
28 | 28 | } |
@@ -26,22 +26,22 @@ discard block |
||
26 | 26 | * @param string $passwd_type ='text' 'text' for cleartext passwords (default) |
27 | 27 | * @return boolean true if successful authenticated, false otherwise |
28 | 28 | */ |
29 | - function authenticate($username, $passwd, $passwd_type='text') |
|
29 | + function authenticate($username, $passwd, $passwd_type = 'text') |
|
30 | 30 | { |
31 | - unset($passwd_type); // not used but required by interface |
|
31 | + unset($passwd_type); // not used but required by interface |
|
32 | 32 | |
33 | 33 | $domain = yp_get_default_domain(); |
34 | - if(!empty($GLOBALS['egw_info']['server']['nis_domain'])) |
|
34 | + if (!empty($GLOBALS['egw_info']['server']['nis_domain'])) |
|
35 | 35 | { |
36 | 36 | $domain = $GLOBALS['egw_info']['server']['nis_domain']; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $map = "passwd.byname"; |
40 | - if(!empty($GLOBALS['egw_info']['server']['nis_map'])) |
|
40 | + if (!empty($GLOBALS['egw_info']['server']['nis_map'])) |
|
41 | 41 | { |
42 | 42 | $map = $GLOBALS['egw_info']['server']['nis_map']; |
43 | 43 | } |
44 | - $entry = yp_match( $domain, $map, $username ); |
|
44 | + $entry = yp_match($domain, $map, $username); |
|
45 | 45 | |
46 | 46 | /* |
47 | 47 | * we assume that the map is structured in the usual |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | * @param int $account_id =0 account id of user whose passwd should be changed |
64 | 64 | * @return boolean true if password successful changed, false otherwise |
65 | 65 | */ |
66 | - function change_password($old_passwd, $new_passwd, $account_id=0) |
|
66 | + function change_password($old_passwd, $new_passwd, $account_id = 0) |
|
67 | 67 | { |
68 | - unset($old_passwd, $new_passwd, $account_id); // not used but required by interface |
|
68 | + unset($old_passwd, $new_passwd, $account_id); // not used but required by interface |
|
69 | 69 | |
70 | 70 | // can't change passwords unless server runs as root (bad idea) |
71 | - return( False ); |
|
71 | + return(False); |
|
72 | 72 | } |
73 | 73 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param string $passwd_type ='text' 'text' for cleartext passwords (default) |
30 | 30 | * @return boolean true if successful authenticated, false otherwise |
31 | 31 | */ |
32 | - function authenticate($username, $passwd, $passwd_type='text') |
|
32 | + function authenticate($username, $passwd, $passwd_type = 'text') |
|
33 | 33 | { |
34 | - unset($username, $passwd, $passwd_type); // not used, but required by interface |
|
34 | + unset($username, $passwd, $passwd_type); // not used, but required by interface |
|
35 | 35 | |
36 | 36 | return isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] === $username; |
37 | 37 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * @param int $account_id account id of user whose passwd should be changed |
45 | 45 | * @return boolean true if password successful changed, false otherwise |
46 | 46 | */ |
47 | - function change_password($old_passwd, $new_passwd, $account_id=0) |
|
47 | + function change_password($old_passwd, $new_passwd, $account_id = 0) |
|
48 | 48 | { |
49 | - unset($old_passwd, $new_passwd, $account_id); // not used, but required by interface |
|
49 | + unset($old_passwd, $new_passwd, $account_id); // not used, but required by interface |
|
50 | 50 | |
51 | 51 | return False; |
52 | 52 | } |