Skip to content

Commit a228481

Browse files
authored
Merge pull request #1 from bcit-ci/develop
update code
2 parents 0674657 + 1a9ee5b commit a228481

File tree

9 files changed

+225
-117
lines changed

9 files changed

+225
-117
lines changed

application/Views/errors/html/error_exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php $error_id = uniqid('error'); ?>
1+
<?php $error_id = uniqid('error', true); ?>
22
<!doctype html>
33
<html>
44
<head>

system/Commands/Database/CreateMigration.php

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2828
* THE SOFTWARE.
2929
*
30-
* @package CodeIgniter
31-
* @author CodeIgniter Dev Team
32-
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
33-
* @license https://opensource.org/licenses/MIT MIT License
34-
* @link https://codeigniter.com
35-
* @since Version 3.0.0
30+
* @package CodeIgniter
31+
* @author CodeIgniter Dev Team
32+
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
33+
* @license https://opensource.org/licenses/MIT MIT License
34+
* @link https://codeigniter.com
35+
* @since Version 3.0.0
3636
* @filesource
3737
*/
38+
3839
use CodeIgniter\CLI\BaseCommand;
3940
use CodeIgniter\CLI\CLI;
4041
use Config\Autoload;
@@ -83,7 +84,7 @@ class CreateMigration extends BaseCommand
8384
* @var array
8485
*/
8586
protected $arguments = [
86-
'migration_name' => 'The migration file name'
87+
'migration_name' => 'The migration file name',
8788
];
8889

8990
/**
@@ -92,7 +93,7 @@ class CreateMigration extends BaseCommand
9293
* @var array
9394
*/
9495
protected $options = [
95-
'-n' => 'Set migration namespace'
96+
'-n' => 'Set migration namespace',
9697
];
9798

9899
/**
@@ -104,7 +105,6 @@ class CreateMigration extends BaseCommand
104105
*/
105106
public function run(array $params = [])
106107
{
107-
108108
$name = array_shift($params);
109109

110110
if (empty($name))
@@ -117,19 +117,18 @@ public function run(array $params = [])
117117
CLI::error(lang('Migrations.badCreateName'));
118118
return;
119119
}
120-
$ns = CLI::getOption('n');
120+
$ns = CLI::getOption('n');
121121
$homepath = APPPATH;
122122

123-
if ( ! empty($ns))
123+
if (! empty($ns))
124124
{
125125
// Get all namespaces form PSR4 paths.
126-
$config = new Autoload();
126+
$config = new Autoload();
127127
$namespaces = $config->psr4;
128128

129129
foreach ($namespaces as $namespace => $path)
130130
{
131-
132-
if ($namespace == $ns)
131+
if ($namespace === $ns)
133132
{
134133
$homepath = realpath($path);
135134
break;
@@ -138,38 +137,39 @@ public function run(array $params = [])
138137
}
139138
else
140139
{
141-
$ns = "App";
140+
$ns = 'App';
142141
}
143142

144143
// Migrations Config
145-
$config = new Migrations();
146-
147-
if ($config->type != 'timestamp' && $config->type != 'sequential')
148-
{
149-
CLI::error(lang('Migrations.invalidType', [$config->type]));
150-
return;
151-
}
152-
153-
// migration Type
154-
if ($config->type === 'timestamp')
155-
{
156-
$name = date('YmdHis_') . $name;
157-
} else if ($config->type === 'sequential')
158-
{
159-
// default with 001
160-
$sequence = $params[0] ?? '001';
161-
// number must be three digits
162-
if (! is_numeric($sequence) || strlen($sequence) != 3)
163-
{
164-
CLI::error(lang('Migrations.migNumberError'));
165-
return;
166-
}
167-
168-
$name = $sequence . '_' . $name;
169-
}
170-
171-
// full path
172-
$path = $homepath . '/Database/Migrations/' . $name . '.php';
144+
$config = new Migrations();
145+
146+
if ($config->type !== 'timestamp' && $config->type !== 'sequential')
147+
{
148+
CLI::error(lang('Migrations.invalidType', [$config->type]));
149+
return;
150+
}
151+
152+
// migration Type
153+
if ($config->type === 'timestamp')
154+
{
155+
$fileName = date('YmdHis_') . $name;
156+
}
157+
else if ($config->type === 'sequential')
158+
{
159+
// default with 001
160+
$sequence = $params[0] ?? '001';
161+
// number must be three digits
162+
if (! is_numeric($sequence) || strlen($sequence) !== 3)
163+
{
164+
CLI::error(lang('Migrations.migNumberError'));
165+
return;
166+
}
167+
168+
$fileName = $sequence . '_' . $name;
169+
}
170+
171+
// full path
172+
$path = $homepath . '/Database/Migrations/' . $fileName . '.php';
173173

174174
$template = <<<EOD
175175
<?php namespace $ns\Database\Migrations;
@@ -195,7 +195,7 @@ public function down()
195195
$template = str_replace('{name}', $name, $template);
196196

197197
helper('filesystem');
198-
if ( ! write_file($path, $template))
198+
if (! write_file($path, $template))
199199
{
200200
CLI::error(lang('Migrations.writeError'));
201201
return;

system/Email/Email.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public function setAttachmentCID($filename)
773773
if ($this->attachments[$i]['name'][0] === $filename)
774774
{
775775
$this->attachments[$i]['multipart'] = 'related';
776-
$this->attachments[$i]['cid'] = uniqid(basename($this->attachments[$i]['name'][0]).'@');
776+
$this->attachments[$i]['cid'] = uniqid(basename($this->attachments[$i]['name'][0]).'@', true);
777777

778778
return $this->attachments[$i]['cid'];
779779
}
@@ -943,7 +943,7 @@ protected function getMessageID()
943943
{
944944
$from = str_replace(['>', '<'], '', $this->headers['Return-Path']);
945945

946-
return '<'.uniqid('').strstr($from, '@').'>';
946+
return '<'.uniqid('', true).strstr($from, '@').'>';
947947
}
948948

949949
//--------------------------------------------------------------------
@@ -1336,7 +1336,7 @@ protected function buildMessage()
13361336
}
13371337
else
13381338
{
1339-
$boundary = uniqid('B_ALT_');
1339+
$boundary = uniqid('B_ALT_', true);
13401340
$hdr .= 'Content-Type: multipart/alternative; boundary="'.$boundary.'"';
13411341

13421342
$body .= $this->getMimeMessage().$this->newline.$this->newline
@@ -1371,7 +1371,7 @@ protected function buildMessage()
13711371

13721372
case 'plain-attach':
13731373

1374-
$boundary = uniqid('B_ATC_');
1374+
$boundary = uniqid('B_ATC_', true);
13751375
$hdr .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"';
13761376

13771377
if ($this->getProtocol() === 'mail')
@@ -1392,19 +1392,19 @@ protected function buildMessage()
13921392
break;
13931393
case 'html-attach':
13941394

1395-
$alt_boundary = uniqid('B_ALT_');
1395+
$alt_boundary = uniqid('B_ALT_', true);
13961396
$last_boundary = null;
13971397

13981398
if ($this->attachmentsHaveMultipart('mixed'))
13991399
{
1400-
$atc_boundary = uniqid('B_ATC_');
1400+
$atc_boundary = uniqid('B_ATC_', true);
14011401
$hdr .= 'Content-Type: multipart/mixed; boundary="'.$atc_boundary.'"';
14021402
$last_boundary = $atc_boundary;
14031403
}
14041404

14051405
if ($this->attachmentsHaveMultipart('related'))
14061406
{
1407-
$rel_boundary = uniqid('B_REL_');
1407+
$rel_boundary = uniqid('B_REL_', true);
14081408
$rel_boundary_header = 'Content-Type: multipart/related; boundary="'.$rel_boundary.'"';
14091409

14101410
if (isset($last_boundary))

system/Helpers/array_helper.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
if (! function_exists('array_value_dot'))
3+
if (! function_exists('dot_array_search'))
44
{
55
/**
66
* Searches an array through dot syntax. Supports
@@ -19,10 +19,10 @@ function dot_array_search(string $index, array $array)
1919
}
2020
}
2121

22-
if (! function_exists('array_search_dot'))
22+
if (! function_exists('_array_search_dot'))
2323
{
2424
/**
25-
* Used by array_value_dot to recursively search the
25+
* Used by dot_array_search to recursively search the
2626
* array with wildcards.
2727
*
2828
* @param array $indexes
@@ -37,13 +37,13 @@ function _array_search_dot(array $indexes, array $array)
3737
? array_shift($indexes)
3838
: null;
3939

40-
if (empty($currentIndex) || (! isset($array[$currentIndex]) && $currentIndex != '*'))
40+
if (empty($currentIndex) || (! isset($array[$currentIndex]) && $currentIndex !== '*'))
4141
{
4242
return null;
4343
}
4444

4545
// Handle Wildcard (*)
46-
if ($currentIndex == '*')
46+
if ($currentIndex === '*')
4747
{
4848
// If $array has more than 1 item, we have to loop over each.
4949
if (is_array($array))
@@ -80,5 +80,3 @@ function _array_search_dot(array $indexes, array $array)
8080
return $array[$currentIndex];
8181
}
8282
}
83-
84-

system/Test/FeatureTestCase.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use CodeIgniter\HTTP\UserAgent;
77
use CodeIgniter\HTTP\IncomingRequest;
88
use Config\App;
9+
use Config\Services;
910

1011
/**
1112
* Class FeatureTestCase
@@ -20,13 +21,15 @@ class FeatureTestCase extends CIDatabaseTestCase
2021
/**
2122
* If present, will override application
2223
* routes when using call().
24+
*
2325
* @var \CodeIgniter\Router\RouteCollection
2426
*/
2527
protected $routes;
2628

2729
/**
2830
* Values to be set in the SESSION global
2931
* before running the test.
32+
*
3033
* @var array
3134
*/
3235
protected $session = [];
@@ -100,13 +103,23 @@ public function call(string $method, string $path, array $params = null)
100103
$_SESSION = [];
101104

102105
$request = $this->setupRequest($method, $path, $params);
103-
104106
$request = $this->populateGlobals($method, $request, $params);
105107

108+
// Make sure any other classes that might call the request
109+
// instance get the right one.
110+
Services::injectMock('request', $request);
111+
$_SERVER['REQUEST_METHOD'] = $method;
112+
106113
$response = $this->app
107114
->setRequest($request)
108115
->run($this->routes, true);
109116

117+
// Clean up any open output buffers
118+
if (ob_get_level() > 0)
119+
{
120+
ob_end_clean();
121+
}
122+
110123
$featureResponse = new FeatureResponse($response);
111124

112125
return $featureResponse;
@@ -199,7 +212,7 @@ public function delete(string $path, array $params = null)
199212
*/
200213
public function options(string $path, array $params = null)
201214
{
202-
return $this->call('delete', $path, $params);
215+
return $this->call('options', $path, $params);
203216
}
204217

205218
/**
@@ -208,16 +221,16 @@ public function options(string $path, array $params = null)
208221
*
209222
* @param string $method
210223
* @param string|null $path
211-
* @param string|null $params
224+
* @param array|null $params
212225
*
213226
* @return \CodeIgniter\HTTP\IncomingRequest
214227
*/
215-
protected function setupRequest(string $method, string $path = null, string $params = null): IncomingRequest
228+
protected function setupRequest(string $method, string $path = null, array $params = null): IncomingRequest
216229
{
217230
$config = config(App::class);
218-
$uri = new URI($config->baseURL .'/'. trim($path, '/ '));
231+
$uri = new URI($config->baseURL . '/' . trim($path, '/ '));
219232

220-
$request = new IncomingRequest($config, clone($uri), $params, new UserAgent());
233+
$request = new IncomingRequest($config, clone($uri), $params, new UserAgent());
221234
$request->uri = $uri;
222235

223236
$request->setMethod($method);

system/View/Parser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ protected function parsePair(string $variable, array $data, string $template): a
371371
}
372372

373373
$temp = [];
374+
$pairs = [];
374375
$out = $match[1];
375376
foreach ($row as $key => $val)
376377
{
@@ -382,6 +383,7 @@ protected function parsePair(string $variable, array $data, string $template): a
382383

383384
if ( ! empty($pair))
384385
{
386+
$pairs[array_keys( $pair )[0]] = true;
385387
$temp = array_merge($temp, $pair);
386388
}
387389

@@ -402,7 +404,7 @@ protected function parsePair(string $variable, array $data, string $template): a
402404
// Now replace our placeholders with the new content.
403405
foreach ($temp as $pattern => $content)
404406
{
405-
$out = $this->replaceSingle($pattern, $content, $out, true);
407+
$out = $this->replaceSingle($pattern, $content, $out, !isset( $pairs[$pattern] ) );
406408
}
407409

408410
$str .= $out;

0 commit comments

Comments
 (0)