Skip to content

Commit 73e355b

Browse files
committed
added http foundation.
1 parent 85dbb42 commit 73e355b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+9442
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation;
13+
14+
/**
15+
* Request represents an HTTP request from an Apache server.
16+
*
17+
* @author Fabien Potencier <fabien@symfony.com>
18+
*/
19+
class ApacheRequest extends Request
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function prepareRequestUri()
25+
{
26+
return $this->server->get('REQUEST_URI');
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
protected function prepareBaseUrl()
33+
{
34+
$baseUrl = $this->server->get('SCRIPT_NAME');
35+
36+
if (false === strpos($this->server->get('REQUEST_URI'), $baseUrl)) {
37+
// assume mod_rewrite
38+
return rtrim(dirname($baseUrl), '/\\');
39+
}
40+
41+
return $baseUrl;
42+
}
43+
44+
/**
45+
* {@inheritdoc}
46+
*/
47+
protected function preparePathInfo()
48+
{
49+
return $this->server->get('PATH_INFO') ?: substr($this->prepareRequestUri(), strlen($this->prepareBaseUrl())) ?: '/';
50+
}
51+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation;
13+
14+
/**
15+
* Represents a cookie
16+
*
17+
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
18+
*
19+
* @api
20+
*/
21+
class Cookie
22+
{
23+
protected $name;
24+
protected $value;
25+
protected $domain;
26+
protected $expire;
27+
protected $path;
28+
protected $secure;
29+
protected $httpOnly;
30+
31+
/**
32+
* Constructor.
33+
*
34+
* @param string $name The name of the cookie
35+
* @param string $value The value of the cookie
36+
* @param integer|string|\DateTime $expire The time the cookie expires
37+
* @param string $path The path on the server in which the cookie will be available on
38+
* @param string $domain The domain that the cookie is available to
39+
* @param Boolean $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
40+
* @param Boolean $httpOnly Whether the cookie will be made accessible only through the HTTP protocol
41+
*
42+
* @api
43+
*/
44+
public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true)
45+
{
46+
// from PHP source code
47+
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
48+
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
49+
}
50+
51+
if (empty($name)) {
52+
throw new \InvalidArgumentException('The cookie name cannot be empty.');
53+
}
54+
55+
// convert expiration time to a Unix timestamp
56+
if ($expire instanceof \DateTime) {
57+
$expire = $expire->format('U');
58+
} elseif (!is_numeric($expire)) {
59+
$expire = strtotime($expire);
60+
61+
if (false === $expire || -1 === $expire) {
62+
throw new \InvalidArgumentException('The cookie expiration time is not valid.');
63+
}
64+
}
65+
66+
$this->name = $name;
67+
$this->value = $value;
68+
$this->domain = $domain;
69+
$this->expire = $expire;
70+
$this->path = empty($path) ? '/' : $path;
71+
$this->secure = (Boolean) $secure;
72+
$this->httpOnly = (Boolean) $httpOnly;
73+
}
74+
75+
public function __toString()
76+
{
77+
$str = urlencode($this->getName()).'=';
78+
79+
if ('' === (string) $this->getValue()) {
80+
$str .= 'deleted; expires='.gmdate("D, d-M-Y H:i:s T", time() - 31536001);
81+
} else {
82+
$str .= urlencode($this->getValue());
83+
84+
if ($this->getExpiresTime() !== 0) {
85+
$str .= '; expires='.gmdate("D, d-M-Y H:i:s T", $this->getExpiresTime());
86+
}
87+
}
88+
89+
if ('/' !== $this->path) {
90+
$str .= '; path='.$this->path;
91+
}
92+
93+
if (null !== $this->getDomain()) {
94+
$str .= '; domain='.$this->getDomain();
95+
}
96+
97+
if (true === $this->isSecure()) {
98+
$str .= '; secure';
99+
}
100+
101+
if (true === $this->isHttpOnly()) {
102+
$str .= '; httponly';
103+
}
104+
105+
return $str;
106+
}
107+
108+
/**
109+
* Gets the name of the cookie.
110+
*
111+
* @return string
112+
*
113+
* @api
114+
*/
115+
public function getName()
116+
{
117+
return $this->name;
118+
}
119+
120+
/**
121+
* Gets the value of the cookie.
122+
*
123+
* @return string
124+
*
125+
* @api
126+
*/
127+
public function getValue()
128+
{
129+
return $this->value;
130+
}
131+
132+
/**
133+
* Gets the domain that the cookie is available to.
134+
*
135+
* @return string
136+
*
137+
* @api
138+
*/
139+
public function getDomain()
140+
{
141+
return $this->domain;
142+
}
143+
144+
/**
145+
* Gets the time the cookie expires.
146+
*
147+
* @return integer
148+
*
149+
* @api
150+
*/
151+
public function getExpiresTime()
152+
{
153+
return $this->expire;
154+
}
155+
156+
/**
157+
* Gets the path on the server in which the cookie will be available on.
158+
*
159+
* @return string
160+
*
161+
* @api
162+
*/
163+
public function getPath()
164+
{
165+
return $this->path;
166+
}
167+
168+
/**
169+
* Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.
170+
*
171+
* @return Boolean
172+
*
173+
* @api
174+
*/
175+
public function isSecure()
176+
{
177+
return $this->secure;
178+
}
179+
180+
/**
181+
* Checks whether the cookie will be made accessible only through the HTTP protocol.
182+
*
183+
* @return Boolean
184+
*
185+
* @api
186+
*/
187+
public function isHttpOnly()
188+
{
189+
return $this->httpOnly;
190+
}
191+
192+
/**
193+
* Whether this cookie is about to be cleared
194+
*
195+
* @return Boolean
196+
*
197+
* @api
198+
*/
199+
public function isCleared()
200+
{
201+
return $this->expire < time();
202+
}
203+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\File\Exception;
13+
14+
/**
15+
* Thrown when the access on a file was denied.
16+
*
17+
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
18+
*/
19+
class AccessDeniedException extends FileException
20+
{
21+
/**
22+
* Constructor.
23+
*
24+
* @param string $path The path to the accessed file
25+
*/
26+
public function __construct($path)
27+
{
28+
parent::__construct(sprintf('The file %s could not be accessed', $path));
29+
}
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\File\Exception;
13+
14+
/**
15+
* Thrown when an error occurred in the component File
16+
*
17+
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
18+
*/
19+
class FileException extends \RuntimeException
20+
{
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\File\Exception;
13+
14+
/**
15+
* Thrown when a file was not found
16+
*
17+
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
18+
*/
19+
class FileNotFoundException extends FileException
20+
{
21+
/**
22+
* Constructor.
23+
*
24+
* @param string $path The path to the file that was not found
25+
*/
26+
public function __construct($path)
27+
{
28+
parent::__construct(sprintf('The file "%s" does not exist', $path));
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\File\Exception;
13+
14+
class UnexpectedTypeException extends FileException
15+
{
16+
public function __construct($value, $expectedType)
17+
{
18+
parent::__construct(sprintf('Expected argument of type %s, %s given', $expectedType, is_object($value) ? get_class($value) : gettype($value)));
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\File\Exception;
13+
14+
/**
15+
* Thrown when an error occurred during file upload
16+
*
17+
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
18+
*/
19+
class UploadException extends FileException
20+
{
21+
}

0 commit comments

Comments
 (0)