Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Oct 31, 2019
1 parent 1763272 commit 21ec585
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/Server/Route/RouteCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ public function getCallable($params = [])
$methodName = $this->methodName;
foreach($params as $name => $value)
{
$className = str_replace('{$' . $name . '}', $value, $className);
$methodName = str_replace('{$' . $name . '}', $value, $methodName);
$search = '{$' . $name . '}';
if(false !== strpos($className, $search))
{
$className = str_replace($search, $value, $className);
}
if(false !== strpos($methodName, $search))
{
$methodName = str_replace($search, $value, $methodName);
}
}
return [$this->server->getBean($className), $methodName];
}
Expand Down
20 changes: 8 additions & 12 deletions src/Util/ArrayData.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ public function set($name, $value = null)
*/
public function setVal($name, $value = null)
{
$type = gettype($name);
if('string' === $type)
if(is_string($name))
{
$name = explode('.', $name);
}
else if('array' !== $type)
else if(!is_array($name))
{
return false;
}
Expand Down Expand Up @@ -79,20 +78,18 @@ public function &get($name = null, $default = false)
{
return $this->data;
}
$type = gettype($name);
if('string' === $type)
if(is_string($name))
{
$name = explode('.', $name);
}
else if('array' !== $type)
else if(!is_array($name))
{
return $default;
}
$result = &$this->data;
foreach ($name as $value)
{
$type = gettype($result);
if('array' === $type)
if(is_array($result))
{
// 数组
if (isset($result[$value]))
Expand All @@ -104,7 +101,7 @@ public function &get($name = null, $default = false)
return $default;
}
}
else if('object' === $type)
else if(is_object($result))
{
// 对象
if (property_exists($result, $value))
Expand Down Expand Up @@ -143,12 +140,11 @@ public function remove($name)
}
foreach($name as $val)
{
$type = gettype($val);
if('string' === $type)
if(is_string($val))
{
$val = explode('.', $val);
}
else if('array' !== $type)
else if(!is_array($val))
{
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Util/ObjectArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public static function get(&$object, $name, $default = null)
$result = &$object;
foreach ($names as $nameItem)
{
$type = gettype($result);
if('array' === $type)
if(is_array($result))
{
// 数组
if (isset($result[$nameItem]))
Expand All @@ -34,7 +33,7 @@ public static function get(&$object, $name, $default = null)
return $default;
}
}
else if('object' === $type)
else if(is_object($result))
{
// 对象
if (isset($result->$nameItem))
Expand Down

0 comments on commit 21ec585

Please sign in to comment.