Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Cookie.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\HttpFoundation;
013
014 /**
015 * Represents a cookie.
016 *
017 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
018 */
019 class Cookie
020 {
021 protected $name;
022 protected $value;
023 protected $domain;
024 protected $expire;
025 protected $path;
026 protected $secure;
027 protected $httpOnly;
028
029 /**
030 * Constructor.
031 *
032 * @param string $name The name of the cookie
033 * @param string $value The value of the cookie
034 * @param int|string|\DateTime|\DateTimeInterface $expire The time the cookie expires
035 * @param string $path The path on the server in which the cookie will be available on
036 * @param string $domain The domain that the cookie is available to
037 * @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
038 * @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol
039 *
040 * @throws \InvalidArgumentException
041 */
042 public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true)
043 {
044 // from PHP source code
045 if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
046 throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
047 }
048
049 if (empty($name)) {
050 throw new \InvalidArgumentException('The cookie name cannot be empty.');
051 }
052
053 // convert expiration time to a Unix timestamp
054 if ($expire instanceof \DateTime || $expire instanceof \DateTimeInterface) {
055 $expire = $expire->format('U');
056 } elseif (!is_numeric($expire)) {
057 $expire = strtotime($expire);
058
059 if (false === $expire || -1 === $expire) {
060 throw new \InvalidArgumentException('The cookie expiration time is not valid.');
061 }
062 }
063
064 $this->name = $name;
065 $this->value = $value;
066 $this->domain = $domain;
067 $this->expire = $expire;
068 $this->path = empty($path) ? '/' : $path;
069 $this->secure = (bool) $secure;
070 $this->httpOnly = (bool) $httpOnly;
071 }
072
073 /**
074 * Returns the cookie as a string.
075 *
076 * @return string The cookie
077 */
078 public function __toString()
079 {
080 $str = urlencode($this->getName()).'=';
081
082 if ('' === (string) $this->getValue()) {
083 $str .= 'deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001);
084 } else {
085 $str .= urlencode($this->getValue());
086
087 if ($this->getExpiresTime() !== 0) {
088 $str .= '; expires='.gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime());
089 }
090 }
091
092 if ($this->path) {
093 $str .= '; path='.$this->path;
094 }
095
096 if ($this->getDomain()) {
097 $str .= '; domain='.$this->getDomain();
098 }
099
100 if (true === $this->isSecure()) {
101 $str .= '; secure';
102 }
103
104 if (true === $this->isHttpOnly()) {
105 $str .= '; httponly';
106 }
107
108 return $str;
109 }
110
111 /**
112 * Gets the name of the cookie.
113 *
114 * @return string
115 */
116 public function getName()
117 {
118 return $this->name;
119 }
120
121 /**
122 * Gets the value of the cookie.
123 *
124 * @return string
125 */
126 public function getValue()
127 {
128 return $this->value;
129 }
130
131 /**
132 * Gets the domain that the cookie is available to.
133 *
134 * @return string
135 */
136 public function getDomain()
137 {
138 return $this->domain;
139 }
140
141 /**
142 * Gets the time the cookie expires.
143 *
144 * @return int
145 */
146 public function getExpiresTime()
147 {
148 return $this->expire;
149 }
150
151 /**
152 * Gets the path on the server in which the cookie will be available on.
153 *
154 * @return string
155 */
156 public function getPath()
157 {
158 return $this->path;
159 }
160
161 /**
162 * Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.
163 *
164 * @return bool
165 */
166 public function isSecure()
167 {
168 return $this->secure;
169 }
170
171 /**
172 * Checks whether the cookie will be made accessible only through the HTTP protocol.
173 *
174 * @return bool
175 */
176 public function isHttpOnly()
177 {
178 return $this->httpOnly;
179 }
180
181 /**
182 * Whether this cookie is about to be cleared.
183 *
184 * @return bool
185 */
186 public function isCleared()
187 {
188 return $this->expire < time();
189 }
190 }
191