Skip to content

Commit

Permalink
Release 4.0.0-beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-parry committed Apr 4, 2019
1 parent f4d0c27 commit 8b6cfe6
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 28 deletions.
2 changes: 1 addition & 1 deletion _support/Config/BadRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class BadRegistrar
{

public static function RegistrarConfig2()
public static function RegistrarConfig()
{
return 'I am not worthy';
}
Expand Down
28 changes: 28 additions & 0 deletions _support/Config/MockServices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace Tests\Support\Config;

use \CodeIgniter\Config\BaseService;

class MockServices extends BaseService
{

public $psr4 = [
'Tests/Support' => TESTPATH . '_support/',
];
public $classmap = [];

//--------------------------------------------------------------------

public function __construct()
{
// Don't call the parent since we don't want the default mappings.
// parent::__construct();
}

//--------------------------------------------------------------------
public static function locator(bool $getShared = true)
{
return new \CodeIgniter\Autoloader\FileLocator(static::autoloader());
}

}
58 changes: 58 additions & 0 deletions _support/Controllers/Popcorn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Tests\Support\Controllers;

use CodeIgniter\API\ResponseTrait;
use CodeIgniter\Controller;
use CodeIgniter\HTTP\Exceptions\HTTPException;

/**
* This is a testing only controller, intended to blow up in multiple
* ways to make sure we catch them.
*/
class Popcorn extends Controller
{

use ResponseTrait;

public function index()
{
return 'Hi there';
}

public function pop()
{
$this->respond('Oops', 567, 'Surprise');
}

public function popper()
{
throw new \RuntimeException('Surprise', 500);
}

public function weasel()
{
$this->respond('', 200);
}

public function oops()
{
$this->failUnauthorized();
}

public function goaway()
{
return redirect()->to('/');
}

// @see https://github.com/codeigniter4/CodeIgniter4/issues/1834
public function index3()
{
$response = $this->response->setJSON([
'lang' => $this->request->getLocale(),
]);

// echo var_dump($this->response->getBody());
return $response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ public function up()
$this->forge->addKey('id', true);
$this->forge->createTable('empty', true);

//No Primary Key
// Secondary Table
$this->forge->addField([
'id' => [
'type' => 'INTEGER',
'constraint' => 3,
$unique_or_auto => true,
],
'key' => [
'type' => 'VARCHAR',
'constraint' => 40,
],
'value' => ['type' => 'TEXT'],
]);
$this->forge->addKey('id', true);
$this->forge->createTable('secondary', true);
}

Expand Down
2 changes: 1 addition & 1 deletion _support/Models/SecondaryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SecondaryModel extends Model
{
protected $table = 'secondary';

protected $primaryKey = null;
protected $primaryKey = 'id';

protected $returnType = 'object';

Expand Down
38 changes: 20 additions & 18 deletions app/Config/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@
* Events::on('create', [$myInstance, 'myMethod']);
*/

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

Events::on('pre_system', function () {
if (ENVIRONMENT !== 'testing')
{
\ob_start(function ($buffer) {
return $buffer;
});
}
Services::toolbar()->respond();
\ob_start(function ($buffer) {
return $buffer;
});
}

/*
* --------------------------------------------------------------------
* Debug Toolbar Listeners.
* --------------------------------------------------------------------
* If you delete, they will no longer be collected.
*/
if (ENVIRONMENT !== 'production')
{
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
Services::toolbar()->respond();
}
});
46 changes: 46 additions & 0 deletions app/Controllers/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php namespace App\Controllers;

/**
* Class BaseController
*
* BaseController provides a convenient place for loading components
* and performing functions that are needed by all your controllers.
* Extend this class in any new controllers:
* class Home extends BaseController
*
* For security be sure to declare any new methods as protected or private.
*
* @package CodeIgniter
*/

use CodeIgniter\Controller;

class BaseController extends Controller
{

/**
* An array of helpers to be loaded automatically upon
* class instantiation. These helpers will be available
* to all other controllers that extend BaseController.
*
* @var array
*/
protected $helpers = [ ];

/**
* Constructor.
*
*/
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);

//--------------------------------------------------------------------
// Preload any models, libraries, etc, here.
//--------------------------------------------------------------------
// E.g.:
// $this->session = \Config\Services::session();

}
}
2 changes: 1 addition & 1 deletion app/Controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use CodeIgniter\Controller;

class Home extends Controller
class Home extends BaseController
{
public function index()
{
Expand Down
8 changes: 4 additions & 4 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

## Issues

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

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.
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.

## Guidelines

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

### PHP Style

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

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

### Signing

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.
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.

## How-to Guide

Expand Down
89 changes: 87 additions & 2 deletions public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Sets the environment that CodeIgniter runs under.
# SetEnv CI_ENVIRONMENT development

# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# UTF-8 encoding
# ----------------------------------------------------------------------
Expand All @@ -17,6 +20,16 @@ AddDefaultCharset utf-8
AddCharset utf-8 .atom .css .js .json .rss .vtt .xml
</IfModule>

# ----------------------------------------------------------------------
# Activate CORS
# ----------------------------------------------------------------------

<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js|gif|png|jpe?g|svg|svgz|ico|webp)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -47,6 +60,12 @@ AddDefaultCharset utf-8
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

# Disable image hotlinkiing start
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ [NC,F,L]
# Disable image hotlinkiing end

# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Expand All @@ -58,10 +77,58 @@ AddDefaultCharset utf-8
ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
ServerSignature Off
# Disable server signature end

# BEGIN Expires
<ifModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/x-component "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/font-woff2 "access plus 1 month"
ExpiresDefault "access 1 month"
</ifModule>
# END Expires

# ----------------------------------------------------------------------
# Gzip compression
# ----------------------------------------------------------------------

# Start gzip compression
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# End gzip compression

<IfModule mod_deflate.c>

# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
Expand All @@ -85,13 +152,31 @@ AddDefaultCharset utf-8
application/x-font-ttf \
application/xhtml+xml \
application/xml \
application/x-javascript \
application/x-font \
application/x-font-truetype \
application/x-font-otf \
application/x-font-woff \
application/x-font-woff2 \
application/x-font-opentype \
font/opentype \
image/svg+xml \
font/ttf \
font/otf \
font/eot \
font/woff \
font/woff2 \
image/svg+xml svg svgz \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
text/xml \
text/javascript \

# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
</IfModule>

0 comments on commit 8b6cfe6

Please sign in to comment.