Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit 77d070a

Browse files
committed
format codes
1 parent 5756538 commit 77d070a

26 files changed

+1229
-1217
lines changed

src/auth/User.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use inhere\librarys\collections\SimpleCollection;
1212
use inhere\librarys\helpers\ObjectHelper;
13-
use Psr\Http\Message\ResponseInterface;
1413
use inhere\exceptions\InvalidArgumentException;
1514
use inhere\exceptions\InvalidConfigException;
1615

@@ -25,7 +24,7 @@ class User extends SimpleCollection
2524
/**
2625
* @var string
2726
*/
28-
protected static $saveKey = '_slim_auth';
27+
protected static $saveKey = '_user_auth_data';
2928

3029
/**
3130
* Exclude fields that don't need to be saved.
@@ -260,7 +259,7 @@ public function sets(array $data)
260259
*/
261260
public function getAccessChecker()
262261
{
263-
return $this->accessChecker ? : \Slim::get('accessChecker');
262+
return $this->accessChecker; // ? : \Slim::get('accessChecker');
264263
}
265264

266265
/**

src/collections/ActiveData.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function all($toArray = false)
8787

8888
/**
8989
* 以点连接 快速获取子级节点的值
90-
* @param $name
90+
* @param array|string $name
9191
* @return ActiveData|null
9292
*/
9393
public function get($name)
@@ -166,6 +166,15 @@ public function offsetUnset($offset)
166166
unset($this->$offset);
167167
}
168168

169+
public function __isset($name)
170+
{
171+
return $this->offsetExists($name);
172+
}
173+
174+
public function __set($name, $value)
175+
{
176+
}
177+
169178
public function __get($name)
170179
{
171180
return $this->get($name);

src/collections/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Config extends DataCollector
4848
/**
4949
* __construct
5050
* @param mixed $data If mode is 'folder', $data is config folder path
51-
* @param array $options
51+
* @param array|string $options
5252
* @param string $name
5353
*/
5454
public function __construct($data = [], $options = [], $name = 'config')

src/collections/DataCollector.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
*/
3939
class DataCollector extends SimpleCollection
4040
{
41-
/**
42-
* data
43-
* @var array
44-
*/
45-
protected $data = [];
46-
4741
/**
4842
* @var array
4943
*/
@@ -159,22 +153,13 @@ public function clear()
159153
return $this->reset();
160154
}
161155

162-
public function toObject($class = 'stdClass')
163-
{
164-
return static::dataToObject($this->data, $class);
165-
}
166-
167156
/**
168-
* get all Data
169-
* @return array
157+
* @param $class
158+
* @return mixed
170159
*/
171-
public function all()
160+
public function toObject($class = \stdClass::class)
172161
{
173-
return $this->data;
174-
}
175-
public function toArray()
176-
{
177-
return $this->all();
162+
return static::dataToObject($this->data, $class);
178163
}
179164

180165
/**
@@ -513,11 +498,11 @@ public static function dataToArray($data, $recursive = false)
513498
}
514499

515500
/**
516-
* @param $array
501+
* @param array $array
517502
* @param string $class
518503
* @return mixed
519504
*/
520-
public static function dataToObject($array, $class = 'stdClass')
505+
public static function dataToObject($array, $class = \stdClass::class)
521506
{
522507
$object = new $class;
523508

@@ -609,7 +594,7 @@ public static function parseYaml($data, $supportImport=false, callable $pathHand
609594

610595
// if needed custom handle $importFile path. e.g: Maybe it uses custom alias path
611596
if ( $pathHandler && is_callable($pathHandler) ) {
612-
$importFile = call_user_func($pathHandler, $importFile);
597+
$importFile = $pathHandler($importFile);
613598
}
614599

615600
// if $importFile is not exists AND $importFile is not a absolute path AND have $parentFile

src/collections/SimpleCollection.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ public function all()
127127
{
128128
return $this->data;
129129
}
130-
131130
public function toArray()
132131
{
133132
return $this->all();

src/di/ContainerManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static public function share($id, $service, $name='')
166166
* @param string $name 容器名称
167167
* @param array $params
168168
* @param int $bindType
169-
* @return null|object
169+
* @return mixed
170170
*/
171171
static public function get($id, $name='', array $params=[], $bindType=self::OVERLOAD_PARAM)
172172
{
@@ -182,7 +182,7 @@ static public function get($id, $name='', array $params=[], $bindType=self::OVER
182182
* @param string $name
183183
* @param array $params
184184
* @param int $bindType
185-
* @return null|object
185+
* @return mixed
186186
*/
187187
static public function getNew($id, $name='', array $params=[], $bindType=self::OVERLOAD_PARAM)
188188
{

src/di/Service.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616
*/
1717
class Service
1818
{
19+
/**
20+
* @var callable
21+
*/
1922
protected $callback;
2023

21-
protected $instance = null;
24+
protected $instance;
2225

26+
/**
27+
* @var array
28+
*/
2329
protected $arguments = [];
2430

2531
/**
@@ -173,4 +179,4 @@ public function isShared()
173179
{
174180
return $this->shared;
175181
}
176-
}
182+
}
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Time: 9:22
77
*/
88

9-
namespace inhere\librarys\traits;
9+
namespace inhere\librarys\di;
1010

1111
/**
1212
* Class TraitSimpleContainer
@@ -33,7 +33,7 @@ trait TraitSimpleContainer
3333
/**
3434
* register a app service
3535
* @param string $name the service name
36-
* @param object|\Closure $service service
36+
* @param mixed $service service
3737
* @param bool $replace replace exists service
3838
* @return static
3939
*/
@@ -47,7 +47,7 @@ public function register($name, $service, $replace = false)
4747
/**
4848
* register a app service
4949
* @param string $name
50-
* @param object $service
50+
* @param mixed $service service
5151
* @param bool $replace replace exists service
5252
* @return bool
5353
*/
@@ -109,7 +109,7 @@ public function raw($name)
109109
* create a app service by name
110110
* it always return a new instance.
111111
* @param string $name
112-
* @return object
112+
* @return mixed
113113
*/
114114
public function factory($name)
115115
{
@@ -143,6 +143,11 @@ public function getServiceNames()
143143
return array_keys(self::$services);
144144
}
145145

146+
public function __isset($name)
147+
{
148+
return $this->has($name);
149+
}
150+
146151
/**
147152
* allow register a app service by property
148153
* ```
@@ -151,7 +156,7 @@ public function getServiceNames()
151156
* };
152157
* ```
153158
* @param string $name
154-
* @param object $service
159+
* @param mixed $service
155160
* @return bool
156161
*/
157162
public function __set($name, $service)
@@ -165,10 +170,10 @@ public function __set($name, $service)
165170
* $logger = Micro::$me->logger;
166171
* ```
167172
* @param string $name service name
168-
* @return object
173+
* @return mixed
169174
*/
170175
public function __get($name)
171176
{
172177
return $this->get($name);
173178
}
174-
}
179+
}

src/env/Client.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ public function init()
110110

111111
protected function _handleInfo($info)
112112
{
113-
return array_map(function($val)
114-
{
115-
return trim(strpos($val,';') ? strchr($val,';', true) : $val);
113+
return array_map(function($val) {
114+
return trim(strpos($val,';') ? strstr($val,';', true) : $val);
116115
},
117116
(array) explode(',', $info)
118117
);
@@ -138,7 +137,7 @@ protected function _handleInfo($info)
138137
*
139138
* ]
140139
*/
141-
private $_headers = null;
140+
private $_headers;
142141

143142
/**
144143
* @return array|false|null
@@ -152,7 +151,7 @@ public function getHeaders()
152151
$this->_headers = http_get_request_headers();
153152
} else {
154153
foreach ($_SERVER as $name => $value) {
155-
if ( $name = $this->_nameConver($name)) {
154+
if ( $name = $this->_nameConvert($name)) {
156155
$this->_headers[$name] = $value;
157156
}
158157
}
@@ -185,14 +184,14 @@ public function getHeader($name, $default = null)
185184

186185
// HTTP_X_TOKEN => xToken
187186
// HTTP_USER_AGENT => userAgent
188-
protected function _nameConver($string)
187+
protected function _nameConvert($string)
189188
{
190189
// if ( !strpos($string, '_') ) {
191190
// return strtolower($string);
192191
// }
193192

194193
if ( strpos($string,'HTTP_')!==false ) {
195-
$string = substr($string, strlen('HTTP_'));
194+
$string = substr($string, strlen('HTTP_'));
196195
} else {
197196
return false;
198197
}
@@ -239,9 +238,9 @@ protected function _userAgentCheck()
239238
//// system check
240239
// $isLinux = $isMac = $isAndroid = false;
241240

242-
if (preg_match('/win/i', $agent)) {
243-
241+
if (false !== strpos($agent, 'win') ) {
244242
$this->set('isWin', true);
243+
$os = 'Windows other';
245244

246245
if (preg_match('/nt 6.0/i', $agent)) {
247246
$os = 'Windows Vista';
@@ -255,10 +254,7 @@ protected function _userAgentCheck()
255254
$os = 'Windows XP';
256255
} else if (preg_match('/nt 5/i', $agent)) {
257256
$os = 'Windows 2000';
258-
} else {
259-
$os = 'Windows other';
260257
}
261-
262258
} elseif (strpos($agent, 'linux')) {
263259

264260
if (strpos($agent, 'android')) {
@@ -340,7 +336,7 @@ protected function _userAgentCheck()
340336
* @from web
341337
* @return string
342338
*/
343-
public function getIP()
339+
public function getIp()
344340
{
345341
$ip = '';
346342

@@ -366,4 +362,4 @@ public function getBrowsers()
366362
return get_browser($this->get('userAgent'),true);
367363
}
368364

369-
}// end class Client
365+
}// end class Client

src/env/Server.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public function init()
104104
'os' => PHP_OS,
105105
'osShort' => strtoupper(substr(PHP_OS, 0, 3)),
106106
'isUnix' => $this->isUnix(),
107-
])->set('isWin', $this->get('osShort') == 'WIN')
108-
->set('isLinux', $this->get('osShort') == 'LIN');
107+
])->set('isWin', $this->get('osShort') === 'Win')
108+
->set('isLinux', $this->get('osShort') === 'Lin');
109109
}
110110

111111
/**
@@ -162,9 +162,9 @@ public static function value($name, $default = '')
162162
*/
163163
public function isUnix()
164164
{
165-
$unames = array('CYG', 'DAR', 'FRE', 'HP-', 'IRI', 'LIN', 'NET', 'OPE', 'SUN', 'UNI');
165+
$uNames = array('CYG', 'DAR', 'FRE', 'HP-', 'IRI', 'LIN', 'NET', 'OPE', 'SUN', 'UNI');
166166

167-
return in_array($this->get('osShort'), $unames);
167+
return in_array($this->get('osShort'), $uNames);
168168
}
169169

170170
/**

0 commit comments

Comments
 (0)