Skip to content

Commit 3abe0e2

Browse files
authored
Merge pull request #1 from codeigniter4/develop
Update develop branch
2 parents 57b0bc4 + b108541 commit 3abe0e2

File tree

202 files changed

+1806
-617
lines changed

Some content is hidden

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

202 files changed

+1806
-617
lines changed

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/styleguide.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,82 @@ Control Structures
247247
if ( $foo ) $bar += $baz;
248248
else $baz = 'bar';
249249

250+
Docblocks
251+
=========
252+
253+
We use phpDocumentor (phpdoc) to generate the API docs, for all of the source
254+
code inside the `system` folder.
255+
256+
It wants to see a file summary docblock at the top of a PHP file,
257+
before any PHP statements, and then a docblock before each documentable
258+
component, namely any class/interface/trait, and all public and protected
259+
methods/functions/variables. The docblock for a method or function
260+
is expected to describe the parameters, return value, and any exceptions
261+
thrown.
262+
263+
Deviations from the above are considered errors by phpdoc.
264+
265+
An example::
266+
267+
<?php
268+
269+
/**
270+
* CodeIgniter
271+
*
272+
* An open source application development framework for PHP
273+
*
274+
...
275+
*
276+
* @package CodeIgniter
277+
* @author CodeIgniter Dev Team
278+
* @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/)
279+
* @license https://opensource.org/licenses/MIT MIT License
280+
* @link https://codeigniter.com
281+
* @since Version 3.0.0
282+
* @filesource
283+
*/
284+
namespace CodeIgniter\Fruit;
285+
use CodeIgniter\Config\BaseConfig;
286+
287+
/**
288+
* Base class for entities in the CodeIgniter\Fruit module.
289+
*
290+
* @property $group
291+
* @property $name
292+
* @property $description
293+
*
294+
* @package CodeIgniter\Fruit
295+
*/
296+
abstract class BaseFruit
297+
{
298+
299+
/**
300+
* The group a fruit belongs to.
301+
*
302+
* @var string
303+
*/
304+
protected $group;
305+
306+
/**
307+
* Fruit constructor.
308+
*
309+
* @param BaseConfig $config
310+
*/
311+
public function __construct(BaseConfig $Config)
312+
{
313+
$this->group = 'Unknown';
314+
}
315+
316+
//--------------------------------------------------------------------
317+
318+
/**
319+
* Model a fruit ripening over time.
320+
*
321+
* @param array $params
322+
*/
323+
abstract public function ripen(array $params);
324+
}
325+
250326
Other
251327
=====
252328

phpdoc.dist.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
<target>api/build/</target>
99
</transformer>
1010
<files>
11-
<directory>./system</directory>
12-
<ignore>./vendor/*</ignore>
13-
<ignore>./tests/*</ignore>
11+
<directory>system</directory>
12+
<ignore>vendor/*</ignore>
13+
<ignore>tests/*</ignore>
1414
<ignore>Kint/*</ignore>
1515
</files>
1616

1717
<logging>
18-
<level>warn</level>
18+
<level>err</level>
1919
<paths>
2020
<default>api/log/{DATE}.log</default>
2121
<errors>api/{DATE}.errors.log</errors>
2222
</paths>
2323
</logging>
2424

2525
<transformations>
26-
<template name="responsive" />
26+
<template name="responsive-twig" />
2727
</transformations>
2828
</phpdoc>

system/API/ResponseTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php namespace CodeIgniter\API;
1+
<?php
22

33
/**
44
* CodeIgniter
@@ -36,6 +36,8 @@
3636
* @filesource
3737
*/
3838

39+
namespace CodeIgniter\API;
40+
3941
use Config\Format;
4042
use CodeIgniter\HTTP\Response;
4143

system/Autoloader/Autoloader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<?php namespace CodeIgniter\Autoloader;
2-
3-
use Composer\Autoload\ClassLoader;
1+
<?php
42

53
/**
64
* CodeIgniter
@@ -38,6 +36,8 @@
3836
* @filesource
3937
*/
4038

39+
namespace CodeIgniter\Autoloader;
40+
4141
/**
4242
* CodeIgniter Autoloader
4343
*

system/Autoloader/FileLocator.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php namespace CodeIgniter\Autoloader;
1+
<?php
22

33
/**
44
* CodeIgniter
@@ -36,6 +36,8 @@
3636
* @filesource
3737
*/
3838

39+
namespace CodeIgniter\Autoloader;
40+
3941
/**
4042
* Class FileLocator
4143
*
@@ -376,6 +378,48 @@ public function listFiles(string $path): array
376378

377379
//--------------------------------------------------------------------
378380

381+
/**
382+
* Scans the provided namespace, returning a list of all files
383+
* that are contained within the subpath specified by $path.
384+
*
385+
* @param string $prefix
386+
* @param string $path
387+
*
388+
* @return array
389+
*/
390+
public function listNamespaceFiles(string $prefix, string $path): array
391+
{
392+
if (empty($path) || empty($prefix))
393+
{
394+
return [];
395+
}
396+
397+
$files = [];
398+
helper('filesystem');
399+
400+
// autoloader->getNamespace($prefix) returns an array of paths for that namespace
401+
foreach ($this->autoloader->getNamespace($prefix) as $namespacePath)
402+
{
403+
$fullPath = realpath($namespacePath . $path);
404+
405+
if (! is_dir($fullPath))
406+
{
407+
continue;
408+
}
409+
410+
$tempFiles = get_filenames($fullPath, true);
411+
412+
if (! empty($tempFiles))
413+
{
414+
$files = array_merge($files, $tempFiles);
415+
}
416+
}
417+
418+
return $files;
419+
}
420+
421+
//--------------------------------------------------------------------
422+
379423
/**
380424
* Checks the application folder to see if the file can be found.
381425
* Only for use with filenames that DO NOT include namespacing.

system/CLI/BaseCommand.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?php namespace CodeIgniter\CLI;
2-
1+
<?php
32
/**
43
* CodeIgniter
54
*
@@ -36,6 +35,8 @@
3635
* @filesource
3736
*/
3837

38+
namespace CodeIgniter\CLI;
39+
3940
use Psr\Log\LoggerInterface;
4041

4142
/**
@@ -94,6 +95,8 @@ abstract class BaseCommand
9495
protected $arguments = [];
9596

9697
/**
98+
* The Logger to use for a command
99+
*
97100
* @var \Psr\Log\LoggerInterface
98101
*/
99102
protected $logger;
@@ -122,6 +125,12 @@ public function __construct(LoggerInterface $logger, CommandRunner $commands)
122125

123126
//--------------------------------------------------------------------
124127

128+
/**
129+
* Actually execute a command.
130+
* This has to be over-ridden in any concrete implementation.
131+
*
132+
* @param array $params
133+
*/
125134
abstract public function run(array $params);
126135

127136
//--------------------------------------------------------------------

0 commit comments

Comments
 (0)