From 17279594c617b44e7206afdccd789bc771404f1c Mon Sep 17 00:00:00 2001 From: Rob Gridley Date: Mon, 19 Sep 2022 09:43:49 -0400 Subject: [PATCH 1/2] PHP 8+ fix for Model::isBuilderMethod() --- src/Model.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Model.php b/src/Model.php index 50af4c3..50e7e84 100644 --- a/src/Model.php +++ b/src/Model.php @@ -4,8 +4,9 @@ use ArrayAccess; use JsonSerializable; -use Pace\XPath\Builder; use Pace\Model\Attachments; +use Pace\XPath\Builder; +use ReflectionMethod; use UnexpectedValueException; class Model implements ArrayAccess, JsonSerializable @@ -633,7 +634,16 @@ protected function guessPrimaryKey() */ protected function isBuilderMethod($name) { - return method_exists(Builder::class, $name) && is_callable([Builder::class, $name]); + if (version_compare(PHP_VERSION, '8.0.0', '>=')) { + if (method_exists(Builder::class, $name)) { + $reflection = new ReflectionMethod(Builder::class, $name); + return $reflection->isPublic(); + } else { + return false; + } + } else { + return method_exists(Builder::class, $name) && is_callable([Builder::class, $name]); + } } /** From 065b401aacd55a5c1c1b1539c2cf83ab8ac18e01 Mon Sep 17 00:00:00 2001 From: Rob Gridley Date: Thu, 13 Oct 2022 13:29:49 -0400 Subject: [PATCH 2/2] Switch to new Doctine Inflector API to support versions 1.4 and 2.0 --- composer.json | 2 +- src/Type.php | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index fe8c220..48a76be 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "ext-fileinfo": "*", "ext-soap": "*", "nesbot/carbon": "^1.20 || ^2.0", - "doctrine/inflector": "~1.0" + "doctrine/inflector": "^1.4 || ^2.0" }, "require-dev": { "phpunit/phpunit": "^8.5", diff --git a/src/Type.php b/src/Type.php index ec626b7..f66a9b1 100644 --- a/src/Type.php +++ b/src/Type.php @@ -2,7 +2,7 @@ namespace Pace; -use Doctrine\Common\Inflector\Inflector; +use Doctrine\Inflector\InflectorFactory; class Type { @@ -62,6 +62,13 @@ class Type 'FileAttachment' => 'attachment', ]; + /** + * The Doctrine Inflector instance. + * + * @var \Doctrine\Inflector\Inflector|null + */ + protected static $inflector; + /** * Convert a name to camel case. * @@ -92,7 +99,11 @@ public static function modelify($name) */ public static function singularize($name) { - return Inflector::singularize($name); + if (is_null(static::$inflector)) { + static::$inflector = InflectorFactory::create()->build(); + } + + return static::$inflector->singularize($name); } /**