Skip to content

Commit aa2a589

Browse files
committed
Merge branch 'develop' into admin/scripts
2 parents a61c7fd + a4b9526 commit aa2a589

16 files changed

Lines changed: 483 additions & 89 deletions

File tree

application/Config/Pager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Pager extends BaseConfig
2020
public $templates = [
2121
'default_full' => 'CodeIgniter\Pager\Views\default_full',
2222
'default_simple' => 'CodeIgniter\Pager\Views\default_simple',
23+
'default_head' => 'CodeIgniter\Pager\Views\default_head',
2324
];
2425

2526
/*

system/Autoloader/FileLocator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ public function listFiles(string $path): array
315315
}
316316

317317
$tempFiles = get_filenames($fullPath, true);
318-
//CLI::newLine($tempFiles);
319318

320319
if (! empty($tempFiles))
321320
{

system/HTTP/CURLRequest.php

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
* A lightweight HTTP client for sending synchronous HTTP requests
4848
* via cURL.
4949
*
50-
* @todo Add a few helpers for dealing with JSON, forms, files, etc.
51-
*
5250
* @package CodeIgniter\HTTP
5351
*/
5452
class CURLRequest extends Request
@@ -267,6 +265,68 @@ public function put(string $url, array $options = []): ResponseInterface
267265

268266
//--------------------------------------------------------------------
269267

268+
/**
269+
* Set the HTTP Authentication.
270+
*
271+
* @param string $username
272+
* @param string $password
273+
* @param string $type basic or digest
274+
*
275+
* @return $this
276+
*/
277+
public function setAuth(string $username, string $password, string $type = 'basic')
278+
{
279+
$this->config['auth'] = [
280+
$username,
281+
$password,
282+
$type,
283+
];
284+
285+
return $this;
286+
}
287+
288+
//--------------------------------------------------------------------
289+
290+
/**
291+
* Set form data to be sent.
292+
*
293+
* @param array $params
294+
* @param boolean $multipart Set TRUE if you are sending CURLFiles
295+
*
296+
* @return $this
297+
*/
298+
public function setForm(array $params, bool $multipart = false)
299+
{
300+
if ($multipart)
301+
{
302+
$this->config['multipart'] = $params;
303+
}
304+
else
305+
{
306+
$this->config['form_params'] = $params;
307+
}
308+
309+
return $this;
310+
}
311+
312+
//--------------------------------------------------------------------
313+
314+
/**
315+
* Set JSON data to be sent.
316+
*
317+
* @param mixed $data
318+
*
319+
* @return $this
320+
*/
321+
public function setJSON($data)
322+
{
323+
$this->config['json'] = $data;
324+
325+
return $this;
326+
}
327+
328+
//--------------------------------------------------------------------
329+
270330
/**
271331
* Sets the correct settings based on the options array
272332
* passed in.

system/HTTP/Message.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ public function getHeaderLine(string $name): string
254254
/**
255255
* Sets a header and it's value.
256256
*
257-
* @param string $name
258-
* @param string $value
257+
* @param string $name
258+
* @param array|null|string $value
259259
*
260260
* @return Message|Response
261261
*/

system/HTTP/Response.php

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@
4040
use Config\App;
4141
use Config\Format;
4242
use CodeIgniter\HTTP\Exceptions\HTTPException;
43-
44-
/**
45-
* Redirect exception
46-
*/
47-
class RedirectException extends \Exception
48-
{
49-
50-
}
43+
use CodeIgniter\Pager\PagerInterface;
5144

5245
/**
5346
* Representation of an outgoing, getServer-side response.
@@ -310,8 +303,8 @@ public function getStatusCode(): int
310303
* provided status code; if none is provided, will
311304
* default to the IANA name.
312305
*
313-
* @return self
314-
* @throws \InvalidArgumentException For invalid status code arguments.
306+
* @return $this
307+
* @throws \CodeIgniter\HTTP\Exceptions\HTTPException For invalid status code arguments.
315308
*/
316309
public function setStatusCode(int $code, string $reason = '')
317310
{
@@ -383,6 +376,43 @@ public function setDate(\DateTime $date)
383376

384377
//--------------------------------------------------------------------
385378

379+
/**
380+
* Set the Link Header
381+
*
382+
* @param \CodeIgniter\Pager\PagerInterface $pager
383+
*
384+
* @see http://tools.ietf.org/html/rfc5988
385+
*
386+
* @return Response
387+
*/
388+
public function setLink(PagerInterface $pager)
389+
{
390+
$links = '';
391+
392+
if ($previous = $pager->getPreviousPageURI())
393+
{
394+
$links .= '<' . $pager->getPageURI($pager->getFirstPage()) . '>; rel="first",';
395+
$links .= '<' . $previous . '>; rel="prev"';
396+
}
397+
398+
if (($next = $pager->getNextPageURI()) && $previous)
399+
{
400+
$links .= ',';
401+
}
402+
403+
if ($next)
404+
{
405+
$links .= '<' . $next . '>; rel="next",';
406+
$links .= '<' . $pager->getPageURI($pager->getLastPage()) . '>; rel="last"';
407+
}
408+
409+
$this->setHeader('Link', $links);
410+
411+
return $this;
412+
}
413+
414+
//--------------------------------------------------------------------
415+
386416
/**
387417
* Sets the Content Type header for this response with the mime type
388418
* and, optionally, the charset.
@@ -411,7 +441,7 @@ public function setContentType(string $mime, string $charset = 'UTF-8')
411441
/**
412442
* Converts the $body into JSON and sets the Content Type header.
413443
*
414-
* @param $body
444+
* @param array|string $body
415445
*
416446
* @return $this
417447
*/
@@ -428,13 +458,18 @@ public function setJSON($body)
428458
* Returns the current body, converted to JSON is it isn't already.
429459
*
430460
* @return mixed|string
461+
*
462+
* @throws \InvalidArgumentException If the body property is not array.
431463
*/
432464
public function getJSON()
433465
{
434466
$body = $this->body;
435467

436468
if ($this->bodyFormat !== 'json')
437469
{
470+
/**
471+
* @var Format $config
472+
*/
438473
$config = config(Format::class);
439474
$formatter = $config->getFormatter('application/json');
440475

@@ -449,7 +484,7 @@ public function getJSON()
449484
/**
450485
* Converts $body into XML, and sets the correct Content-Type.
451486
*
452-
* @param $body
487+
* @param array|string $body
453488
*
454489
* @return $this
455490
*/
@@ -466,13 +501,17 @@ public function setXML($body)
466501
* Retrieves the current body into XML and returns it.
467502
*
468503
* @return mixed|string
504+
* @throws \InvalidArgumentException If the body property is not array.
469505
*/
470506
public function getXML()
471507
{
472508
$body = $this->body;
473509

474510
if ($this->bodyFormat !== 'xml')
475511
{
512+
/**
513+
* @var Format $config
514+
*/
476515
$config = config(Format::class);
477516
$formatter = $config->getFormatter('application/xml');
478517

@@ -488,10 +527,11 @@ public function getXML()
488527
* Handles conversion of the of the data into the appropriate format,
489528
* and sets the correct Content-Type header for our response.
490529
*
491-
* @param $body
492-
* @param string $format Valid: json, xml
530+
* @param string|array $body
531+
* @param string $format Valid: json, xml
493532
*
494533
* @return mixed
534+
* @throws \InvalidArgumentException If the body property is not string or array.
495535
*/
496536
protected function formatBody($body, string $format)
497537
{
@@ -502,6 +542,9 @@ protected function formatBody($body, string $format)
502542
// Nothing much to do for a string...
503543
if (! is_string($body))
504544
{
545+
/**
546+
* @var Format $config
547+
*/
505548
$config = config(Format::class);
506549
$formatter = $config->getFormatter($mime);
507550

@@ -718,7 +761,7 @@ public function getBody()
718761
* @param integer $code The type of redirection, defaults to 302
719762
*
720763
* @return $this
721-
* @throws \CodeIgniter\HTTP\RedirectException
764+
* @throws \CodeIgniter\HTTP\Exceptions\HTTPException For invalid status code.
722765
*/
723766
public function redirect(string $uri, string $method = 'auto', int $code = null)
724767
{
@@ -775,6 +818,8 @@ public function redirect(string $uri, string $method = 'auto', int $code = null)
775818
* @param string $prefix Cookie name prefix
776819
* @param boolean|false $secure Whether to only transfer cookies via SSL
777820
* @param boolean|false $httponly Whether only make the cookie accessible via HTTP (no javascript)
821+
*
822+
* @return $this
778823
*/
779824
public function setCookie(
780825
$name,
@@ -851,9 +896,9 @@ public function setCookie(
851896
/**
852897
* Checks to see if the Response has a specified cookie or not.
853898
*
854-
* @param string $name
855-
* @param null $value
856-
* @param string $prefix
899+
* @param string $name
900+
* @param string|null $value
901+
* @param string $prefix
857902
*
858903
* @return boolean
859904
*/
@@ -887,8 +932,8 @@ public function hasCookie(string $name, $value = null, string $prefix = '')
887932
/**
888933
* Returns the cookie
889934
*
890-
* @param string $name
891-
* @param string $prefix
935+
* @param string|null $name
936+
* @param string $prefix
892937
*
893938
* @return mixed
894939
*/
@@ -924,12 +969,14 @@ public function getCookie(string $name = null, string $prefix = '')
924969
* @param string $domain
925970
* @param string $path
926971
* @param string $prefix
972+
*
973+
* @return $this
927974
*/
928975
public function deleteCookie($name = '', string $domain = '', string $path = '/', string $prefix = '')
929976
{
930977
if (empty($name))
931978
{
932-
return;
979+
return $this;
933980
}
934981

935982
if ($prefix === '' && $this->cookiePrefix !== '')
@@ -989,6 +1036,8 @@ protected function sendCookies()
9891036
* @param string $filename The path to the file to send
9901037
* @param string $data The data to be downloaded
9911038
* @param boolean $setMime Whether to try and send the actual MIME type
1039+
*
1040+
* @return \CodeIgniter\HTTP\DownloadResponse|null
9921041
*/
9931042
public function download(string $filename = '', $data = '', bool $setMime = false)
9941043
{

system/Pager/Pager.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,36 +325,33 @@ public function getPageURI(int $page = null, string $group = 'default', $returnO
325325
{
326326
$this->ensureGroup($group);
327327

328+
/**
329+
* @var \CodeIgniter\HTTP\URI $uri
330+
*/
328331
$uri = $this->groups[$group]['uri'];
329332

330333
$segment = $this->segment[$group] ?? 0;
331334

335+
if ($segment)
336+
{
337+
$uri->setSegment($segment, $page);
338+
}
339+
else
340+
{
341+
$uri->addQuery('page', $page);
342+
}
343+
332344
if ($this->only)
333345
{
334346
$query = array_intersect_key($_GET, array_flip($this->only));
335347

336-
if ($segment > 0)
337-
{
338-
$uri->setSegment($segment, $page);
339-
}
340-
else
348+
if (! $segment)
341349
{
342350
$query['page'] = $page;
343351
}
344352

345353
$uri->setQueryArray($query);
346354
}
347-
else
348-
{
349-
if ($segment > 0)
350-
{
351-
$uri->setSegment($segment, $page);
352-
}
353-
else
354-
{
355-
$uri->addQuery('page', $page);
356-
}
357-
}
358355

359356
return $returnObject === true ? $uri : (string) $uri;
360357
}

0 commit comments

Comments
 (0)