Skip to content

Commit 0417bf2

Browse files
committed
PHP 8.1+ compat and various dependency updates
1 parent a66bf03 commit 0417bf2

File tree

8 files changed

+65
-40
lines changed

8 files changed

+65
-40
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
17+
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1']
1818

1919
steps:
2020
- name: Checkout
@@ -63,7 +63,7 @@ jobs:
6363

6464
strategy:
6565
matrix:
66-
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
66+
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1']
6767

6868
steps:
6969
- name: Checkout
@@ -114,7 +114,7 @@ jobs:
114114

115115
strategy:
116116
matrix:
117-
php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
117+
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1']
118118

119119
steps:
120120
- name: Checkout

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
[![Build Status](https://github.com/modxcms/xpdo/workflows/CI/badge.svg?branch=3.x)](https://github.com/modxcms/xpdo/workflows/CI/badge.svg?branch=3.x)
44

5-
xPDO is an ultra-light object-relational bridge library for PHP 5.6+. It is a standalone library and can be used with any framework or DI container.
5+
xPDO is an ultra-light object-relational bridge library for PHP. It is a standalone library and can be used with any framework or DI container.
66

77
## Installation
88

99
xPDO can be installed in your project via composer:
1010

11-
composer require xpdo/xpdo ^3.0
11+
composer require xpdo/xpdo
1212

1313

1414
## Usage

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.6",
18+
"php": ">=7.2.5",
1919
"ext-PDO": "*",
2020
"ext-json": "*",
2121
"ext-simplexml": "*",
22-
"symfony/console": "~2.8|~3.4",
23-
"psr/container": "^1.0"
22+
"symfony/console": "^5.4",
23+
"psr/container": "^2.0.1"
2424
},
2525
"require-dev": {
26-
"yoast/phpunit-polyfills": "^0.2.0"
26+
"yoast/phpunit-polyfills": "^1.0"
2727
},
2828
"suggest": {
2929
"ext-redis": "Allows caching using Redis"

src/xPDO/Console/Command/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function loadConfig(OutputInterface $output, $config = null)
2828
if (is_readable($location)) {
2929
$config = $location;
3030
break;
31-
};
31+
}
3232
}
3333
}
3434
if (!empty($config) && is_readable($config)) {

src/xPDO/xPDOContainer.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
namespace xPDO;
1212

1313

14+
use ArrayAccess;
15+
use Exception;
1416
use Psr\Container\ContainerExceptionInterface;
1517
use Psr\Container\ContainerInterface;
1618
use Psr\Container\NotFoundExceptionInterface;
@@ -22,7 +24,7 @@
2224
*
2325
* @package xPDO
2426
*/
25-
class xPDOContainer implements ContainerInterface, \ArrayAccess
27+
class xPDOContainer implements ContainerInterface, ArrayAccess
2628
{
2729
private $entries = array();
2830

@@ -32,7 +34,7 @@ class xPDOContainer implements ContainerInterface, \ArrayAccess
3234
* @param string $id The identifier for the entry.
3335
* @param mixed $entry The entry to add.
3436
*/
35-
public function add($id, $entry)
37+
public function add(string $id, $entry)
3638
{
3739
$this->offsetSet($id, $entry);
3840
}
@@ -47,12 +49,12 @@ public function add($id, $entry)
4749
*
4850
* @return mixed Entry.
4951
*/
50-
public function get($id)
52+
public function get(string $id)
5153
{
5254
if ($this->has($id)) {
5355
try {
5456
return $this->offsetGet($id);
55-
} catch (\Exception $e) {
57+
} catch (Exception $e) {
5658
throw new ContainerException($e->getMessage(), $e->getCode(), $e);
5759
}
5860
}
@@ -65,29 +67,29 @@ public function get($id)
6567
*
6668
* @param string $id Identifier of the entry to look for.
6769
*
68-
* @return boolean
70+
* @return bool
6971
*/
70-
public function has($id)
72+
public function has(string $id): bool
7173
{
7274
return $this->offsetExists($id);
7375
}
7476

7577
/**
76-
* Whether a offset exists
78+
* Whether an offset exists
7779
*
7880
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
7981
*
8082
* @param mixed $offset <p>
8183
* An offset to check for.
8284
* </p>
8385
*
84-
* @return boolean true on success or false on failure.
86+
* @return bool true on success or false on failure.
8587
* </p>
8688
* <p>
87-
* The return value will be casted to boolean if non-boolean was returned.
89+
* The return value will be cast to boolean if non-boolean was returned.
8890
* @since 5.0.0
8991
*/
90-
public function offsetExists($offset)
92+
public function offsetExists($offset): bool
9193
{
9294
return array_key_exists($offset, $this->entries);
9395
}
@@ -124,7 +126,7 @@ public function offsetGet($offset)
124126
* @return void
125127
* @since 5.0.0
126128
*/
127-
public function offsetSet($offset, $value)
129+
public function offsetSet($offset, $value): void
128130
{
129131
$this->entries[$offset] = $value;
130132
}
@@ -141,7 +143,7 @@ public function offsetSet($offset, $value)
141143
* @return void
142144
* @since 5.0.0
143145
*/
144-
public function offsetUnset($offset)
146+
public function offsetUnset($offset): void
145147
{
146148
unset($this->entries[$offset]);
147149
}

src/xPDO/xPDOException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010

1111
namespace xPDO;
1212

13+
use Exception;
14+
1315
/**
1416
* Represents an xPDO-related Exception.
1517
*
1618
* @package xPDO
1719
*/
18-
class xPDOException extends \Exception
20+
class xPDOException extends Exception
1921
{
2022

2123
}

src/xPDO/xPDOIterator.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
namespace xPDO;
1212

1313

14+
use Iterator;
15+
use PDO;
16+
use PDOStatement;
17+
use xPDO\Om\xPDOQuery;
18+
1419
/**
1520
* An iterable representation of an xPDOObject result set.
1621
*
@@ -20,28 +25,30 @@
2025
*
2126
* @package xpdo
2227
*/
23-
class xPDOIterator implements \Iterator {
28+
class xPDOIterator implements Iterator
29+
{
2430
private $xpdo = null;
2531
private $index = 0;
2632
private $current = null;
27-
/** @var null|\PDOStatement */
33+
/** @var null|PDOStatement */
2834
private $stmt = null;
2935
private $class = null;
30-
private $alias = null;
31-
/** @var null|int|string|array|\xPDO\Om\xPDOQuery */
36+
private $alias;
37+
/** @var null|int|string|array|xPDOQuery */
3238
private $criteria = null;
3339
private $criteriaType = 'xPDOQuery';
3440
private $cacheFlag = false;
3541

3642
/**
3743
* Construct a new xPDOIterator instance (do not call directly).
3844
*
39-
* @see xPDO::getIterator()
4045
* @param xPDO &$xpdo A reference to a valid xPDO instance.
4146
* @param array $options An array of options for the iterator.
4247
* @return xPDOIterator An xPDOIterator instance.
48+
* @see xPDO::getIterator()
4349
*/
44-
function __construct(& $xpdo, array $options= array()) {
50+
public function __construct(xPDO &$xpdo, array $options = [])
51+
{
4552
$this->xpdo =& $xpdo;
4653
if (isset($options['class'])) {
4754
$this->class = $this->xpdo->loadClass($options['class']);
@@ -67,9 +74,12 @@ function __construct(& $xpdo, array $options= array()) {
6774
$this->alias = $this->criteria->getAlias();
6875
}
6976
}
77+
78+
return $this;
7079
}
7180

72-
public function rewind() {
81+
public function rewind()
82+
{
7383
$this->index = 0;
7484
if (!empty($this->stmt)) {
7585
$this->stmt->closeCursor();
@@ -86,15 +96,18 @@ public function rewind() {
8696
}
8797
}
8898

89-
public function current() {
99+
public function current()
100+
{
90101
return $this->current;
91102
}
92103

93-
public function key() {
104+
public function key()
105+
{
94106
return $this->index;
95107
}
96108

97-
public function next() {
109+
public function next()
110+
{
98111
$this->fetch();
99112
if (!$this->valid()) {
100113
$this->index = null;
@@ -104,7 +117,8 @@ public function next() {
104117
return $this->current();
105118
}
106119

107-
public function valid() {
120+
public function valid(): bool
121+
{
108122
return ($this->current !== null);
109123
}
110124

@@ -114,10 +128,15 @@ public function valid() {
114128
* Calls the _loadInstance() method for the specified class, so it properly
115129
* inherits behavior from xPDOObject derivatives.
116130
*/
117-
protected function fetch() {
118-
$row = $this->stmt->fetch(\PDO::FETCH_ASSOC);
131+
protected function fetch()
132+
{
133+
$row = $this->stmt->fetch(PDO::FETCH_ASSOC);
119134
if (is_array($row) && !empty($row)) {
120-
$instance = $this->xpdo->call($this->class, '_loadInstance', array(& $this->xpdo, $this->class, $this->alias, $row));
135+
$instance = $this->xpdo->call(
136+
$this->class,
137+
'_loadInstance',
138+
[& $this->xpdo, $this->class, $this->alias, $row]
139+
);
121140
if ($instance === null) {
122141
$this->fetch();
123142
} else {

src/xPDO/xPDOMap.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
namespace xPDO;
1212

1313

14-
class xPDOMap implements \ArrayAccess
14+
use ArrayAccess;
15+
16+
class xPDOMap implements ArrayAccess
1517
{
1618
/**
1719
* @var array An object/relational map by class.
@@ -24,11 +26,11 @@ class xPDOMap implements \ArrayAccess
2426

2527
public function __construct(xPDO &$xpdo)
2628
{
27-
$this->map = array();
29+
$this->map = [];
2830
$this->xpdo =& $xpdo;
2931
}
3032

31-
public function offsetExists($offset)
33+
public function offsetExists($offset): bool
3234
{
3335
if (!isset($this->map[$offset])) {
3436
$this->_checkClass($offset);

0 commit comments

Comments
 (0)