Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8+ fix for Model::isBuilderMethod() #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
}
}

/**
Expand Down
15 changes: 13 additions & 2 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Pace;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;

class Type
{
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}

/**
Expand Down