-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split some class. remove inhere\library package
- Loading branch information
Showing
21 changed files
with
1,785 additions
and
967 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: inhere | ||
* Date: 2017/10/21 | ||
* Time: 下午2:04 | ||
*/ | ||
|
||
namespace Inhere\Http; | ||
|
||
/** | ||
* Class Collection | ||
* @package Inhere\Http | ||
*/ | ||
class Collection extends \ArrayObject | ||
{ | ||
public function sets(array $values) | ||
{ | ||
$this->replace($values); | ||
} | ||
|
||
/** | ||
* @param array $items | ||
*/ | ||
public function replace(array $items) | ||
{ | ||
foreach ($items as $key => $value) { | ||
$this->set($key, $value); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param null $default | ||
* @return mixed|null | ||
*/ | ||
public function get(string $name, $default = null) | ||
{ | ||
return $this[$name] ?? $default; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $value | ||
* @return mixed|null | ||
*/ | ||
public function add($name, $value) | ||
{ | ||
if (isset($this[$name])) { | ||
return null; | ||
} | ||
|
||
$this[$name] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $value | ||
* @return mixed|null | ||
*/ | ||
public function set($name, $value) | ||
{ | ||
return $this[$name] = $value; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function all() | ||
{ | ||
return $this->getArrayCopy(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function has(string $key) | ||
{ | ||
return array_key_exists($key, $this->data); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function remove($key) | ||
{ | ||
if (isset($this[$key])) { | ||
$val = $this[$key]; | ||
unset($this[$key]); | ||
|
||
return $val; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* clear all data | ||
*/ | ||
public function clear() | ||
{ | ||
foreach ($this as $key) { | ||
unset($this[$key]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: inhere | ||
* Date: 2017/10/21 | ||
* Time: 下午1:18 | ||
*/ | ||
|
||
namespace Inhere\Http; | ||
|
||
/** | ||
* Trait CookiesTrait | ||
* @package Inhere\Http | ||
*/ | ||
trait CookiesTrait | ||
{ | ||
/** | ||
* @var Cookies | ||
*/ | ||
private $cookies; | ||
|
||
/******************************************************************************* | ||
* Cookies | ||
******************************************************************************/ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getCookieParams() | ||
{ | ||
return $this->cookies->all(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getCookieParam($key, $default = null) | ||
{ | ||
return $this->cookies->get($key, $default); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function withCookieParams(array $cookies) | ||
{ | ||
$clone = clone $this; | ||
$clone->cookies = new Cookies($cookies); | ||
|
||
return $clone; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param string|array $value | ||
* @return $this | ||
*/ | ||
public function setCookie(string $name, $value) | ||
{ | ||
$this->cookies->set($name, $value); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Cookies | ||
*/ | ||
public function getCookies(): Cookies | ||
{ | ||
return $this->cookies; | ||
} | ||
|
||
/** | ||
* @param Cookies|array $cookies | ||
* @return $this | ||
*/ | ||
public function setCookies($cookies) | ||
{ | ||
if (is_array($cookies)) { | ||
return $this->setCookiesFromArray($cookies); | ||
} | ||
|
||
$this->cookies = $cookies; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $cookies | ||
* @return $this | ||
*/ | ||
public function setCookiesFromArray(array $cookies) | ||
{ | ||
if (!$this->cookies) { | ||
$this->cookies = new Cookies($cookies); | ||
} else { | ||
$this->cookies->sets($cookies); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.