Skip to content

Commit 5d28010

Browse files
Merge pull request #2 from codeigniter4/develop
updates
2 parents 52a857e + eaaf227 commit 5d28010

File tree

17 files changed

+191
-78
lines changed

17 files changed

+191
-78
lines changed

app/Config/Cache.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Cache extends BaseConfig
4646
* system.
4747
*
4848
* @var string
49+
*
50+
* @deprecated Use the driver-specific variant under $file
4951
*/
5052
public $storePath = WRITEPATH . 'cache/';
5153

@@ -80,6 +82,20 @@ class Cache extends BaseConfig
8082
*/
8183
public $prefix = '';
8284

85+
/**
86+
* --------------------------------------------------------------------------
87+
* File settings
88+
* --------------------------------------------------------------------------
89+
* Your file storage preferences can be specified below, if you are using
90+
* the File driver.
91+
*
92+
* @var array<string, string|int|null>
93+
*/
94+
public $file = [
95+
'storePath' => WRITEPATH . 'cache/',
96+
'mode' => 0640,
97+
];
98+
8399
/**
84100
* -------------------------------------------------------------------------
85101
* Memcached settings

app/Config/Mimes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class Mimes
149149
'multipart/x-zip',
150150
],
151151
'rar' => [
152+
'application/vnd.rar',
152153
'application/x-rar',
153154
'application/rar',
154155
'application/x-rar-compressed',

system/Cache/Handlers/FileHandler.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ class FileHandler implements CacheInterface
3434
*/
3535
protected $path;
3636

37+
/**
38+
* Mode for the stored files.
39+
* Must be chmod-safe (octal).
40+
*
41+
* @var integer
42+
*
43+
* @see https://www.php.net/manual/en/function.chmod.php
44+
*/
45+
protected $mode;
46+
3747
//--------------------------------------------------------------------
3848

3949
/**
@@ -44,14 +54,24 @@ class FileHandler implements CacheInterface
4454
*/
4555
public function __construct(Cache $config)
4656
{
47-
$path = ! empty($config->storePath) ? $config->storePath : WRITEPATH . 'cache';
48-
if (! is_really_writable($path))
57+
if (! property_exists($config, 'file'))
58+
{
59+
$config->file = [
60+
'storePath' => $config->storePath ?? WRITEPATH . 'cache',
61+
'mode' => 0640,
62+
];
63+
}
64+
65+
$this->path = ! empty($config->file['storePath']) ? $config->file['storePath'] : WRITEPATH . 'cache';
66+
$this->path = rtrim($this->path, '/') . '/';
67+
68+
if (! is_really_writable($this->path))
4969
{
50-
throw CacheException::forUnableToWrite($path);
70+
throw CacheException::forUnableToWrite($this->path);
5171
}
5272

53-
$this->prefix = $config->prefix ?: '';
54-
$this->path = rtrim($path, '/') . '/';
73+
$this->mode = $config->file['mode'] ?? 0640;
74+
$this->prefix = (string) $config->prefix;
5575
}
5676

5777
//--------------------------------------------------------------------
@@ -105,7 +125,7 @@ public function save(string $key, $value, int $ttl = 60)
105125

106126
if ($this->writeFile($this->path . $key, serialize($contents)))
107127
{
108-
chmod($this->path . $key, 0640);
128+
chmod($this->path . $key, $this->mode);
109129

110130
return true;
111131
}

system/Cache/Handlers/MemcachedHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MemcachedHandler implements CacheInterface
5858
*/
5959
public function __construct(Cache $config)
6060
{
61-
$this->prefix = $config->prefix ?: '';
61+
$this->prefix = (string) $config->prefix;
6262

6363
if (! empty($config))
6464
{

system/Cache/Handlers/PredisHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class PredisHandler implements CacheInterface
5858
*/
5959
public function __construct(Cache $config)
6060
{
61-
$this->prefix = $config->prefix ?: '';
61+
$this->prefix = (string) $config->prefix;
6262

6363
if (isset($config->redis))
6464
{

system/Cache/Handlers/RedisHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RedisHandler implements CacheInterface
5858
*/
5959
public function __construct(Cache $config)
6060
{
61-
$this->prefix = $config->prefix ?: '';
61+
$this->prefix = (string) $config->prefix;
6262

6363
if (! empty($config))
6464
{

system/Cache/Handlers/WincacheHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class WincacheHandler implements CacheInterface
3737
*/
3838
public function __construct(Cache $config)
3939
{
40-
$this->prefix = $config->prefix ?: '';
40+
$this->prefix = (string) $config->prefix;
4141
}
4242

4343
//--------------------------------------------------------------------

system/Config/View.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
*/
1717
class View extends BaseConfig
1818
{
19+
/**
20+
* When false, the view method will clear the data between each
21+
* call.
22+
*
23+
* @var boolean
24+
*/
25+
public $saveData = true;
26+
1927
/**
2028
* Parser Filters map a filter name with any PHP callable. When the
2129
* Parser prepares a variable for display, it will chain it

system/HTTP/Request.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ class Request extends Message implements MessageInterface, RequestInterface
4343
*/
4444
protected $uri;
4545

46-
//--------------------------------------------------------------------
47-
4846
/**
4947
* Constructor.
5048
*
@@ -68,8 +66,6 @@ public function __construct($config = null)
6866
}
6967
}
7068

71-
//--------------------------------------------------------------------
72-
7369
/**
7470
* Validate an IP address
7571
*
@@ -85,8 +81,6 @@ public function isValidIP(string $ip = null, string $which = null): bool
8581
return (new FormatRules())->valid_ip($ip, $which);
8682
}
8783

88-
//--------------------------------------------------------------------
89-
9084
/**
9185
* Get the request method.
9286
*
@@ -101,8 +95,6 @@ public function getMethod(bool $upper = false): string
10195
return ($upper) ? strtoupper($this->method) : strtolower($this->method);
10296
}
10397

104-
//--------------------------------------------------------------------
105-
10698
/**
10799
* Sets the request method. Used when spoofing the request.
108100
*
@@ -124,16 +116,16 @@ public function setMethod(string $method)
124116
*
125117
* @param string $method
126118
*
127-
* @return self
119+
* @return static
128120
*/
129121
public function withMethod($method)
130122
{
131-
$clone = clone $this;
123+
$request = clone $this;
132124

133-
return $clone->setMethod($method);
134-
}
125+
$request->method = $method;
135126

136-
//--------------------------------------------------------------------
127+
return $request;
128+
}
137129

138130
/**
139131
* Retrieves the URI instance.

system/Validation/FormatRules.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public function alpha_space(?string $value = null): bool
4444
return true;
4545
}
4646

47-
return (bool) preg_match('/^[A-Z ]+$/i', $value);
47+
// @see https://regex101.com/r/LhqHPO/1
48+
return (bool) preg_match('/\A[A-Z ]+\z/i', $value);
4849
}
4950

5051
/**
@@ -56,7 +57,8 @@ public function alpha_space(?string $value = null): bool
5657
*/
5758
public function alpha_dash(?string $str = null): bool
5859
{
59-
return (bool) preg_match('/^[a-z0-9_-]+$/i', $str);
60+
// @see https://regex101.com/r/XfVY3d/1
61+
return (bool) preg_match('/\A[a-z0-9_-]+\z/i', $str);
6062
}
6163

6264
/**
@@ -72,7 +74,8 @@ public function alpha_dash(?string $str = null): bool
7274
*/
7375
public function alpha_numeric_punct($str)
7476
{
75-
return (bool) preg_match('/^[A-Z0-9 ~!#$%\&\*\-_+=|:.]+$/i', $str);
77+
// @see https://regex101.com/r/6N8dDY/1
78+
return (bool) preg_match('/\A[A-Z0-9 ~!#$%\&\*\-_+=|:.]+\z/i', $str);
7679
}
7780

7881
/**
@@ -96,7 +99,8 @@ public function alpha_numeric(?string $str = null): bool
9699
*/
97100
public function alpha_numeric_space(?string $str = null): bool
98101
{
99-
return (bool) preg_match('/^[A-Z0-9 ]+$/i', $str);
102+
// @see https://regex101.com/r/0AZDME/1
103+
return (bool) preg_match('/\A[A-Z0-9 ]+\z/i', $str);
100104
}
101105

102106
/**
@@ -123,7 +127,8 @@ public function string($str = null): bool
123127
*/
124128
public function decimal(?string $str = null): bool
125129
{
126-
return (bool) preg_match('/^[-+]?[0-9]{0,}\.?[0-9]+$/', $str);
130+
// @see https://regex101.com/r/HULifl/1/
131+
return (bool) preg_match('/\A[-+]?[0-9]{0,}\.?[0-9]+\z/', $str);
127132
}
128133

129134
/**
@@ -147,7 +152,7 @@ public function hex(?string $str = null): bool
147152
*/
148153
public function integer(?string $str = null): bool
149154
{
150-
return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
155+
return (bool) preg_match('/\A[\-+]?[0-9]+\z/', $str);
151156
}
152157

153158
/**
@@ -181,7 +186,8 @@ public function is_natural_no_zero(?string $str = null): bool
181186
*/
182187
public function numeric(?string $str = null): bool
183188
{
184-
return (bool) preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
189+
// @see https://regex101.com/r/bb9wtr/1
190+
return (bool) preg_match('/\A[\-+]?[0-9]*\.?[0-9]+\z/', $str);
185191
}
186192

187193
/**
@@ -253,6 +259,7 @@ public function valid_json(string $str = null): bool
253259
*/
254260
public function valid_email(string $str = null): bool
255261
{
262+
// @see https://regex101.com/r/wlJG1t/1/
256263
if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46') && preg_match('#\A([^@]+)@(.+)\z#', $str, $matches))
257264
{
258265
$str = $matches[1] . '@' . idn_to_ascii($matches[2], 0, INTL_IDNA_VARIANT_UTS46);

0 commit comments

Comments
 (0)