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 support #343

Open
wants to merge 3 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
23 changes: 15 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
"issues": "https://github.com/kdyby/doctrine/issues"
},
"require": {
"php": "^7.1",
"doctrine/orm": "~2.7",
"doctrine/dbal": "~2.9",
"kdyby/console": "^2.7.1",
"php": "^7.1 || ^8.0",
"doctrine/orm": "^2.10",
"doctrine/dbal": "~2.13.1",
"kdyby/console": "^4.0",
"kdyby/annotations": "^3.0",
"kdyby/doctrine-cache": "^3.0",
"kdyby/strict-objects": "^2.0",
"kdyby/doctrine-cache": "dev-php-8-support as 3.1.2",
"kdyby/strict-objects": "dev-updates",
"nette/di": "^3.0",
"nette/utils": "^3.0",
"nette/finder": "^2.5"
"nette/finder": "^2.5",
"symfony/console": "^4.4"
},
"suggest": {
"kdyby/doctrine-magic-accessors": "Fast-prototyping magic accessors trait for Doctrine entities",
Expand Down Expand Up @@ -61,5 +62,11 @@
"branch-alias": {
"dev-master": "4.0-dev"
}
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mhucik/DoctrineCache"
}
]
}
2 changes: 0 additions & 2 deletions src/Kdyby/Doctrine/Console/DbalDelegateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ protected function configure()
$this->setHelp($this->command->getHelp());
$this->setDefinition($this->command->getDefinition());
$this->setDescription($this->command->getDescription());

$this->addOption('connection', NULL, InputOption::VALUE_OPTIONAL, 'The connection to use for this command');
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Kdyby/Doctrine/Console/OrmDelegateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ protected function configure()
$this->setHelp($this->command->getHelp());
$this->setDefinition($this->command->getDefinition());
$this->setDescription($this->command->getDescription());

$this->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command');
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/Kdyby/Doctrine/DI/OrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Kdyby\Annotations\DI\AnnotationsExtension;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use ReflectionClass;

/**
* @author Filip Procházka <filip@prochazka.su>
Expand Down Expand Up @@ -243,7 +244,7 @@ protected function processEntityManager($name, array $defaults)
}

$metadataDriver = $builder->addDefinition($this->prefix($name . '.metadataDriver'))
->setClass(Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class)
->setClass(Doctrine\Persistence\Mapping\Driver\MappingDriverChain::class)
->setAutowired(FALSE);
/** @var \Nette\DI\ServiceDefinition $metadataDriver */

Expand Down Expand Up @@ -595,7 +596,7 @@ protected function processMetadataDriver(Nette\DI\ServiceDefinition $metadataDri
}

$impl = $driver instanceof \stdClass ? $driver->value : ($driver instanceof Statement ? $driver->getEntity() : (string) $driver);
list($driver) = CacheHelpers::filterArgs($driver);
[$driver] = CacheHelpers::filterArgs($driver);
/** @var Statement $driver */

/** @var string $impl */
Expand All @@ -618,7 +619,7 @@ protected function processMetadataDriver(Nette\DI\ServiceDefinition $metadataDri
$serviceName = $this->prefix($prefix . '.driver.' . str_replace('\\', '_', $namespace) . '.' . str_replace('\\', '_', $impl) . 'Impl');

$this->getContainerBuilder()->addDefinition($serviceName)
->setClass(Doctrine\Common\Persistence\Mapping\Driver\MappingDriver::class)
->setClass(Doctrine\Persistence\Mapping\Driver\MappingDriver::class)
->setFactory($driver->getEntity(), $driver->arguments)
->setAutowired(FALSE);

Expand Down Expand Up @@ -853,9 +854,9 @@ private function isKdybyEventsPresent()
private function addCollapsePathsToTracy(Method $init)
{
$blueScreen = \Tracy\Debugger::class . '::getBlueScreen()';
$commonDirname = dirname(Nette\Reflection\ClassType::from(Doctrine\Common\Version::class)->getFileName());
$commonDirname = dirname((new ReflectionClass(Doctrine\Common\ClassLoader::class))->getFileName());

$init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(Nette\Reflection\ClassType::from(Kdyby\Doctrine\Exception::class)->getFileName())]);
$init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname((new ReflectionClass(Kdyby\Doctrine\Exception::class))->getFileName())]);
$init->addBody($blueScreen . '->collapsePaths[] = ?;', [dirname(dirname(dirname(dirname($commonDirname))))]); // this should be vendor/doctrine
foreach ($this->proxyAutoloaders as $dir) {
$init->addBody($blueScreen . '->collapsePaths[] = ?;', [$dir]);
Expand Down
27 changes: 14 additions & 13 deletions src/Kdyby/Doctrine/Diagnostics/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

use Doctrine;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\Proxy;
use Doctrine\Common\Annotations\AnnotationException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\Persistence\Proxy;
use Kdyby;
use Nette;
use Nette\Utils\Strings;
use ReflectionClass;
use Tracy\Bar;
use Tracy\BlueScreen;
use Tracy\Debugger;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function startQuery($sql, array $params = NULL, array $types = NULL)
foreach (debug_backtrace(FALSE) as $row) {
if (isset($row['file']) && $this->filterTracePaths(realpath($row['file']))) {
if (isset($row['class']) && stripos($row['class'], '\\' . Proxy::MARKER) !== FALSE) {
if (!in_array(Doctrine\Common\Persistence\Proxy::class, class_implements($row['class']))) {
if (!in_array(Proxy::class, class_implements($row['class']))) {
continue;

} elseif (isset($row['function']) && $row['function'] === '__load') {
Expand Down Expand Up @@ -287,7 +288,7 @@ protected function renderStyles()
protected function processQuery(array $query)
{
$h = 'htmlspecialchars';
list($sql, $params, $time, $types, $source) = $query;
[$sql, $params, $time, $types, $source] = $query;

$s = self::highlightQuery(static::formatQuery($sql, (array) $params, (array) $types, $this->connection ? $this->connection->getDatabasePlatform() : NULL));
if ($source) {
Expand Down Expand Up @@ -318,10 +319,10 @@ public function renderQueryException($e)
return NULL;
}

list($sql, $params, , , $source) = $this->failed[spl_object_hash($e)];
[$sql, $params, , , $source] = $this->failed[spl_object_hash($e)];

} else {
list($sql, $params, , $types, $source) = end($this->queries) + range(1, 5);
[$sql, $params, , $types, $source] = end($this->queries) + range(1, 5);
}

if (!$sql) {
Expand Down Expand Up @@ -370,7 +371,7 @@ public static function renderException($e, Nette\DI\Container $dic)

} elseif ($e instanceof Doctrine\ORM\Mapping\MappingException) {
if ($invalidEntity = Strings::match($e->getMessage(), '~^Class "([\\S]+)" .*? is not .*? valid~i')) {
$refl = Nette\Reflection\ClassType::from($invalidEntity[1]);
$refl = new ReflectionClass($invalidEntity[1]);
$file = $refl->getFileName();
$errorLine = $refl->getStartLine();

Expand Down Expand Up @@ -494,7 +495,7 @@ protected function dumpQuery($query, $params, array $types = [], $source = NULL)

$e = NULL;
if ($source && is_array($source)) {
list($file, $line) = $source;
[$file, $line] = $source;
$e = '<p><b>File:</b> ' . self::editorLink($file, $line) . '</p>';
}

Expand Down Expand Up @@ -576,7 +577,7 @@ public static function formatQuery($query, $params, array $types = [], AbstractP
}

try {
list($query, $params, $types) = \Doctrine\DBAL\SQLParserUtils::expandListParameters($query, $params, $types);
[$query, $params, $types] = \Doctrine\DBAL\SQLParserUtils::expandListParameters($query, $params, $types);
} catch (Doctrine\DBAL\SQLParserUtilsException $e) {
}

Expand Down Expand Up @@ -648,7 +649,7 @@ public static function highlightAnnotationLine(AnnotationException $e)
return FALSE;
}

$refl = Nette\Reflection\ClassType::from($context['class']);
$refl = new ReflectionClass($context['class']);
$file = $refl->getFileName();
$line = NULL;

Expand All @@ -673,7 +674,7 @@ public static function highlightAnnotationLine(AnnotationException $e)


/**
* @param \Reflector|\Nette\Reflection\ClassType|\Nette\Reflection\Method|\Nette\Reflection\Property $refl
* @param \Reflector|\ReflectionClass|\ReflectionMethod|\ReflectionProperty $refl
* @param \Exception|\Throwable $e
* @param int|NULL $startLine
* @return int|NULL
Expand Down Expand Up @@ -711,7 +712,7 @@ public static function calculateErrorLine(\Reflector $refl, $e, $startLine = NUL


/**
* @param \Reflector|\Nette\Reflection\ClassType|\Nette\Reflection\Method $refl
* @param \Reflector|\ReflectionClass|\ReflectionMethod $refl
* @param int $symbolPos
* @return int
*/
Expand All @@ -731,7 +732,7 @@ protected static function calculateAffectedLine(\Reflector $refl, $symbolPos)


/**
* @param \Reflector|Nette\Reflection\ClassType|Nette\Reflection\Method $refl
* @param \Reflector|\ReflectionClass|\ReflectionMethod $refl
* @param string $annotation
* @return string
*/
Expand Down Expand Up @@ -762,7 +763,7 @@ private static function findRenamed(\Reflector $refl, $annotation)


/**
* @param \Nette\Reflection\ClassType|\Nette\Reflection\Method|\Reflector $refl
* @param \ReflectionClass|\ReflectionMethod|\Reflector $refl
* @param int|null $atPos
* @return string
*/
Expand Down
19 changes: 9 additions & 10 deletions src/Kdyby/Doctrine/Entities/SerializableMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

use Kdyby;
use Kdyby\Doctrine\StaticClassException;
use Nette;
use Nette\Reflection\ClassType;
use ReflectionClass;
use Serializable;


Expand All @@ -25,12 +24,12 @@ final class SerializableMixin
{

/**
* @var array|\Nette\Reflection\ClassType[]
* @var array|\ReflectionClass[]
*/
private static $classes = [];

/**
* @var array|\Nette\Reflection\Property
* @var array|\ReflectionProperty
*/
private static $properties = [];

Expand Down Expand Up @@ -60,10 +59,10 @@ public static function serialize(Serializable $object)
$allowed = (array)$object->__sleep();
}

$class = ClassType::from($object);
$class = new ReflectionClass($object);

do {
/** @var \Nette\Reflection\Property $propertyRefl */
/** @var \ReflectionProperty $propertyRefl */
foreach ($class->getProperties() as $propertyRefl) {
if ($allowed !== FALSE && !in_array($propertyRefl->getName(), $allowed)) {
continue;
Expand Down Expand Up @@ -99,7 +98,7 @@ public static function unserialize(Serializable $object, $serialized)

foreach ($data as $target => $value) {
if (strpos($target, '::') !== FALSE) {
list($class, $name) = explode('::', $target, 2);
[$class, $name] = explode('::', $target, 2);
$propertyRefl = self::getProperty($name, $class);

} else {
Expand All @@ -122,7 +121,7 @@ public static function unserialize(Serializable $object, $serialized)
* @param string $name
* @param string|object $class
*
* @return \Nette\Reflection\Property
* @return \ReflectionProperty
*/
private static function getProperty($name, $class)
{
Expand All @@ -132,10 +131,10 @@ private static function getProperty($name, $class)
}

if (!isset(self::$classes[$class])) {
self::$classes[$class] = ClassType::from($class);
self::$classes[$class] = new ReflectionClass($class);
}

/** @var \Nette\Reflection\Property $propRefl */
/** @var \ReflectionProperty $propRefl */
$propRefl = self::$classes[$class]->getProperty($name);
$propRefl->setAccessible(TRUE);

Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ClassMetadata extends Doctrine\ORM\Mapping\ClassMetadata
public function getReflectionClass()
{
if ($this->reflClass === NULL) {
$this->reflClass = new Nette\Reflection\ClassType($this->name);
$this->reflClass = new \ReflectionClass($this->name);
}

return $this->reflClass;
Expand Down
19 changes: 7 additions & 12 deletions src/Kdyby/Doctrine/Mapping/RuntimeReflectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@

use Doctrine;
use Kdyby;
use Nette;
use Nette\Reflection;

use ReflectionClass;
use ReflectionProperty;


/**
* @author Filip Procházka <filip@prochazka.su>
*/
class RuntimeReflectionService extends Doctrine\Common\Persistence\Mapping\RuntimeReflectionService
class RuntimeReflectionService extends Doctrine\Persistence\Mapping\RuntimeReflectionService
{

/**
* Return a reflection class instance or null
*
* @param string $class
* @return \Nette\Reflection\ClassType
*/
public function getClass($class)
public function getClass($class): ?ReflectionClass
{
return new Reflection\ClassType($class);
return new ReflectionClass($class);
}


Expand All @@ -41,12 +37,11 @@ public function getClass($class)
*
* @param string $class
* @param string $property
* @return \Nette\Reflection\Property|NULL
*/
public function getAccessibleProperty($class, $property)
public function getAccessibleProperty($class, $property): ?ReflectionProperty
{
try {
$property = new Reflection\Property($class, $property);
$property = new ReflectionProperty($class, $property);
$property->setAccessible(TRUE);

return $property;
Expand Down
2 changes: 1 addition & 1 deletion src/Kdyby/Doctrine/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace Kdyby\Doctrine;

use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\AbstractManagerRegistry;
use Kdyby;
use Nette;

Expand Down