From 9aa5037ce9b2688cf7753c30490d3cbb1bbe2842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Hu=C4=8D=C3=ADk?= Date: Tue, 12 Apr 2022 13:16:41 +0200 Subject: [PATCH 1/3] Update packages and add PHP 8 support --- composer.json | 11 +- src/Kdyby/Doctrine/ConnectionHelper.php | 42 +++ .../Doctrine/Console/DbalDelegateCommand.php | 2 - .../Doctrine/Console/OrmDelegateCommand.php | 2 - src/Kdyby/Doctrine/DI/OrmExtension.php | 11 +- src/Kdyby/Doctrine/Diagnostics/Panel.php | 27 +- .../Doctrine/Entities/SerializableMixin.php | 19 +- src/Kdyby/Doctrine/Geo/Coordinates.php | 134 +++++++++ src/Kdyby/Doctrine/Geo/Element.php | 265 ++++++++++++++++++ src/Kdyby/Doctrine/Mapping/ClassMetadata.php | 2 +- .../Mapping/RuntimeReflectionService.php | 19 +- src/Kdyby/Doctrine/Registry.php | 2 +- 12 files changed, 484 insertions(+), 52 deletions(-) create mode 100644 src/Kdyby/Doctrine/ConnectionHelper.php create mode 100644 src/Kdyby/Doctrine/Geo/Coordinates.php create mode 100644 src/Kdyby/Doctrine/Geo/Element.php diff --git a/composer.json b/composer.json index 88803804..8a71b5ca 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,12 @@ "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", + "kdyby/console": "dev-master", "kdyby/annotations": "^3.0", - "kdyby/doctrine-cache": "^3.0", - "kdyby/strict-objects": "^2.0", + "kdyby/doctrine-cache": "^3.1.2", + "kdyby/strict-objects": "dev-updates", "nette/di": "^3.0", "nette/utils": "^3.0", "nette/finder": "^2.5" diff --git a/src/Kdyby/Doctrine/ConnectionHelper.php b/src/Kdyby/Doctrine/ConnectionHelper.php new file mode 100644 index 00000000..744b6206 --- /dev/null +++ b/src/Kdyby/Doctrine/ConnectionHelper.php @@ -0,0 +1,42 @@ +_connection = $connection; + } + + /** + * Retrieves the Doctrine database Connection. + * + * @return Connection + */ + public function getConnection() + { + return $this->_connection; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'connection'; + } +} diff --git a/src/Kdyby/Doctrine/Console/DbalDelegateCommand.php b/src/Kdyby/Doctrine/Console/DbalDelegateCommand.php index 2aba7c2d..d6926d53 100644 --- a/src/Kdyby/Doctrine/Console/DbalDelegateCommand.php +++ b/src/Kdyby/Doctrine/Console/DbalDelegateCommand.php @@ -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'); } /** diff --git a/src/Kdyby/Doctrine/Console/OrmDelegateCommand.php b/src/Kdyby/Doctrine/Console/OrmDelegateCommand.php index 00bf7dc0..308eea0b 100644 --- a/src/Kdyby/Doctrine/Console/OrmDelegateCommand.php +++ b/src/Kdyby/Doctrine/Console/OrmDelegateCommand.php @@ -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'); } /** diff --git a/src/Kdyby/Doctrine/DI/OrmExtension.php b/src/Kdyby/Doctrine/DI/OrmExtension.php index daa84659..4f18dd68 100644 --- a/src/Kdyby/Doctrine/DI/OrmExtension.php +++ b/src/Kdyby/Doctrine/DI/OrmExtension.php @@ -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 @@ -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 */ @@ -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 */ @@ -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); @@ -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]); diff --git a/src/Kdyby/Doctrine/Diagnostics/Panel.php b/src/Kdyby/Doctrine/Diagnostics/Panel.php index f90da8f8..80283ed7 100644 --- a/src/Kdyby/Doctrine/Diagnostics/Panel.php +++ b/src/Kdyby/Doctrine/Diagnostics/Panel.php @@ -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; @@ -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') { @@ -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) { @@ -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) { @@ -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(); @@ -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 = '

File: ' . self::editorLink($file, $line) . '

'; } @@ -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) { } @@ -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; @@ -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 @@ -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 */ @@ -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 */ @@ -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 */ diff --git a/src/Kdyby/Doctrine/Entities/SerializableMixin.php b/src/Kdyby/Doctrine/Entities/SerializableMixin.php index 9ff4982e..b6298a56 100644 --- a/src/Kdyby/Doctrine/Entities/SerializableMixin.php +++ b/src/Kdyby/Doctrine/Entities/SerializableMixin.php @@ -12,8 +12,7 @@ use Kdyby; use Kdyby\Doctrine\StaticClassException; -use Nette; -use Nette\Reflection\ClassType; +use ReflectionClass; use Serializable; @@ -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 = []; @@ -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; @@ -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 { @@ -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) { @@ -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); diff --git a/src/Kdyby/Doctrine/Geo/Coordinates.php b/src/Kdyby/Doctrine/Geo/Coordinates.php new file mode 100644 index 00000000..52c33af4 --- /dev/null +++ b/src/Kdyby/Doctrine/Geo/Coordinates.php @@ -0,0 +1,134 @@ + + */ +class Coordinates +{ + + use \Kdyby\StrictObjects\Scream; + + /** + * @var float + */ + private $lon = 0.0; + + /** + * @var float + */ + private $lat = 0.0; + + /** + * @var string + */ + private $separator = ' '; + + /** + * @var int + */ + private $precision = 13; + + + + /** + * @param float|string $lon + * @param float|string $lat + */ + public function __construct($lon, $lat) + { + $this->lon = (float) $lon; + $this->lat = (float) $lat; + } + + + + /** + * @return float + */ + public function getLatitude() + { + return $this->lat; + } + + + + /** + * @return float + */ + public function getLongitude() + { + return $this->lon; + } + + + + /** + * @return string + */ + public function getSeparator() + { + return $this->separator; + } + + + + /** + * @param string $separator + * @return Coordinates + */ + public function setSeparator($separator) + { + $this->separator = $separator; + return $this; + } + + + + /** + * @return int + */ + public function getPrecision() + { + return $this->precision; + } + + + + /** + * @param int $precision + * @return Coordinates + */ + public function setPrecision($precision) + { + $this->precision = $precision; + return $this; + } + + + + /** + * @return string + */ + public function __toString() + { + return number_format($this->lat, $this->precision, '.', '') . + $this->separator . + number_format($this->lon, $this->precision, '.', ''); + } + +} diff --git a/src/Kdyby/Doctrine/Geo/Element.php b/src/Kdyby/Doctrine/Geo/Element.php new file mode 100644 index 00000000..2f1cdcad --- /dev/null +++ b/src/Kdyby/Doctrine/Geo/Element.php @@ -0,0 +1,265 @@ + + */ +class Element +{ + + use \Kdyby\StrictObjects\Scream; + + const POINT = 'POINT'; + const LINE_STRING = 'LINESTRING'; + const MULTI_LINE_STRING = 'MULTILINESTRING'; + const POLYGON = 'POLYGON'; + const MULTI_POLYGON = 'MULTIPOLYGON'; + const GEOMETRY_COLLECTION = 'GEOMETRYCOLLECTION'; + + /** + * @var string + */ + private $name = self::POINT; + + /** + * @var Coordinates[] + */ + private $coordinates = []; + + /** + * @var string + */ + private $separator = ','; + + /** + * @var string + */ + private $coordsSeparator = ' '; + + /** + * @var bool + */ + private $frozen = FALSE; + + /** + * @var string|NULL + */ + private $stringValue; + + + + /** + * @param string $name + */ + public function __construct($name = self::POINT) + { + $this->name = $name; + } + + + + /** + * @return string + */ + public function getName() + { + if ($this->stringValue) { + $this->init(); + } + + return $this->name; + } + + + + /** + * @param float $lon + * @param float $lat + * @throws \Kdyby\Doctrine\InvalidStateException + * @return Element + */ + public function addCoordinate($lon, $lat) + { + if ($this->stringValue) { + $this->init(); + } + if ($this->frozen) { + $class = get_class($this); + throw new Kdyby\Doctrine\InvalidStateException("Cannot modify a frozen object $class."); + } + + $this->coordinates[] = new Coordinates($lon, $lat); + return $this; + } + + + + /** + * @return Coordinates[] + */ + public function getCoordinates() + { + if ($this->stringValue) { + $this->init(); + } + + return $this->coordinates; + } + + + + /** + * @param string $lat + * @param string $lon + * @return array + */ + public function toArray($lat = 'lat', $lon = 'lon') + { + if ($this->stringValue) { + $this->init(); + } + + $list = []; + foreach ($this->coordinates as $coords) { + $list[] = [$lat => $coords->getLatitude(), $lon => $coords->getLongitude()]; + } + return $list; + } + + + + /** + * @return string + */ + public function getSeparator() + { + return $this->separator; + } + + + + /** + * @return string + */ + public function getCoordsSeparator() + { + return $this->coordsSeparator; + } + + + + /** + * @param string $text + * @param string $separator + * @param string $coordsSeparator + * @throws \Kdyby\Doctrine\InvalidArgumentException + * @return Element + */ + public static function fromString($text, $separator = ',', $coordsSeparator = ' ') + { + $el = new static(); + $el->stringValue = $text; + $el->separator = $separator; + $el->coordsSeparator = $coordsSeparator; + + return $el; + } + + + + /** + * @return Element + */ + public function freeze() + { + if ($this->stringValue) { + $this->init(); + } + $this->frozen = TRUE; + + return $this; + } + + + + /** + * Creates a modifiable clone of the object. + */ + public function __clone() + { + if (!$this->stringValue) { + $this->frozen = FALSE; + + $list = []; + foreach ($this->coordinates as $coords) { + $list[] = clone $coords; + } + $this->coordinates = $list; + } + } + + + + /** + * @return string + */ + public function __toString() + { + if ($this->stringValue) { + $this->init(); + } + + $coordinates = implode($this->separator, $this->coordinates); + if (in_array($this->name, [self::POINT, self::LINE_STRING])) { + return strtoupper($this->name) . '(' . $coordinates . ')'; + } else { + return strtoupper($this->name) . '((' . $coordinates . '))'; + } + } + + + + protected function init() + { + if (!$m = Strings::match($this->stringValue, '~^(?P\w+)\(\(?(?P[^)]+)\)?\)$~i')) { + throw new Kdyby\Doctrine\InvalidArgumentException("Given expression '" . $this->stringValue . "' is not geometry definition."); + } + $name = $m['name']; + $coordsList = $m['coordsList']; + + $separator = $this->separator; + $coordsSeparator = $this->coordsSeparator; + $coordsRegexp = '~^\s*-?[\d\.]+\s*' . preg_quote($coordsSeparator) . '\s*-?[\d\.]+\s*$~i'; + + $coordinates = []; + foreach (explode($separator, $coordsList) as $coords) { + if (!Strings::match($coords, $coordsRegexp)) { + throw new Kdyby\Doctrine\InvalidArgumentException("Given expression '" . $this->stringValue . "' is not geometry definition."); + } + list($lat, $lon) = explode($coordsSeparator, trim(Strings::replace($coords, '~\s+~', ' '))); + $coordinates[] = new Coordinates($lon, $lat); + } + + $this->name = $name; + $this->coordinates = $coordinates; + + $this->frozen = TRUE; + $this->stringValue = NULL; + } + +} diff --git a/src/Kdyby/Doctrine/Mapping/ClassMetadata.php b/src/Kdyby/Doctrine/Mapping/ClassMetadata.php index d6d6d7a6..3e5cb447 100644 --- a/src/Kdyby/Doctrine/Mapping/ClassMetadata.php +++ b/src/Kdyby/Doctrine/Mapping/ClassMetadata.php @@ -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; diff --git a/src/Kdyby/Doctrine/Mapping/RuntimeReflectionService.php b/src/Kdyby/Doctrine/Mapping/RuntimeReflectionService.php index fece83bc..f633abaa 100644 --- a/src/Kdyby/Doctrine/Mapping/RuntimeReflectionService.php +++ b/src/Kdyby/Doctrine/Mapping/RuntimeReflectionService.php @@ -12,26 +12,22 @@ use Doctrine; use Kdyby; -use Nette; -use Nette\Reflection; - +use ReflectionClass; +use ReflectionProperty; /** * @author Filip Procházka */ -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); } @@ -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; diff --git a/src/Kdyby/Doctrine/Registry.php b/src/Kdyby/Doctrine/Registry.php index bb3c0e8a..471af8d2 100644 --- a/src/Kdyby/Doctrine/Registry.php +++ b/src/Kdyby/Doctrine/Registry.php @@ -10,8 +10,8 @@ namespace Kdyby\Doctrine; -use Doctrine\Common\Persistence\AbstractManagerRegistry; use Doctrine\ORM\ORMException; +use Doctrine\Persistence\AbstractManagerRegistry; use Kdyby; use Nette; From 351419e6e1ee569c803b185ed5f2151414e39b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Hu=C4=8D=C3=ADk?= Date: Tue, 12 Apr 2022 14:14:26 +0200 Subject: [PATCH 2/3] Update packages and add PHP 8 support --- composer.json | 1 + src/Kdyby/Doctrine/ConnectionHelper.php | 42 ---- src/Kdyby/Doctrine/Geo/Coordinates.php | 134 ------------ src/Kdyby/Doctrine/Geo/Element.php | 265 ------------------------ 4 files changed, 1 insertion(+), 441 deletions(-) delete mode 100644 src/Kdyby/Doctrine/ConnectionHelper.php delete mode 100644 src/Kdyby/Doctrine/Geo/Coordinates.php delete mode 100644 src/Kdyby/Doctrine/Geo/Element.php diff --git a/composer.json b/composer.json index 8a71b5ca..c06184c1 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "require": { "php": "^7.1 || ^8.0", "doctrine/orm": "^2.10", + "doctrine/dbal": "~2.11.0", "kdyby/console": "dev-master", "kdyby/annotations": "^3.0", "kdyby/doctrine-cache": "^3.1.2", diff --git a/src/Kdyby/Doctrine/ConnectionHelper.php b/src/Kdyby/Doctrine/ConnectionHelper.php deleted file mode 100644 index 744b6206..00000000 --- a/src/Kdyby/Doctrine/ConnectionHelper.php +++ /dev/null @@ -1,42 +0,0 @@ -_connection = $connection; - } - - /** - * Retrieves the Doctrine database Connection. - * - * @return Connection - */ - public function getConnection() - { - return $this->_connection; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'connection'; - } -} diff --git a/src/Kdyby/Doctrine/Geo/Coordinates.php b/src/Kdyby/Doctrine/Geo/Coordinates.php deleted file mode 100644 index 52c33af4..00000000 --- a/src/Kdyby/Doctrine/Geo/Coordinates.php +++ /dev/null @@ -1,134 +0,0 @@ - - */ -class Coordinates -{ - - use \Kdyby\StrictObjects\Scream; - - /** - * @var float - */ - private $lon = 0.0; - - /** - * @var float - */ - private $lat = 0.0; - - /** - * @var string - */ - private $separator = ' '; - - /** - * @var int - */ - private $precision = 13; - - - - /** - * @param float|string $lon - * @param float|string $lat - */ - public function __construct($lon, $lat) - { - $this->lon = (float) $lon; - $this->lat = (float) $lat; - } - - - - /** - * @return float - */ - public function getLatitude() - { - return $this->lat; - } - - - - /** - * @return float - */ - public function getLongitude() - { - return $this->lon; - } - - - - /** - * @return string - */ - public function getSeparator() - { - return $this->separator; - } - - - - /** - * @param string $separator - * @return Coordinates - */ - public function setSeparator($separator) - { - $this->separator = $separator; - return $this; - } - - - - /** - * @return int - */ - public function getPrecision() - { - return $this->precision; - } - - - - /** - * @param int $precision - * @return Coordinates - */ - public function setPrecision($precision) - { - $this->precision = $precision; - return $this; - } - - - - /** - * @return string - */ - public function __toString() - { - return number_format($this->lat, $this->precision, '.', '') . - $this->separator . - number_format($this->lon, $this->precision, '.', ''); - } - -} diff --git a/src/Kdyby/Doctrine/Geo/Element.php b/src/Kdyby/Doctrine/Geo/Element.php deleted file mode 100644 index 2f1cdcad..00000000 --- a/src/Kdyby/Doctrine/Geo/Element.php +++ /dev/null @@ -1,265 +0,0 @@ - - */ -class Element -{ - - use \Kdyby\StrictObjects\Scream; - - const POINT = 'POINT'; - const LINE_STRING = 'LINESTRING'; - const MULTI_LINE_STRING = 'MULTILINESTRING'; - const POLYGON = 'POLYGON'; - const MULTI_POLYGON = 'MULTIPOLYGON'; - const GEOMETRY_COLLECTION = 'GEOMETRYCOLLECTION'; - - /** - * @var string - */ - private $name = self::POINT; - - /** - * @var Coordinates[] - */ - private $coordinates = []; - - /** - * @var string - */ - private $separator = ','; - - /** - * @var string - */ - private $coordsSeparator = ' '; - - /** - * @var bool - */ - private $frozen = FALSE; - - /** - * @var string|NULL - */ - private $stringValue; - - - - /** - * @param string $name - */ - public function __construct($name = self::POINT) - { - $this->name = $name; - } - - - - /** - * @return string - */ - public function getName() - { - if ($this->stringValue) { - $this->init(); - } - - return $this->name; - } - - - - /** - * @param float $lon - * @param float $lat - * @throws \Kdyby\Doctrine\InvalidStateException - * @return Element - */ - public function addCoordinate($lon, $lat) - { - if ($this->stringValue) { - $this->init(); - } - if ($this->frozen) { - $class = get_class($this); - throw new Kdyby\Doctrine\InvalidStateException("Cannot modify a frozen object $class."); - } - - $this->coordinates[] = new Coordinates($lon, $lat); - return $this; - } - - - - /** - * @return Coordinates[] - */ - public function getCoordinates() - { - if ($this->stringValue) { - $this->init(); - } - - return $this->coordinates; - } - - - - /** - * @param string $lat - * @param string $lon - * @return array - */ - public function toArray($lat = 'lat', $lon = 'lon') - { - if ($this->stringValue) { - $this->init(); - } - - $list = []; - foreach ($this->coordinates as $coords) { - $list[] = [$lat => $coords->getLatitude(), $lon => $coords->getLongitude()]; - } - return $list; - } - - - - /** - * @return string - */ - public function getSeparator() - { - return $this->separator; - } - - - - /** - * @return string - */ - public function getCoordsSeparator() - { - return $this->coordsSeparator; - } - - - - /** - * @param string $text - * @param string $separator - * @param string $coordsSeparator - * @throws \Kdyby\Doctrine\InvalidArgumentException - * @return Element - */ - public static function fromString($text, $separator = ',', $coordsSeparator = ' ') - { - $el = new static(); - $el->stringValue = $text; - $el->separator = $separator; - $el->coordsSeparator = $coordsSeparator; - - return $el; - } - - - - /** - * @return Element - */ - public function freeze() - { - if ($this->stringValue) { - $this->init(); - } - $this->frozen = TRUE; - - return $this; - } - - - - /** - * Creates a modifiable clone of the object. - */ - public function __clone() - { - if (!$this->stringValue) { - $this->frozen = FALSE; - - $list = []; - foreach ($this->coordinates as $coords) { - $list[] = clone $coords; - } - $this->coordinates = $list; - } - } - - - - /** - * @return string - */ - public function __toString() - { - if ($this->stringValue) { - $this->init(); - } - - $coordinates = implode($this->separator, $this->coordinates); - if (in_array($this->name, [self::POINT, self::LINE_STRING])) { - return strtoupper($this->name) . '(' . $coordinates . ')'; - } else { - return strtoupper($this->name) . '((' . $coordinates . '))'; - } - } - - - - protected function init() - { - if (!$m = Strings::match($this->stringValue, '~^(?P\w+)\(\(?(?P[^)]+)\)?\)$~i')) { - throw new Kdyby\Doctrine\InvalidArgumentException("Given expression '" . $this->stringValue . "' is not geometry definition."); - } - $name = $m['name']; - $coordsList = $m['coordsList']; - - $separator = $this->separator; - $coordsSeparator = $this->coordsSeparator; - $coordsRegexp = '~^\s*-?[\d\.]+\s*' . preg_quote($coordsSeparator) . '\s*-?[\d\.]+\s*$~i'; - - $coordinates = []; - foreach (explode($separator, $coordsList) as $coords) { - if (!Strings::match($coords, $coordsRegexp)) { - throw new Kdyby\Doctrine\InvalidArgumentException("Given expression '" . $this->stringValue . "' is not geometry definition."); - } - list($lat, $lon) = explode($coordsSeparator, trim(Strings::replace($coords, '~\s+~', ' '))); - $coordinates[] = new Coordinates($lon, $lat); - } - - $this->name = $name; - $this->coordinates = $coordinates; - - $this->frozen = TRUE; - $this->stringValue = NULL; - } - -} From a5c558e24910b71f19607958f8669a84b42ac590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Hu=C4=8D=C3=ADk?= Date: Thu, 30 Nov 2023 09:07:40 +0100 Subject: [PATCH 3/3] Update with all needed dependencies --- composer.json | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index c06184c1..5afc3f56 100644 --- a/composer.json +++ b/composer.json @@ -19,14 +19,15 @@ "require": { "php": "^7.1 || ^8.0", "doctrine/orm": "^2.10", - "doctrine/dbal": "~2.11.0", - "kdyby/console": "dev-master", + "doctrine/dbal": "~2.13.1", + "kdyby/console": "^4.0", "kdyby/annotations": "^3.0", - "kdyby/doctrine-cache": "^3.1.2", + "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", @@ -61,5 +62,11 @@ "branch-alias": { "dev-master": "4.0-dev" } - } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/mhucik/DoctrineCache" + } + ] }