Skip to content

Commit d124a0a

Browse files
committed
Merge branch 'develop' of github.com:bcit-ci/CodeIgniter4 into develop
2 parents da43a39 + ccd9267 commit d124a0a

13 files changed

Lines changed: 221 additions & 23 deletions

File tree

application/Config/Routes.php

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

7474
// We get a performance increase by specifying the default
7575
// route since we don't have to scan directories.
76-
$routes->add('/', 'Home::index');
76+
$routes->get('/', 'Home::index');
7777

7878
/**
7979
* --------------------------------------------------------------------
File renamed without changes.

public/.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ----------------------------------------------------------------------
44

55
# Sets the environment that CodeIgniter runs under.
6-
SetEnv CI_ENVIRONMENT development
6+
# SetEnv CI_ENVIRONMENT development
77

88
# ----------------------------------------------------------------------
99
# UTF-8 encoding

system/Entity.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ public function __set(string $key, $value = null)
221221
$value = serialize($value);
222222
}
223223

224+
// JSON casting requires that we JSONize the value
225+
// when setting it so that it can easily be stored
226+
// back to the database.
227+
if (function_exists('json_encode') && array_key_exists($key, $this->_options['casts']) && ($this->_options['casts'][$key] === 'json' || $this->_options['casts'][$key] === 'json-array'))
228+
{
229+
$value = json_encode($value);
230+
}
231+
224232
// if a set* method exists for this key,

225233
// use that method to insert this value.

226234
$method = 'set' . str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $key)));
@@ -360,6 +368,7 @@ protected function mutateDate($value)
360368
*
361369
* @return mixed
362370
*/
371+
363372
protected function castAs($value, string $type)
364373
{
365374
switch($type)
@@ -390,6 +399,12 @@ protected function castAs($value, string $type)
390399

391400
$value = (array)$value;
392401
break;
402+
case 'json':
403+
$value = $this->castAsJson($value, false);
404+
break;
405+
case 'json-array':
406+
$value = $this->castAsJson($value, true);
407+
break;
393408
case 'datetime':
394409
return new \DateTime($value);
395410
break;
@@ -400,4 +415,32 @@ protected function castAs($value, string $type)
400415

401416
return $value;
402417
}
418+
419+
//--------------------------------------------------------------------
420+
421+
/**
422+
* Cast as JSON
423+
*
424+
* @param mixed $value
425+
* @param bool $asArray
426+
*
427+
* @return mixed
428+
*/
429+
private function castAsJson($value, bool $asArray = false)
430+
{
431+
$tmp = !is_null($value) ? ($asArray ? [] : new \stdClass) : null;
432+
if(function_exists('json_decode'))
433+
{
434+
if((is_string($value) && (strpos($value, '[') === 0 || strpos($value, '{') === 0 || (strpos($value, '"') === 0 && strrpos($value, '"') === 0 ))) || is_numeric($value))
435+
{
436+
$tmp = json_decode($value, $asArray);
437+
438+
if(json_last_error() !== JSON_ERROR_NONE)
439+
{
440+
throw CastException::forInvalidJsonFormatException(json_last_error());
441+
}
442+
}
443+
}
444+
return $tmp;
445+
}
403446
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php namespace CodeIgniter\Exceptions;
2+
3+
/**
4+
* Cast Exceptions.
5+
*/
6+
class CastException extends CriticalError
7+
{
8+
9+
/**
10+
* Error code
11+
* @var int
12+
*/
13+
protected $code = 3;
14+
15+
public static function forInvalidJsonFormatException(int $error)
16+
{
17+
switch($error)
18+
{
19+
case JSON_ERROR_DEPTH:
20+
throw new static(lang('Cast.jsonErrorDepth'));
21+
break;
22+
case JSON_ERROR_STATE_MISMATCH:
23+
throw new static(lang('Cast.jsonErrorStateMismatch'));
24+
break;
25+
case JSON_ERROR_CTRL_CHAR:
26+
throw new static(lang('Cast.jsonErrorCtrlChar'));
27+
break;
28+
case JSON_ERROR_SYNTAX:
29+
throw new static(lang('Cast.jsonErrorSyntax'));
30+
break;
31+
case JSON_ERROR_UTF8:
32+
throw new static(lang('Cast.jsonErrorUtf8'));
33+
break;
34+
default:
35+
throw new static(lang('Cast.jsonErrorUnknown'));
36+
}
37+
38+
}
39+
40+
}

system/Language/en/Cast.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Cast language strings.
4+
*
5+
* @package CodeIgniter
6+
* @author CodeIgniter Dev Team
7+
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
8+
* @license https://opensource.org/licenses/MIT MIT License
9+
* @link https://codeigniter.com
10+
* @since Version 3.0.0
11+
* @filesource
12+
*
13+
* @codeCoverageIgnore
14+
*/
15+
16+
return [
17+
'jsonErrorDepth' => 'Maximum stack depth exceeded',
18+
'jsonErrorStateMismatch' => 'Underflow or the modes mismatch',
19+
'jsonErrorCtrlChar' => 'Unexpected control character found',
20+
'jsonErrorSyntax' => 'Syntax error, malformed JSON',
21+
'jsonErrorUtf8' => 'Malformed UTF-8 characters, possibly incorrectly encoded',
22+
'jsonErrorUnknown' => 'Unknown error'
23+
];
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
###########################
2+
Contributing to CodeIgniter
3+
###########################
4+
5+
CodeIgniter is a community driven project and accepts contributions of code
6+
and documentation from the community. These contributions are made in the form
7+
of Issues or `Pull Requests <https://help.github.com/articles/using-pull-requests/>`_
8+
on the `CodeIgniter4 repository <https://github.com/bcit-ci/CodeIgniter4>`_ on GitHub.
9+
10+
Issues are a quick way to point out a bug. If you find a bug or documentation
11+
error in CodeIgniter then please check a few things first:
12+
13+
- There is not already an open Issue
14+
- The issue has already been fixed (check the develop branch, or look for
15+
closed Issues)
16+
- Is it something really obvious that you fix it yourself?
17+
18+
Reporting issues is helpful but an even better approach is to send a Pull
19+
Request, which is done by "Forking" the main repository and committing to your
20+
own copy. This will require you to use the version control system called Git.
21+
22+
Please see the `Contributing to CodeIgniter4 <https://github.com/bcit-ci/CodeIgniter4/tree/develop/contributing>`_
23+
section of our code repository.
24+
25+
26+
*******
27+
Support
28+
*******
29+
30+
Please note that GitHub is not for general support questions! If you are
31+
having trouble using a feature of CodeIgniter, ask for help on our
32+
`forums <http://forum.codeigniter.com/>`_ instead.
33+
34+
If you are not sure whether you are using something correctly or if you
35+
have found a bug, again - please ask on the forums first.
36+
37+
********
38+
Security
39+
********
40+
41+
Did you find a security issue in CodeIgniter?
42+
43+
Please *don't* disclose it publicly, but e-mail us at security@codeigniter.com,
44+
or report it via our page on `HackerOne <https://hackerone.com/codeigniter>`_.
45+
46+
If you've found a critical vulnerability, we'd be happy to credit you in our
47+
`ChangeLog <https://bcit-ci.github.io/CodeIgniter4/changelog.html>`_.
48+
49+
****************************
50+
Tips for a Good Issue Report
51+
****************************
52+
53+
Use a descriptive subject line (eg parser library chokes on commas) rather than a vague one (eg. your code broke).
54+
55+
Address a single issue in a report.
56+
57+
Identify the CodeIgniter version (eg 4.0.1) and the component if you know it (eg. parser library)
58+
59+
Explain what you expected to happen, and what did happen.
60+
Include error messages and stacktrace, if any.
61+
62+
Include short code segments if they help to explain.
63+
Use a pastebin or dropbox facility to include longer segments of code or screenshots - do not include them in the issue report itself.
64+
This means setting a reasonable expiry for those, until the issue is resolved or closed.
65+
66+
If you know how to fix the issue, you can do so in your own fork & branch, and submit a pull request.
67+
The issue report information above should be part of that.
68+
69+
If your issue report can describe the steps to reproduce the problem, that is great.
70+
If you can include a unit test that reproduces the problem, that is even better, as it gives whoever is fixing
71+
it a clearer target!

user_guide_src/source/extending/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ CodeIgniter 4 has been designed to be easy to extend or build upon.
99

1010
core_classes
1111
events
12+
contributing

user_guide_src/source/installation/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Installation
44

55
CodeIgniter4 can be installed manually, or using Composer.
66

7+
.. note:: Before using CodeIgniter, make sure that your server meets the
8+
:doc:`requirements </intro/requirements>`.
9+
710
Manual Installation
811
===================
912

user_guide_src/source/intro/requirements.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
Server Requirements
33
###################
44

5-
`PHP <http://php.net/>`_ version 7.1 or newer is required, with the *intl* extension installed. `Why 7.1 <https://gophp71.org/>`_?
5+
`PHP <http://php.net/>`_ version 7.1 or newer is required, with the
6+
`*intl* extension <http://php.net/manual/en/intl.requirements.php>`_
7+
installed. `Why 7.1 <https://gophp71.org/>`_?
8+
9+
The following PHP extensions should be enabled on your server:
10+
``php-json``, ``php-mbstring``, ``php-mysqlnd``, `php-xml``
11+
12+
In order to use the :doc:`CURLRequest </libraries/curlrequest>`, you will need
13+
`libcurl <http://php.net/manual/en/curl.requirements.php>`_ installed.
614

715
A database is required for most web application programming.
816
Currently supported databases are:

0 commit comments

Comments
 (0)