Skip to content

Commit 5b5ccfe

Browse files
committed
Release 4.0.0-beta.2
1 parent 672e46f commit 5b5ccfe

File tree

204 files changed

+2602
-1089
lines changed

Some content is hidden

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

204 files changed

+2602
-1089
lines changed

_support/Config/BadRegistrar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class BadRegistrar
1111
{
1212

13-
public static function RegistrarConfig2()
13+
public static function RegistrarConfig()
1414
{
1515
return 'I am not worthy';
1616
}

_support/Config/MockServices.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
namespace Tests\Support\Config;
3+
4+
use \CodeIgniter\Config\BaseService;
5+
6+
class MockServices extends BaseService
7+
{
8+
9+
public $psr4 = [
10+
'Tests/Support' => TESTPATH . '_support/',
11+
];
12+
public $classmap = [];
13+
14+
//--------------------------------------------------------------------
15+
16+
public function __construct()
17+
{
18+
// Don't call the parent since we don't want the default mappings.
19+
// parent::__construct();
20+
}
21+
22+
//--------------------------------------------------------------------
23+
public static function locator(bool $getShared = true)
24+
{
25+
return new \CodeIgniter\Autoloader\FileLocator(static::autoloader());
26+
}
27+
28+
}

_support/Controllers/Popcorn.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
namespace Tests\Support\Controllers;
3+
4+
use CodeIgniter\API\ResponseTrait;
5+
use CodeIgniter\Controller;
6+
use CodeIgniter\HTTP\Exceptions\HTTPException;
7+
8+
/**
9+
* This is a testing only controller, intended to blow up in multiple
10+
* ways to make sure we catch them.
11+
*/
12+
class Popcorn extends Controller
13+
{
14+
15+
use ResponseTrait;
16+
17+
public function index()
18+
{
19+
return 'Hi there';
20+
}
21+
22+
public function pop()
23+
{
24+
$this->respond('Oops', 567, 'Surprise');
25+
}
26+
27+
public function popper()
28+
{
29+
throw new \RuntimeException('Surprise', 500);
30+
}
31+
32+
public function weasel()
33+
{
34+
$this->respond('', 200);
35+
}
36+
37+
public function oops()
38+
{
39+
$this->failUnauthorized();
40+
}
41+
42+
public function goaway()
43+
{
44+
return redirect()->to('/');
45+
}
46+
47+
// @see https://github.com/codeigniter4/CodeIgniter4/issues/1834
48+
public function index3()
49+
{
50+
$response = $this->response->setJSON([
51+
'lang' => $this->request->getLocale(),
52+
]);
53+
54+
// echo var_dump($this->response->getBody());
55+
return $response;
56+
}
57+
58+
}

_support/Database/Migrations/20160428212500_Create_test_tables.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,20 @@ public function up()
8686
$this->forge->addKey('id', true);
8787
$this->forge->createTable('empty', true);
8888

89-
//No Primary Key
89+
// Secondary Table
9090
$this->forge->addField([
91+
'id' => [
92+
'type' => 'INTEGER',
93+
'constraint' => 3,
94+
$unique_or_auto => true,
95+
],
9196
'key' => [
9297
'type' => 'VARCHAR',
9398
'constraint' => 40,
9499
],
95100
'value' => ['type' => 'TEXT'],
96101
]);
102+
$this->forge->addKey('id', true);
97103
$this->forge->createTable('secondary', true);
98104
}
99105

_support/Models/SecondaryModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class SecondaryModel extends Model
66
{
77
protected $table = 'secondary';
88

9-
protected $primaryKey = null;
9+
protected $primaryKey = 'id';
1010

1111
protected $returnType = 'object';
1212

app/Config/Events.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,25 @@
1919
* Events::on('create', [$myInstance, 'myMethod']);
2020
*/
2121

22-
/*
23-
* --------------------------------------------------------------------
24-
* Debug Toolbar Listeners.
25-
* --------------------------------------------------------------------
26-
* If you delete, they will no longer be collected.
27-
*/
28-
if (ENVIRONMENT !== 'production')
29-
{
30-
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
22+
Events::on('pre_system', function () {
23+
while (\ob_get_level() > 0)
24+
{
25+
\ob_end_flush();
26+
}
3127

32-
Events::on('pre_system', function () {
33-
if (ENVIRONMENT !== 'testing')
34-
{
35-
\ob_start(function ($buffer) {
36-
return $buffer;
37-
});
38-
}
39-
Services::toolbar()->respond();
28+
\ob_start(function ($buffer) {
29+
return $buffer;
4030
});
41-
}
31+
32+
/*
33+
* --------------------------------------------------------------------
34+
* Debug Toolbar Listeners.
35+
* --------------------------------------------------------------------
36+
* If you delete, they will no longer be collected.
37+
*/
38+
if (ENVIRONMENT !== 'production')
39+
{
40+
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
41+
Services::toolbar()->respond();
42+
}
43+
});

app/Controllers/BaseController.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php namespace App\Controllers;
2+
3+
/**
4+
* Class BaseController
5+
*
6+
* BaseController provides a convenient place for loading components
7+
* and performing functions that are needed by all your controllers.
8+
* Extend this class in any new controllers:
9+
* class Home extends BaseController
10+
*
11+
* For security be sure to declare any new methods as protected or private.
12+
*
13+
* @package CodeIgniter
14+
*/
15+
16+
use CodeIgniter\Controller;
17+
18+
class BaseController extends Controller
19+
{
20+
21+
/**
22+
* An array of helpers to be loaded automatically upon
23+
* class instantiation. These helpers will be available
24+
* to all other controllers that extend BaseController.
25+
*
26+
* @var array
27+
*/
28+
protected $helpers = [ ];
29+
30+
/**
31+
* Constructor.
32+
*
33+
*/
34+
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
35+
{
36+
// Do Not Edit This Line
37+
parent::initController($request, $response, $logger);
38+
39+
//--------------------------------------------------------------------
40+
// Preload any models, libraries, etc, here.
41+
//--------------------------------------------------------------------
42+
// E.g.:
43+
// $this->session = \Config\Services::session();
44+
45+
}
46+
}

app/Controllers/Home.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use CodeIgniter\Controller;
44

5-
class Home extends Controller
5+
class Home extends BaseController
66
{
77
public function index()
88
{

contributing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
We expect all contributions to conform to our style guide, be commented (inside the PHP source files),
77
be documented (in the user guide), and unit tested (in the test folder).
8-
There is a [Contributing to CodeIgniter](./contributing/index.rst) section in the repository which describes the contribution process; this page is an overview.
8+
There is a [Contributing to CodeIgniter](./contributing/README.rst) section in the repository which describes the contribution process; this page is an overview.
99

1010
## Issues
1111

@@ -15,7 +15,7 @@ Issues are a quick way to point out a bug. If you find a bug or documentation er
1515
2. The issue has already been fixed (check the develop branch, or look for closed Issues)
1616
3. Is it something really obvious that you can fix yourself?
1717

18-
Reporting issues is helpful but an even [better approach](https://codeigniter4.github.io/CodeIgniter4/contributing/workflow.html) is to send a Pull Request, which is done by "Forking" the main repository and committing to your own copy. This will require you to use the version control system called Git.
18+
Reporting issues is helpful but an even [better approach](./contributing/workflow.rst) is to send a Pull Request, which is done by "Forking" the main repository and committing to your own copy. This will require you to use the version control system called Git.
1919

2020
## Guidelines
2121

@@ -26,7 +26,7 @@ for us to maintain quality of the code-base.
2626

2727
### PHP Style
2828

29-
All code must meet the [Style Guide](https://codeigniter4.github.io/CodeIgniter4/contributing/styleguide.html).
29+
All code must meet the [Style Guide](./contributing/styleguide.rst).
3030
This makes certain that all code is the same format as the existing code and means it will be as readable as possible.
3131

3232
### Documentation
@@ -46,7 +46,7 @@ One thing at a time: A pull request should only contain one change. That does no
4646

4747
### Signing
4848

49-
You must [GPG-sign](https://codeigniter4.github.io/CodeIgniter4/contributing/signing.html) your work, certifying that you either wrote the work or otherwise have the right to pass it on to an open source project. This is *not* just a "signed-off-by" commit, but instead a digitally signed one.
49+
You must [GPG-sign](./contributing/signing.rst) your work, certifying that you either wrote the work or otherwise have the right to pass it on to an open source project. This is *not* just a "signed-off-by" commit, but instead a digitally signed one.
5050

5151
## How-to Guide
5252

public/.htaccess

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# Sets the environment that CodeIgniter runs under.
66
# SetEnv CI_ENVIRONMENT development
77

8+
# Disable directory browsing
9+
Options All -Indexes
10+
811
# ----------------------------------------------------------------------
912
# UTF-8 encoding
1013
# ----------------------------------------------------------------------
@@ -17,6 +20,16 @@ AddDefaultCharset utf-8
1720
AddCharset utf-8 .atom .css .js .json .rss .vtt .xml
1821
</IfModule>
1922

23+
# ----------------------------------------------------------------------
24+
# Activate CORS
25+
# ----------------------------------------------------------------------
26+
27+
<IfModule mod_headers.c>
28+
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js|gif|png|jpe?g|svg|svgz|ico|webp)$">
29+
Header set Access-Control-Allow-Origin "*"
30+
</FilesMatch>
31+
</IfModule>
32+
2033
# ----------------------------------------------------------------------
2134
# Rewrite engine
2235
# ----------------------------------------------------------------------
@@ -47,6 +60,12 @@ AddDefaultCharset utf-8
4760
RewriteCond %{REQUEST_FILENAME} !-d
4861
RewriteRule ^(.*)$ index.php/$1 [L]
4962

63+
# Disable image hotlinkiing start
64+
RewriteCond %{HTTP_REFERER} !^$
65+
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
66+
RewriteRule \.(jpg|jpeg|png|gif)$ [NC,F,L]
67+
# Disable image hotlinkiing end
68+
5069
# Ensure Authorization header is passed along
5170
RewriteCond %{HTTP:Authorization} .
5271
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
@@ -58,10 +77,58 @@ AddDefaultCharset utf-8
5877
ErrorDocument 404 index.php
5978
</IfModule>
6079

80+
# Disable server signature start
81+
ServerSignature Off
82+
# Disable server signature end
83+
84+
# BEGIN Expires
85+
<ifModule mod_expires.c>
86+
ExpiresActive On
87+
ExpiresByType text/css "access 1 month"
88+
ExpiresByType text/html "access 1 month"
89+
ExpiresByType image/gif "access 1 year"
90+
ExpiresByType image/png "access 1 year"
91+
ExpiresByType image/jpg "access 1 year"
92+
ExpiresByType image/jpeg "access 1 year"
93+
ExpiresByType image/x-icon "access 1 year"
94+
ExpiresByType image/svg+xml "access plus 1 month"
95+
ExpiresByType audio/ogg "access plus 1 year"
96+
ExpiresByType video/mp4 "access plus 1 year"
97+
ExpiresByType video/ogg "access plus 1 year"
98+
ExpiresByType video/webm "access plus 1 year"
99+
ExpiresByType application/atom+xml "access plus 1 hour"
100+
ExpiresByType application/rss+xml "access plus 1 hour"
101+
ExpiresByType application/pdf "access 1 month"
102+
ExpiresByType application/javascript "access 1 month"
103+
ExpiresByType text/x-javascript "access 1 month"
104+
ExpiresByType text/x-component "access plus 1 month"
105+
ExpiresByType application/x-shockwave-flash "access 1 month"
106+
ExpiresByType font/opentype "access plus 1 month"
107+
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
108+
ExpiresByType application/x-font-ttf "access plus 1 month"
109+
ExpiresByType application/font-woff "access plus 1 month"
110+
ExpiresByType application/font-woff2 "access plus 1 month"
111+
ExpiresDefault "access 1 month"
112+
</ifModule>
113+
# END Expires
114+
61115
# ----------------------------------------------------------------------
62116
# Gzip compression
63117
# ----------------------------------------------------------------------
64118

119+
# Start gzip compression
120+
<IfModule mod_gzip.c>
121+
mod_gzip_on Yes
122+
mod_gzip_dechunk Yes
123+
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
124+
mod_gzip_item_include handler ^cgi-script$
125+
mod_gzip_item_include mime ^text/.*
126+
mod_gzip_item_include mime ^application/x-javascript.*
127+
mod_gzip_item_exclude mime ^image/.*
128+
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
129+
</IfModule>
130+
# End gzip compression
131+
65132
<IfModule mod_deflate.c>
66133

67134
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
@@ -85,13 +152,31 @@ AddDefaultCharset utf-8
85152
application/x-font-ttf \
86153
application/xhtml+xml \
87154
application/xml \
155+
application/x-javascript \
156+
application/x-font \
157+
application/x-font-truetype \
158+
application/x-font-otf \
159+
application/x-font-woff \
160+
application/x-font-woff2 \
161+
application/x-font-opentype \
88162
font/opentype \
89-
image/svg+xml \
163+
font/ttf \
164+
font/otf \
165+
font/eot \
166+
font/woff \
167+
font/woff2 \
168+
image/svg+xml svg svgz \
90169
image/x-icon \
91170
text/css \
92171
text/html \
93172
text/plain \
94173
text/x-component \
95-
text/xml
174+
text/xml \
175+
text/javascript \
176+
177+
# For Olders Browsers Which Can't Handle Compression
178+
BrowserMatch ^Mozilla/4 gzip-only-text/html
179+
BrowserMatch ^Mozilla/4\.0[678] no-gzip
180+
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
96181
</IfModule>
97182
</IfModule>

0 commit comments

Comments
 (0)