From 63fed4cdf56f94dbad281bab4cf57ccf97be4aa8 Mon Sep 17 00:00:00 2001 From: Goran Tomic Date: Thu, 1 Jun 2023 13:07:09 +0200 Subject: [PATCH 1/6] feat(FIAP-197): fix deprecations WIP --- composer.json | 1 + lib/PHPPdf/Core/AbstractUnitConverter.php | 2 +- lib/PHPPdf/Core/AttributeBag.php | 7 +- lib/PHPPdf/Core/Boundary.php | 23 +- .../ComplexAttributeFactory.php | 8 +- lib/PHPPdf/Core/DrawingTaskHeap.php | 8 +- lib/PHPPdf/Core/FontRegistry.php | 2 + lib/PHPPdf/Core/Formatter/BaseFormatter.php | 9 +- .../Formatter/StandardDimensionFormatter.php | 27 +- lib/PHPPdf/Core/Node/BasicList.php | 2 +- lib/PHPPdf/Core/Node/Container.php | 4 +- lib/PHPPdf/Core/Node/DynamicPage.php | 4 +- lib/PHPPdf/Core/Node/Node.php | 18 +- lib/PHPPdf/Core/Node/NodeFactory.php | 2 +- lib/PHPPdf/Core/Node/Page.php | 6 +- lib/PHPPdf/Core/Node/Paragraph.php | 2 +- lib/PHPPdf/Core/Node/Runtime/PageText.php | 6 +- lib/PHPPdf/Core/Node/Table/Row.php | 2 +- lib/PHPPdf/Core/Node/Text.php | 4 +- lib/PHPPdf/Core/Parser/BagContainer.php | 286 +++++++++--------- .../Core/Parser/StylesheetConstraint.php | 2 + lib/PHPPdf/Core/Point.php | 8 +- test.php | 23 ++ 23 files changed, 253 insertions(+), 203 deletions(-) create mode 100644 test.php diff --git a/composer.json b/composer.json index 9c02bfe3..fc66cb33 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ } ], "require": { + "ext-mbstring": "*", "zendframework/zendpdf": "~2.0.0" }, "require-dev": { diff --git a/lib/PHPPdf/Core/AbstractUnitConverter.php b/lib/PHPPdf/Core/AbstractUnitConverter.php index 857a0146..6598ebb8 100644 --- a/lib/PHPPdf/Core/AbstractUnitConverter.php +++ b/lib/PHPPdf/Core/AbstractUnitConverter.php @@ -50,7 +50,7 @@ abstract protected function convertPtUnit($value); public function convertPercentageValue($percent, $value) { - if(strpos($percent, '%') !== false) + if(str_contains($percent, '%')) { $percent = (double) $percent; $percent = $value*$percent / 100; diff --git a/lib/PHPPdf/Core/AttributeBag.php b/lib/PHPPdf/Core/AttributeBag.php index b619c415..6402fb2a 100644 --- a/lib/PHPPdf/Core/AttributeBag.php +++ b/lib/PHPPdf/Core/AttributeBag.php @@ -8,12 +8,14 @@ namespace PHPPdf\Core; +use ReturnTypeWillChange; + /** * Bag of attributes * * @author Piotr Śliwa */ -class AttributeBag implements \Countable, \Serializable +class AttributeBag implements \Countable { private $elements = array(); @@ -39,6 +41,7 @@ public function add($name, $value) return $this; } + #[ReturnTypeWillChange] public function count() { return count($this->elements); @@ -92,4 +95,4 @@ public function unserialize($serialized) { $this->elements = \unserialize($serialized); } -} \ No newline at end of file +} diff --git a/lib/PHPPdf/Core/Boundary.php b/lib/PHPPdf/Core/Boundary.php index 19ec03bb..d5ff1bda 100644 --- a/lib/PHPPdf/Core/Boundary.php +++ b/lib/PHPPdf/Core/Boundary.php @@ -8,17 +8,18 @@ namespace PHPPdf\Core; -use PHPPdf\Exception\OutOfBoundsException; -use PHPPdf\Exception\BadMethodCallException; -use PHPPdf\Exception\InvalidArgumentException; +use PHPPdf\Exception\OutOfBoundsException; +use PHPPdf\Exception\BadMethodCallException; +use PHPPdf\Exception\InvalidArgumentException; use PHPPdf\Exception\LogicException; - +use ReturnTypeWillChange; + /** * Set of ordered points whom determine boundary and shape of node element. * * @author Piotr Śliwa */ -class Boundary implements \Countable, \Iterator, \ArrayAccess, \Serializable +class Boundary implements \Countable, \Iterator, \ArrayAccess { private $points = array(); private $numberOfPoints = 0; @@ -169,11 +170,13 @@ private function getPointBetween(Point $point1, Point $point2) /** * @return integer Number of points in boundary */ + #[ReturnTypeWillChange] public function count() { return $this->numberOfPoints; } + #[ReturnTypeWillChange] public function current() { $points = $this->getPoints(); @@ -183,6 +186,8 @@ public function current() /** * @return array Array of Point objects */ + + #[ReturnTypeWillChange] public function getPoints() { return $this->points; @@ -193,21 +198,25 @@ public function getPoint($i) return $this->offsetGet($i); } + #[ReturnTypeWillChange] public function key() { return $this->current; } + #[ReturnTypeWillChange] public function next() { $this->current++; } + #[ReturnTypeWillChange] public function rewind() { $this->current = 0; } + #[ReturnTypeWillChange] public function valid() { $points = $this->getPoints(); @@ -314,11 +323,13 @@ public function isClosed() return $this->closed; } + #[ReturnTypeWillChange] public function offsetExists($offset) { return (is_int($offset) && $offset < $this->numberOfPoints); } + #[ReturnTypeWillChange] public function offsetGet($offset) { if(!$this->offsetExists($offset)) @@ -329,11 +340,13 @@ public function offsetGet($offset) return $this->points[$offset]; } + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { throw new BadMethodCallException('You can not set point directly.'); } + #[ReturnTypeWillChange] public function offsetUnset($offset) { throw new BadMethodCallException('You can not unset point directly.'); diff --git a/lib/PHPPdf/Core/ComplexAttribute/ComplexAttributeFactory.php b/lib/PHPPdf/Core/ComplexAttribute/ComplexAttributeFactory.php index 44e239d3..e4573c54 100644 --- a/lib/PHPPdf/Core/ComplexAttribute/ComplexAttributeFactory.php +++ b/lib/PHPPdf/Core/ComplexAttribute/ComplexAttributeFactory.php @@ -8,7 +8,7 @@ namespace PHPPdf\Core\ComplexAttribute; -use PHPPdf\Exception\InvalidArgumentException; +use PHPPdf\Exception\InvalidArgumentException; use PHPPdf\Core\ComplexAttribute\Exception\DefinitionNotFoundException; @@ -20,7 +20,7 @@ * * @author Piotr Śliwa */ -class ComplexAttributeFactory implements \Serializable +class ComplexAttributeFactory { private $definitions = array(); private $constructors = array(); @@ -251,11 +251,11 @@ public function serialize() public function unserialize($serialized) { - $definitions = \unserialize($serialized); + $definitions = unserialize($serialized); foreach($definitions as $name => $className) { $this->addDefinition($name, $className); } } -} \ No newline at end of file +} diff --git a/lib/PHPPdf/Core/DrawingTaskHeap.php b/lib/PHPPdf/Core/DrawingTaskHeap.php index c1cdbea8..4209b91c 100644 --- a/lib/PHPPdf/Core/DrawingTaskHeap.php +++ b/lib/PHPPdf/Core/DrawingTaskHeap.php @@ -19,14 +19,16 @@ class DrawingTaskHeap extends \SplHeap { private $elements = 0; - public function insert($value) + public function insert($value): bool { $value->setOrder($this->elements++); parent::insert($value); + + return true; } - public function compare($value1, $value2) + public function compare($value1, $value2): int { return $value1->compareTo($value2); } -} \ No newline at end of file +} diff --git a/lib/PHPPdf/Core/FontRegistry.php b/lib/PHPPdf/Core/FontRegistry.php index a73b3186..3fd06ae6 100644 --- a/lib/PHPPdf/Core/FontRegistry.php +++ b/lib/PHPPdf/Core/FontRegistry.php @@ -9,6 +9,7 @@ namespace PHPPdf\Core; use PHPPdf\Exception\InvalidArgumentException; +use ReturnTypeWillChange; /** * @author Piotr Śliwa @@ -51,6 +52,7 @@ public function has($name) return isset($this->fonts[$name]); } + #[ReturnTypeWillChange] public function count() { return count($this->fonts); diff --git a/lib/PHPPdf/Core/Formatter/BaseFormatter.php b/lib/PHPPdf/Core/Formatter/BaseFormatter.php index e30884b6..998e3309 100644 --- a/lib/PHPPdf/Core/Formatter/BaseFormatter.php +++ b/lib/PHPPdf/Core/Formatter/BaseFormatter.php @@ -8,17 +8,12 @@ namespace PHPPdf\Core\Formatter; -use PHPPdf\Core\Formatter\Formatter, - PHPPdf\Core\Node\Node, - PHPPdf\Core\Document, - PHPPdf\Core\Formatter\Chain; - /** * Base formatter class * * @author Piotr Śliwa */ -abstract class BaseFormatter implements Formatter, \Serializable +abstract class BaseFormatter implements Formatter { public function serialize() { @@ -28,4 +23,4 @@ public function serialize() public function unserialize($serialized) { } -} \ No newline at end of file +} diff --git a/lib/PHPPdf/Core/Formatter/StandardDimensionFormatter.php b/lib/PHPPdf/Core/Formatter/StandardDimensionFormatter.php index 787610ce..a293960b 100644 --- a/lib/PHPPdf/Core/Formatter/StandardDimensionFormatter.php +++ b/lib/PHPPdf/Core/Formatter/StandardDimensionFormatter.php @@ -8,9 +8,9 @@ namespace PHPPdf\Core\Formatter; -use PHPPdf\Core\Formatter\BaseFormatter, - PHPPdf\Core\Node\Node, - PHPPdf\Core\Document; +use PHPPdf\Core\Formatter\BaseFormatter; +use PHPPdf\Core\Node\Node; +use PHPPdf\Core\Document; /** * Calculates real dimension of node @@ -25,8 +25,7 @@ public function format(Node $node, Document $document) $maxWidth = $node->getRecurseAttribute('max-width') ?: \PHP_INT_MAX; $maxHeight = $node->getRecurseAttribute('max-height') ?: \PHP_INT_MAX; - if($node->getWidth() === null && !$node->isInline() && $node->getFloat() === Node::FLOAT_NONE) - { + if ($node->getWidth() === null && !$node->isInline() && $node->getFloat() === Node::FLOAT_NONE) { $parentWidth = $parent->getWidthWithoutPaddings(); $marginLeft = $node->getMarginLeft(); @@ -34,14 +33,11 @@ public function format(Node $node, Document $document) $node->setWidth(min($parentWidth - ($marginLeft + $marginRight), $maxWidth)); $node->setRelativeWidth('100%'); - } - elseif($node->isInline()) - { + } elseif ($node->isInline()) { $node->setWidth(0); } - if($node->getHeight() === null) - { + if ($node->getHeight() === null) { $node->setHeight(0); } @@ -49,15 +45,14 @@ public function format(Node $node, Document $document) $paddingRight = $node->getPaddingRight(); $paddingTop = $node->getPaddingTop(); $paddingBottom = $node->getPaddingBottom(); - + $prefferedWidth = $node->getRealWidth() + $paddingLeft + $paddingRight; - + $parent = $node->getParent(); - + $parentWidth = $parent ? $parent->getWidthWithoutPaddings() : null; - - if($parent && $parentWidth < $prefferedWidth) - { + + if ($parent && $parentWidth < $prefferedWidth) { $prefferedWidth = $parentWidth; } diff --git a/lib/PHPPdf/Core/Node/BasicList.php b/lib/PHPPdf/Core/Node/BasicList.php index ddb83d57..10400816 100644 --- a/lib/PHPPdf/Core/Node/BasicList.php +++ b/lib/PHPPdf/Core/Node/BasicList.php @@ -200,7 +200,7 @@ protected function doBreakAt($height) return $node; } - public function copy() + public function copy(): Node|Container { $node = parent::copy(); $node->setOmitEnumerationOfFirstElement(false); diff --git a/lib/PHPPdf/Core/Node/Container.php b/lib/PHPPdf/Core/Node/Container.php index d8f4dab9..0e0a21bf 100644 --- a/lib/PHPPdf/Core/Node/Container.php +++ b/lib/PHPPdf/Core/Node/Container.php @@ -60,7 +60,7 @@ public function removeAll() $this->children = array(); } - public function reset() + public function reset(): void { parent::reset(); @@ -83,7 +83,7 @@ protected function doDraw(Document $document, DrawingTaskHeap $tasks) } } - public function copy() + public function copy(): Node|Container { $copy = parent::copy(); diff --git a/lib/PHPPdf/Core/Node/DynamicPage.php b/lib/PHPPdf/Core/Node/DynamicPage.php index bfb4f216..2dd6061b 100644 --- a/lib/PHPPdf/Core/Node/DynamicPage.php +++ b/lib/PHPPdf/Core/Node/DynamicPage.php @@ -97,7 +97,7 @@ public function getNumberOfPages() return $this->numberOfPages; } - public function copy() + public function copy(): Node|Container { $copy = parent::copy(); $copy->prototype = $this->prototype->copy(); @@ -108,7 +108,7 @@ public function copy() return $copy; } - public function reset() + public function reset(): void { $this->pages = array(); $this->currentPage = null; diff --git a/lib/PHPPdf/Core/Node/Node.php b/lib/PHPPdf/Core/Node/Node.php index 243fab6e..c96df16d 100644 --- a/lib/PHPPdf/Core/Node/Node.php +++ b/lib/PHPPdf/Core/Node/Node.php @@ -24,13 +24,14 @@ use PHPPdf\Core\Node\Behaviour\Behaviour; use PHPPdf\Core\Exception\InvalidAttributeException; use PHPPdf\Core\Point; +use ReturnTypeWillChange; /** * Base node class * * @author Piotr Śliwa */ -abstract class Node implements Drawable, NodeAware, \ArrayAccess, \Serializable +abstract class Node implements Drawable, NodeAware, \ArrayAccess { const MARGIN_AUTO = 'auto'; const FLOAT_NONE = 'none'; @@ -353,6 +354,7 @@ public function getMiddlePoint() return $this->getBoundary()->getMiddlePoint(); } + #[ReturnTypeWillChange] public function setParent(Container $node) { $oldParent = $this->parent; @@ -369,6 +371,7 @@ public function setParent(Container $node) /** * @return Node */ + #[ReturnTypeWillChange] public function getParent() { return $this->parent; @@ -380,6 +383,7 @@ public function getParent() * @param string $type Full class name with namespace * @return PHPPdf\Core\Node\Node Nearest ancestor in $type */ + #[ReturnTypeWillChange] public function getAncestorByType($type) { $current = $this; @@ -408,7 +412,7 @@ public function getSiblings() return $parent->getChildren(); } - public function initialize() + public function initialize(): void { $this->setComplexAttributeBag(new AttributeBag()); } @@ -434,7 +438,7 @@ public function getBehaviours() /** * Reset state of object */ - public function reset() + public function reset(): void { } @@ -442,6 +446,8 @@ public function reset() * @return Page Page of current objects * @throws LogicException If object has not been attached to any page */ + + #[ReturnTypeWillChange] public function getPage() { $page = $this->getAncestorByType('\PHPPdf\Core\Node\Page'); @@ -1247,21 +1253,25 @@ protected function beforeFormat(Document $document) { } + #[ReturnTypeWillChange] public function offsetExists($offset) { return $this->hasAttribute($offset); } + #[ReturnTypeWillChange] public function offsetGet($offset) { return $this->getAttribute($offset); } + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->setAttribute($offset, $value); } + #[ReturnTypeWillChange] public function offsetUnset($offset) { $this->setAttribute($offset, null); @@ -1317,7 +1327,7 @@ public function removeParent() /** * @return Node Copy of this node */ - public function copy() + public function copy(): Node|static { $copy = clone $this; $copy->reset(); diff --git a/lib/PHPPdf/Core/Node/NodeFactory.php b/lib/PHPPdf/Core/Node/NodeFactory.php index 6ae35c70..b8a38105 100644 --- a/lib/PHPPdf/Core/Node/NodeFactory.php +++ b/lib/PHPPdf/Core/Node/NodeFactory.php @@ -16,7 +16,7 @@ * * @author Piotr Śliwa */ -class NodeFactory implements \Serializable +class NodeFactory { private $prototypes = array(); private $invocationsMethodsOnCreate = array(); diff --git a/lib/PHPPdf/Core/Node/Page.php b/lib/PHPPdf/Core/Node/Page.php index da028795..b0f5799b 100644 --- a/lib/PHPPdf/Core/Node/Page.php +++ b/lib/PHPPdf/Core/Node/Page.php @@ -18,6 +18,7 @@ use PHPPdf\Core\Engine\GraphicsContext; use PHPPdf\Core\Point; use PHPPdf\Core\Formatter\Formatter; +use ReturnTypeWillChange; /** * Single pdf page @@ -117,7 +118,7 @@ protected static function setDefaultAttributes() static::addAttribute('document-template'); } - public function initialize() + public function initialize(): void { parent::initialize(); @@ -303,6 +304,7 @@ private function setGraphicsContextDefaultStyle(Document $document) $this->graphicsContext->setLineColor($blackColor); } + #[ReturnTypeWillChange] public function getPage() { return $this; @@ -318,7 +320,7 @@ public function breakAt($height) throw new LogicException('Page can\'t be broken.'); } - public function copy() + public function copy(): Node|Container { $boundary = clone $this->getBoundary(); $copy = parent::copy(); diff --git a/lib/PHPPdf/Core/Node/Paragraph.php b/lib/PHPPdf/Core/Node/Paragraph.php index 5c5540f7..fd7a0e60 100644 --- a/lib/PHPPdf/Core/Node/Paragraph.php +++ b/lib/PHPPdf/Core/Node/Paragraph.php @@ -22,7 +22,7 @@ class Paragraph extends Container { private $lines = array(); - public function initialize() + public function initialize(): void { parent::initialize(); $this->setAttribute('text-align', null); diff --git a/lib/PHPPdf/Core/Node/Runtime/PageText.php b/lib/PHPPdf/Core/Node/Runtime/PageText.php index f0b3a571..f4e61d4a 100644 --- a/lib/PHPPdf/Core/Node/Runtime/PageText.php +++ b/lib/PHPPdf/Core/Node/Runtime/PageText.php @@ -8,13 +8,14 @@ namespace PHPPdf\Core\Node\Runtime; -use PHPPdf\Core\DrawingTaskHeap; +use PHPPdf\Core\DrawingTaskHeap; use PHPPdf\Core\Node\Text, PHPPdf\Core\Node\Runtime, PHPPdf\Core\Node\Page, PHPPdf\Core\UnitConverter, PHPPdf\Core\Document; +use ReturnTypeWillChange; /** * @author Piotr Śliwa @@ -39,7 +40,7 @@ protected static function setDefaultAttributes() static::addAttribute('offset', 0); } - public function initialize() + public function initialize(): void { parent::initialize(); @@ -142,6 +143,7 @@ public function mergeComplexAttributes($name, array $parameters = array()) { } + #[ReturnTypeWillChange] public function getPage() { if($this->page !== null) diff --git a/lib/PHPPdf/Core/Node/Table/Row.php b/lib/PHPPdf/Core/Node/Table/Row.php index 43ca5fe6..3de5b5de 100644 --- a/lib/PHPPdf/Core/Node/Table/Row.php +++ b/lib/PHPPdf/Core/Node/Table/Row.php @@ -108,7 +108,7 @@ public function getWidth() return $this->getParent()->getWidth(); } - public function reset() + public function reset(): void { parent::reset(); $this->numberOfColumns = 0; diff --git a/lib/PHPPdf/Core/Node/Text.php b/lib/PHPPdf/Core/Node/Text.php index eb4c38bf..d27f6e73 100644 --- a/lib/PHPPdf/Core/Node/Text.php +++ b/lib/PHPPdf/Core/Node/Text.php @@ -43,7 +43,7 @@ public function __construct($text = '', array $attributes = array(), UnitConvert parent::__construct($attributes, $converter); } - public function initialize() + public function initialize(): void { parent::initialize(); @@ -224,7 +224,7 @@ protected function getDataForSerialize() return $data; } - public function copy() + public function copy(): \PHPPdf\Core\Node\Node|static { $copy = parent::copy(); diff --git a/lib/PHPPdf/Core/Parser/BagContainer.php b/lib/PHPPdf/Core/Parser/BagContainer.php index 95cfc8e4..9b0d84fe 100644 --- a/lib/PHPPdf/Core/Parser/BagContainer.php +++ b/lib/PHPPdf/Core/Parser/BagContainer.php @@ -1,144 +1,144 @@ - - * - * License information is in LICENSE file - */ - -namespace PHPPdf\Core\Parser; - -use PHPPdf\Core\Node\Node; -use PHPPdf\Core\AttributeBag; - -/** - * Class to encapsulate two bags: AttributeBag and ComplexAttributeBag - * - * @author Piotr Śliwa - */ -class BagContainer implements \Serializable -{ - protected $attributeBag; - protected $weight; - protected $order = 0; - - public function __construct(array $attributes = array(), $weight = 0) - { - $attributeBag = new AttributeBag(); - - foreach($attributes as $name => $value) - { - $attributeBag->add($name, $value); - } - - $this->attributeBag = $attributeBag; - $this->weight = (double) $weight; - } - - /** - * @return AttributeBag - */ - protected function getAttributeBag() - { - return $this->attributeBag; - } - - public function getAll() - { - return $this->getAttributeBag()->getAll(); - } - - public function add($name, $value) - { - $this->getAttributeBag()->add($name, $value); - } - - public function setOrder($order) - { - $this->order = (int) $order; - } - - public function getOrder() - { - return $this->order; - } - - public function getWeight() - { - return $this->weight; - } - - public function addWeight($weight) - { - $this->weight += $weight; - } - - public function serialize() - { - return serialize($this->getDataToSerialize()); - } - - protected function getDataToSerialize() - { - return array( - 'attributes' => $this->getAttributeBag()->getAll(), - 'weight' => $this->weight, - ); - } - - public function unserialize($serialized) - { - $data = unserialize($serialized); - - $this->restoreDataAfterUnserialize($data); - } - - protected function restoreDataAfterUnserialize($data) - { - $this->attributeBag = new AttributeBag($data['attributes']); - $this->weight = (float) $data['weight']; - } - - public function apply(Node $node) - { - $attributes = $this->getAll(); - - foreach($attributes as $name => $value) - { - if(is_array($value)) - { - $node->mergeComplexAttributes($name, $value); - } - else - { - $node->setAttribute($name, $value); - } - } - } - - /** - * Marge couple of BagContainers into one object. - * - * Result of merging always is BagContainer. - * - * @param array $containers - * @return BagContainer Result of merging - */ - public static function merge(array $containers) - { - $attributeBags = array(); - - $weight = 0; - foreach($containers as $container) - { - $weight = max($weight, $container->getWeight()); - $attributeBags[] = $container->getAttributeBag(); - } - - $container = new static(); - $container->attributeBag = AttributeBag::merge($attributeBags); - $container->weight = $weight; - - return $container; - } + + * + * License information is in LICENSE file + */ + +namespace PHPPdf\Core\Parser; + +use PHPPdf\Core\Node\Node; +use PHPPdf\Core\AttributeBag; + +/** + * Class to encapsulate two bags: AttributeBag and ComplexAttributeBag + * + * @author Piotr Śliwa + */ +class BagContainer +{ + protected $attributeBag; + protected $weight; + protected $order = 0; + + public function __construct(array $attributes = array(), $weight = 0) + { + $attributeBag = new AttributeBag(); + + foreach($attributes as $name => $value) + { + $attributeBag->add($name, $value); + } + + $this->attributeBag = $attributeBag; + $this->weight = (double) $weight; + } + + /** + * @return AttributeBag + */ + protected function getAttributeBag() + { + return $this->attributeBag; + } + + public function getAll() + { + return $this->getAttributeBag()->getAll(); + } + + public function add($name, $value) + { + $this->getAttributeBag()->add($name, $value); + } + + public function setOrder($order) + { + $this->order = (int) $order; + } + + public function getOrder() + { + return $this->order; + } + + public function getWeight() + { + return $this->weight; + } + + public function addWeight($weight) + { + $this->weight += $weight; + } + + public function serialize() + { + return serialize($this->getDataToSerialize()); + } + + protected function getDataToSerialize() + { + return array( + 'attributes' => $this->getAttributeBag()->getAll(), + 'weight' => $this->weight, + ); + } + + public function unserialize($serialized) + { + $data = unserialize($serialized); + + $this->restoreDataAfterUnserialize($data); + } + + protected function restoreDataAfterUnserialize($data) + { + $this->attributeBag = new AttributeBag($data['attributes']); + $this->weight = (float) $data['weight']; + } + + public function apply(Node $node) + { + $attributes = $this->getAll(); + + foreach($attributes as $name => $value) + { + if(is_array($value)) + { + $node->mergeComplexAttributes($name, $value); + } + else + { + $node->setAttribute($name, $value); + } + } + } + + /** + * Marge couple of BagContainers into one object. + * + * Result of merging always is BagContainer. + * + * @param array $containers + * @return BagContainer Result of merging + */ + public static function merge(array $containers) + { + $attributeBags = array(); + + $weight = 0; + foreach($containers as $container) + { + $weight = max($weight, $container->getWeight()); + $attributeBags[] = $container->getAttributeBag(); + } + + $container = new static(); + $container->attributeBag = AttributeBag::merge($attributeBags); + $container->weight = $weight; + + return $container; + } } \ No newline at end of file diff --git a/lib/PHPPdf/Core/Parser/StylesheetConstraint.php b/lib/PHPPdf/Core/Parser/StylesheetConstraint.php index 0bfbc19f..438920e1 100644 --- a/lib/PHPPdf/Core/Parser/StylesheetConstraint.php +++ b/lib/PHPPdf/Core/Parser/StylesheetConstraint.php @@ -9,6 +9,7 @@ namespace PHPPdf\Core\Parser; use PHPPdf\Core\AttributeBag; +use ReturnTypeWillChange; /** * Constraints encapsulate Attribute and ComplexAttribute Bag in tree structure. @@ -99,6 +100,7 @@ public function getConstraints() return $this->constraints; } + #[ReturnTypeWillChange] public function count() { return count($this->getConstraints()); diff --git a/lib/PHPPdf/Core/Point.php b/lib/PHPPdf/Core/Point.php index 618d61aa..2cbedcbb 100644 --- a/lib/PHPPdf/Core/Point.php +++ b/lib/PHPPdf/Core/Point.php @@ -144,12 +144,12 @@ public function translate($x, $y) return self::getInstance($this->x + $x, $this->y - $y); } - public function offsetExists($offset) + public function offsetExists($offset): bool { return ($offset == 1 || $offset == 0); } - public function offsetGet($offset) + public function offsetGet($offset): mixed { switch($offset) { @@ -162,12 +162,12 @@ public function offsetGet($offset) } } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { throw new BadMethodCallException(sprintf('%s class is inmutable.', __CLASS__)); } - public function offsetUnset($offset) + public function offsetUnset($offset): void { throw new BadMethodCallException(sprintf('%s class is inmutable.', __CLASS__)); } diff --git a/test.php b/test.php new file mode 100644 index 00000000..e9dbddb7 --- /dev/null +++ b/test.php @@ -0,0 +1,23 @@ +getData()); From 7335c000a0cf2767da0633d4500a4fbf1d86a6bf Mon Sep 17 00:00:00 2001 From: Goran Tomic Date: Thu, 1 Jun 2023 15:03:49 +0200 Subject: [PATCH 2/6] feat(FIAP-197): fix deprecations WIP#2 --- lib/PHPPdf/Core/Formatter/TableColumnFormatter.php | 2 +- lib/PHPPdf/Core/Formatter/TableFormatter.php | 2 +- lib/PHPPdf/Core/Node/Paragraph.php | 2 +- lib/PHPPdf/Core/Node/Table.php | 4 ++-- lib/PHPPdf/Core/Node/Table/Row.php | 12 ++++++------ .../Core/Node/Table/{Cell.php => TableCell.php} | 2 +- lib/PHPPdf/Resources/config/nodes.xml | 2 +- lib/PHPPdf/Resources/config/services/nodes.xml | 2 +- tests/PHPPdf/ObjectMother/TableObjectMother.php | 2 +- .../Core/Formatter/RowDimensionFormatterTest.php | 2 +- .../Test/Core/Formatter/TableFormatterTest.php | 2 +- tests/PHPPdf/Test/Core/Node/CellTest.php | 6 +++--- tests/PHPPdf/Test/Core/Node/RowTest.php | 10 +++++----- tests/PHPPdf/Test/Core/Node/TableTest.php | 12 ++++++------ 14 files changed, 31 insertions(+), 31 deletions(-) rename lib/PHPPdf/Core/Node/Table/{Cell.php => TableCell.php} (98%) diff --git a/lib/PHPPdf/Core/Formatter/TableColumnFormatter.php b/lib/PHPPdf/Core/Formatter/TableColumnFormatter.php index ac321220..d2a60dee 100644 --- a/lib/PHPPdf/Core/Formatter/TableColumnFormatter.php +++ b/lib/PHPPdf/Core/Formatter/TableColumnFormatter.php @@ -37,7 +37,7 @@ public function format(Node $node, Document $document) foreach($node->getChildren() as $row) { - foreach($row->getChildren() as /* @var $cell PHPPdf\Core\Node\Table\Cell */ $cell) + foreach($row->getChildren() as /* @var $cell PHPPdf\Core\Node\Table\TableCell */ $cell) { $column = $cell->getNumberOfColumn(); $colspan = $cell->getColspan(); diff --git a/lib/PHPPdf/Core/Formatter/TableFormatter.php b/lib/PHPPdf/Core/Formatter/TableFormatter.php index eddb71a3..e31946ee 100644 --- a/lib/PHPPdf/Core/Formatter/TableFormatter.php +++ b/lib/PHPPdf/Core/Formatter/TableFormatter.php @@ -36,7 +36,7 @@ public function format(Node $node, Document $document) { $diffBetweenTableAndColumnsWidths = $tableWidth - $totalWidth - $totalMargins; $translate = 0; - foreach($row->getChildren() as /* @var $cell PHPPdf\Core\Node\Table\Cell */ $cell) + foreach($row->getChildren() as /* @var $cell PHPPdf\Core\Node\Table\TableCell */ $cell) { $column = $cell->getNumberOfColumn(); $colspan = $cell->getColspan(); diff --git a/lib/PHPPdf/Core/Node/Paragraph.php b/lib/PHPPdf/Core/Node/Paragraph.php index fd7a0e60..cf4eef4b 100644 --- a/lib/PHPPdf/Core/Node/Paragraph.php +++ b/lib/PHPPdf/Core/Node/Paragraph.php @@ -227,7 +227,7 @@ protected function doBreakAt($height) return $paragraphProduct; } - public function copy() + public function copy(): Node|Container { $copy = parent::copy(); $copy->lines = array(); diff --git a/lib/PHPPdf/Core/Node/Table.php b/lib/PHPPdf/Core/Node/Table.php index 16bd4ef9..d18f8d98 100644 --- a/lib/PHPPdf/Core/Node/Table.php +++ b/lib/PHPPdf/Core/Node/Table.php @@ -9,7 +9,7 @@ namespace PHPPdf\Core\Node; use PHPPdf\Exception\InvalidArgumentException; -use PHPPdf\Core\Node\Table\Cell; +use PHPPdf\Core\Node\Table\TableCell; use PHPPdf\Core\Node\Node; use PHPPdf\Core\Node\Table\Row; @@ -59,7 +59,7 @@ public function add(Node $node) return parent::add($node); } - private function updateColumnDataIfNecessary(Cell $cell) + private function updateColumnDataIfNecessary(TableCell $cell) { $this->setColumnWidthIfNecessary($cell); foreach(array('margin-left', 'margin-right') as $attribute) diff --git a/lib/PHPPdf/Core/Node/Table/Row.php b/lib/PHPPdf/Core/Node/Table/Row.php index 3de5b5de..a7b131b5 100644 --- a/lib/PHPPdf/Core/Node/Table/Row.php +++ b/lib/PHPPdf/Core/Node/Table/Row.php @@ -10,7 +10,7 @@ use PHPPdf\Exception\InvalidArgumentException; use PHPPdf\Core\Document; -use PHPPdf\Core\Node\Table\Cell; +use PHPPdf\Core\Node\Table\TableCell; use PHPPdf\Core\Node\Container; use PHPPdf\Core\Node\Listener; use PHPPdf\Core\Node\Node; @@ -29,7 +29,7 @@ class Row extends Container implements Listener 'margin-bottom' => 0, ); - public function initialize() + public function initialize(): void { parent::initialize(); @@ -38,9 +38,9 @@ public function initialize() public function add(Node $node) { - if(!$node instanceof Cell) + if(!$node instanceof TableCell) { - throw new InvalidArgumentException(sprintf('Invalid child node type, expected PHPPdf\Core\Node\Table\Cell, %s given.', get_class($node))); + throw new InvalidArgumentException(sprintf('Invalid child node type, expected PHPPdf\Core\Node\Table\TableCell, %s given.', get_class($node))); } $node->setNumberOfColumn($this->numberOfColumns); @@ -61,7 +61,7 @@ public function add(Node $node) return parent::add($node); } - private function setMaxHeightOfCellsIfHeightOfPassedCellIsGreater(Cell $node) + private function setMaxHeightOfCellsIfHeightOfPassedCellIsGreater(TableCell $node) { $height = $node->getHeight(); @@ -71,7 +71,7 @@ private function setMaxHeightOfCellsIfHeightOfPassedCellIsGreater(Cell $node) } } - private function setCellMarginIfNecessary(Cell $cell, $marginType) + private function setCellMarginIfNecessary(TableCell $cell, $marginType) { $margin = $cell->getAttribute($marginType); diff --git a/lib/PHPPdf/Core/Node/Table/Cell.php b/lib/PHPPdf/Core/Node/Table/TableCell.php similarity index 98% rename from lib/PHPPdf/Core/Node/Table/Cell.php rename to lib/PHPPdf/Core/Node/Table/TableCell.php index 5bedb0e4..0f2c040c 100644 --- a/lib/PHPPdf/Core/Node/Table/Cell.php +++ b/lib/PHPPdf/Core/Node/Table/TableCell.php @@ -17,7 +17,7 @@ * * @author Piotr Śliwa */ -class Cell extends Container +class TableCell extends Container { private $listeners = array(); private $numberOfColumn; diff --git a/lib/PHPPdf/Resources/config/nodes.xml b/lib/PHPPdf/Resources/config/nodes.xml index 7d9a1c04..49b69a4d 100644 --- a/lib/PHPPdf/Resources/config/nodes.xml +++ b/lib/PHPPdf/Resources/config/nodes.xml @@ -309,7 +309,7 @@ - + diff --git a/lib/PHPPdf/Resources/config/services/nodes.xml b/lib/PHPPdf/Resources/config/services/nodes.xml index f98c6cbc..93d126a7 100644 --- a/lib/PHPPdf/Resources/config/services/nodes.xml +++ b/lib/PHPPdf/Resources/config/services/nodes.xml @@ -451,7 +451,7 @@ - + diff --git a/tests/PHPPdf/ObjectMother/TableObjectMother.php b/tests/PHPPdf/ObjectMother/TableObjectMother.php index bbed3b1a..84a08187 100644 --- a/tests/PHPPdf/ObjectMother/TableObjectMother.php +++ b/tests/PHPPdf/ObjectMother/TableObjectMother.php @@ -29,7 +29,7 @@ public function getCellMockWithTranslateAndResizeExpectations($width, $newWidth, public function getCellMockWithResizeExpectations($width, $newWidth, $invokeResizeMethod = true) { - $cell = $this->test->getMock('PHPPdf\Core\Node\Table\Cell', array('getWidth', 'getBoundary', 'setWidth', 'translate', 'getNumberOfColumn', 'resize')); + $cell = $this->test->getMock('PHPPdf\Core\Node\Table\TableCell', array('getWidth', 'getBoundary', 'setWidth', 'translate', 'getNumberOfColumn', 'resize')); $cell->expects($this->test->any()) ->method('getWidth') diff --git a/tests/PHPPdf/Test/Core/Formatter/RowDimensionFormatterTest.php b/tests/PHPPdf/Test/Core/Formatter/RowDimensionFormatterTest.php index dacb0709..3b4d5de3 100644 --- a/tests/PHPPdf/Test/Core/Formatter/RowDimensionFormatterTest.php +++ b/tests/PHPPdf/Test/Core/Formatter/RowDimensionFormatterTest.php @@ -88,7 +88,7 @@ public function enlargeCellsToRowHeight($rowHeight, array $cellHeights, $marginT { $boundary = $this->getBoundaryMockWithEnlargeAsserts($rowHeight - $height); - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('getHeight', 'setHeight', 'getBoundary')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('getHeight', 'setHeight', 'getBoundary')); $cell->expects($this->atLeastOnce()) ->method('getBoundary') diff --git a/tests/PHPPdf/Test/Core/Formatter/TableFormatterTest.php b/tests/PHPPdf/Test/Core/Formatter/TableFormatterTest.php index cdbbe0f0..2d685ef9 100644 --- a/tests/PHPPdf/Test/Core/Formatter/TableFormatterTest.php +++ b/tests/PHPPdf/Test/Core/Formatter/TableFormatterTest.php @@ -8,7 +8,7 @@ PHPPdf\Core\Node\Table\Row, PHPPdf\Core\Node\Table, PHPPdf\ObjectMother\TableObjectMother, - PHPPdf\Core\Node\Table\Cell; + PHPPdf\Core\Node\Table\TableCell; class TableFormatterTest extends \PHPPdf\PHPUnit\Framework\TestCase { diff --git a/tests/PHPPdf/Test/Core/Node/CellTest.php b/tests/PHPPdf/Test/Core/Node/CellTest.php index fe4886cf..5f3b83ac 100644 --- a/tests/PHPPdf/Test/Core/Node/CellTest.php +++ b/tests/PHPPdf/Test/Core/Node/CellTest.php @@ -2,7 +2,7 @@ namespace PHPPdf\Test\Core\Node; -use PHPPdf\Core\Node\Table\Cell; +use PHPPdf\Core\Node\Table\TableCell; use PHPPdf\Core\Node\Node; use PHPPdf\Core\Node\Table; @@ -12,7 +12,7 @@ class CellTest extends \PHPPdf\PHPUnit\Framework\TestCase public function setUp() { - $this->cell = new Cell(); + $this->cell = new TableCell(); } /** @@ -72,6 +72,6 @@ public function notifyListenersWhenAttributeHasChanged() $this->cell->setAttribute('width', 100); $this->cell->setAttribute('width', 200); - $this->cell->setParent(new Cell()); + $this->cell->setParent(new TableCell()); } } \ No newline at end of file diff --git a/tests/PHPPdf/Test/Core/Node/RowTest.php b/tests/PHPPdf/Test/Core/Node/RowTest.php index 6b3b6575..258cdc01 100644 --- a/tests/PHPPdf/Test/Core/Node/RowTest.php +++ b/tests/PHPPdf/Test/Core/Node/RowTest.php @@ -29,7 +29,7 @@ public function addingInvalidChild() */ public function addingValidChild() { - $node = new Nodes\Table\Cell(); + $node = new Nodes\Table\TableCell(); $this->row->add($node); $this->assertTrue(count($this->row->getChildren()) > 0); @@ -100,7 +100,7 @@ public function setNumberOfColumnForCells(array $colspans) $i = 0; foreach($colspans as $colspan) { - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('setNumberOfColumn', 'getColspan')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('setNumberOfColumn', 'getColspan')); $cell->expects($this->atLeastOnce()) ->method('getColspan') ->will($this->returnValue($colspan)); @@ -142,7 +142,7 @@ public function addTableAsListenerWhenCellHasAddedToRow() private function cellWithAddListenerExpectation($listener) { - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('addListener')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('addListener')); $cell->expects($this->at(0)) ->method('addListener') @@ -191,7 +191,7 @@ private function createMockedCellsWithHeights(array $heights) $cells = array(); foreach($heights as $height) { - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('getHeight')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('getHeight')); $cell->expects($this->atLeastOnce()) ->method('getHeight') ->will($this->returnValue($height)); @@ -250,7 +250,7 @@ private function createMockedCellsWidthVerticalMargins($marginsTop, $marginsBott for($i=0, $count = count($marginsTop); $i<$count; $i++) { - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('getMarginTop', 'getMarginBottom')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('getMarginTop', 'getMarginBottom')); $cell->expects($this->atLeastOnce()) ->method('getMarginTop') ->will($this->returnValue($marginsTop[$i])); diff --git a/tests/PHPPdf/Test/Core/Node/TableTest.php b/tests/PHPPdf/Test/Core/Node/TableTest.php index beb7f235..ceee2aa7 100644 --- a/tests/PHPPdf/Test/Core/Node/TableTest.php +++ b/tests/PHPPdf/Test/Core/Node/TableTest.php @@ -2,9 +2,9 @@ namespace PHPPdf\Test\Core\Node; -use PHPPdf\Core\PdfUnitConverter; +use PHPPdf\Core\PdfUnitConverter; -use PHPPdf\Core\Node\Table\Cell; +use PHPPdf\Core\Node\Table\TableCell; use PHPPdf\Core\Node\Table; use PHPPdf\Core\Boundary; use PHPPdf\Core\Node as Nodes; @@ -160,7 +160,7 @@ public function setColumnsWidthsWhenTableHasBeenNotifiedByCell(array $cellsWidth { foreach($cellsWidths as $rowNumber => $width) { - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('getWidth', 'getNumberOfColumn', 'getColspan')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('getWidth', 'getNumberOfColumn', 'getColspan')); $cell->expects($this->atLeastOnce()) ->method('getWidth') ->will($this->returnValue($width)); @@ -233,7 +233,7 @@ public function setColumnsMarginsWhenTableHasBeenNotifiedByCell(array $cellsMarg { $marginRight = $cellsMarginsRight[$columnNumber][$rowNumber]; - $cell = new Cell(array( + $cell = new TableCell(array( 'margin-left' => $marginLeft, 'margin-right' => $marginRight, )); @@ -278,7 +278,7 @@ public function cellsInRowsMarginsProvider() public function setColumnsWidthsWhenRowHasBeenAdded($cellWidth, $colspan, $expectedColumnsWidth) { $row = $this->getMock('PHPPdf\Core\Node\Table\Row', array('getChildren')); - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('getWidth', 'getNumberOfColumn', 'getColspan')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('getWidth', 'getNumberOfColumn', 'getColspan')); $row->expects($this->atLeastOnce()) ->method('getChildren') @@ -346,7 +346,7 @@ public function minWidthOfColumnIsMaxOfMinWidthOfColumnsCells(array $cellsInRows { $colspan = $colspans[$rowNumber][$columnNumber]; - $cell = $this->getMock('PHPPdf\Core\Node\Table\Cell', array('getMinWidth', 'getNumberOfColumn', 'getColspan')); + $cell = $this->getMock('PHPPdf\Core\Node\Table\TableCell', array('getMinWidth', 'getNumberOfColumn', 'getColspan')); $cell->expects($this->atLeastOnce()) ->method('getMinWidth') ->will($this->returnValue($minWidth)); From 6e4ca1b07db4d42512c3b341d08401637b496826 Mon Sep 17 00:00:00 2001 From: Goran Tomic Date: Fri, 2 Jun 2023 09:13:22 +0200 Subject: [PATCH 3/6] feat(FIAP-197): updated zendpdf --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fc66cb33..855a82ff 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,16 @@ ], "require": { "ext-mbstring": "*", - "zendframework/zendpdf": "~2.0.0" + "jobcloud/zendpdf": "dev-main" }, "require-dev": { "imagine/imagine": ">=0.2.0,<0.6.0", "phpunit/phpunit": "^9.6.7" }, + "minimum-stability": "dev", + "repositories": [ + {"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/ZendPdf.git"} + ], "suggest": { "imagine/imagine": "If you want to use image generating (required version: >=v0.2.6)" }, From 8704dc6601b193e0862f8d0da92a5bc99c1cdbfa Mon Sep 17 00:00:00 2001 From: Goran Tomic Date: Fri, 2 Jun 2023 10:06:08 +0200 Subject: [PATCH 4/6] feat(FIAP-197): prefer-stable --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 855a82ff..31c4f331 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "imagine/imagine": ">=0.2.0,<0.6.0", "phpunit/phpunit": "^9.6.7" }, + "prefer-stable": true, "minimum-stability": "dev", "repositories": [ {"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/ZendPdf.git"} From d501c4b5b92dd0e05bafd88d13f5f527a7089686 Mon Sep 17 00:00:00 2001 From: Goran Tomic Date: Fri, 2 Jun 2023 11:45:54 +0200 Subject: [PATCH 5/6] feat(FIAP-197): use tagged ver of zendpdf --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 31c4f331..db81c040 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ ], "require": { "ext-mbstring": "*", - "jobcloud/zendpdf": "dev-main" + "jobcloud/zendpdf": "^1.0.0" }, "require-dev": { "imagine/imagine": ">=0.2.0,<0.6.0", From cd8fbe4400ade272557e67854f18b07387989aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20H=C3=A4ber?= Date: Mon, 5 Jun 2023 17:43:16 +0200 Subject: [PATCH 6/6] feat(FIAP-197): use alpine and update composer --- composer.json | 10 +++--- docker/.env | 3 ++ docker/Dockerfile | 47 -------------------------- docker/docker-compose.dev.yml | 25 ++++++++++++++ docker/docker-compose.yml | 12 ------- docker/php/Dockerfile | 37 ++++++++++++++++++++ docker/php/files/bin/php-ext-disable | 12 +++++++ docker/php/files/bin/php-ext-enable | 20 +++++++++++ docker/php/files/user-home/.bashrc | 7 ++++ docker/php/files/user-home/.ssh/config | 4 +++ test.php | 23 ------------- 11 files changed, 113 insertions(+), 87 deletions(-) create mode 100644 docker/.env delete mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.dev.yml delete mode 100644 docker/docker-compose.yml create mode 100644 docker/php/Dockerfile create mode 100755 docker/php/files/bin/php-ext-disable create mode 100755 docker/php/files/bin/php-ext-enable create mode 100644 docker/php/files/user-home/.bashrc create mode 100644 docker/php/files/user-home/.ssh/config delete mode 100644 test.php diff --git a/composer.json b/composer.json index db81c040..1896ff58 100644 --- a/composer.json +++ b/composer.json @@ -14,19 +14,19 @@ "email": "peter.pl7@gmail.com" } ], + "repositories": [ + {"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/zendpdf.git"} + ], "require": { "ext-mbstring": "*", - "jobcloud/zendpdf": "^1.0.0" + "jobcloud/zendpdf": "^2.0.3" }, "require-dev": { "imagine/imagine": ">=0.2.0,<0.6.0", - "phpunit/phpunit": "^9.6.7" + "phpunit/phpunit": "^8.5.33" }, "prefer-stable": true, "minimum-stability": "dev", - "repositories": [ - {"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/ZendPdf.git"} - ], "suggest": { "imagine/imagine": "If you want to use image generating (required version: >=v0.2.6)" }, diff --git a/docker/.env b/docker/.env new file mode 100644 index 00000000..7f5ec0f1 --- /dev/null +++ b/docker/.env @@ -0,0 +1,3 @@ +COMPOSE_PROJECT_NAME=jobcloud-phppdf +XDEBUG_REMOTE_HOST=localhost +#XDEBUG_REMOTE_HOST=docker.for.mac.localhost diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index cd6a5e30..00000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,47 +0,0 @@ -FROM php:8.1-fpm - -# Set Environment Variables -ENV DEBIAN_FRONTEND noninteractive - -# -#-------------------------------------------------------------------------- -# Software's Installation -#-------------------------------------------------------------------------- -# -# Installing tools and PHP extentions using "apt", "docker-php", "pecl", -# - -# Install "curl", "libmemcached-dev", "libpq-dev", "libjpeg-dev", -# "libpng-dev", "libfreetype6-dev", "libssl-dev", "libmcrypt-dev", -RUN set -eux; \ - apt-get update; \ - apt-get upgrade -y; \ - apt-get install -y --no-install-recommends \ - git \ - curl \ - libmemcached-dev \ - libz-dev \ - libpq-dev \ - libjpeg-dev \ - libpng-dev \ - libfreetype6-dev \ - libssl-dev \ - libwebp-dev \ - libxpm-dev \ - libmcrypt-dev \ - libonig-dev; \ - rm -rf /var/lib/apt/lists/* - -RUN set -eux; \ - # Install the PHP gd library - docker-php-ext-configure gd \ - --prefix=/usr \ - --with-jpeg \ - --with-webp \ - --with-xpm \ - --with-freetype; \ - docker-php-ext-install gd; \ - php -r 'var_dump(gd_info());' - -# install composer -RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml new file mode 100644 index 00000000..8446521f --- /dev/null +++ b/docker/docker-compose.dev.yml @@ -0,0 +1,25 @@ +version: '3.9' +services: + php: + container_name: jobcloud-phppdf-php + hostname: jobcloud-phppdf-php + build: + dockerfile: php/Dockerfile + context: ./ + args: + USER_ID: ${USER_ID} + ports: + - '8080:80' + tty: true + volumes: + - ../:/var/www/html + - ~/.bash_aliases:/home/www-data/.bash_aliases:rw + - ~/.bash_history:/home/www-data/.bash_history:rw + secrets: + - ssh_host_key + environment: + XDEBUG_CONFIG: remote_host=${XDEBUG_REMOTE_HOST} + PHP_IDE_CONFIG: serverName=php +secrets: + ssh_host_key: + file: ~/.ssh/id_rsa \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml deleted file mode 100644 index dc2ecdc8..00000000 --- a/docker/docker-compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -version: '3.9' - -services: - php: - container_name: php-pdf - build: - dockerfile: ./Dockerfile - context: ./ - ports: - - '8080:80' - volumes: - - ../:/var/www/html diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 00000000..1a1eb88d --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,37 @@ +FROM php:8.1-alpine3.18 + +ARG USER_ID + +# PHP: Copy configuration files & remove dist files +RUN mkdir /phpIni +COPY php/files/bin/ /usr/local/bin/ + +# SYS: Install required packages +RUN apk --no-cache upgrade && \ + apk --no-cache add bash git sudo openssh autoconf gcc g++ make gettext sudo shadow + +RUN if [ -n "$USER_ID" ] && [ "$USER_ID" -lt 60001 ]; then \ + usermod -u ${USER_ID} -o www-data; \ + fi + +# USER: set /bin/bash and allow www-data to become root +RUN usermod -s /bin/bash www-data && \ + echo 'www-data ALL=(ALL) NOPASSWD: ALL' > '/etc/sudoers.d/www-data' + +# USER: copy home +COPY --chown=www-data:www-data php/files/user-home /home/www-data + +# USER: add ssh key and fix permission of the ssh directory +RUN ln -s /run/secrets/ssh_host_key /home/www-data/.ssh/id_rsa && \ + chmod 700 /home/www-data/.ssh && \ + chmod 400 /home/www-data/.ssh/config + +# PHP: Install php extensions +RUN pecl channel-update pecl.php.net + +# COMPOSER: install binary +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer + +USER www-data + +WORKDIR /var/www/html diff --git a/docker/php/files/bin/php-ext-disable b/docker/php/files/bin/php-ext-disable new file mode 100755 index 00000000..1f6f68f8 --- /dev/null +++ b/docker/php/files/bin/php-ext-disable @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ $# -eq 0 ] + then + echo "Please pass a php module name" + exit +fi + +for phpmod in "$@" +do + rm -f /usr/local/etc/php/conf.d/*$phpmod*.ini +done diff --git a/docker/php/files/bin/php-ext-enable b/docker/php/files/bin/php-ext-enable new file mode 100755 index 00000000..43e06b92 --- /dev/null +++ b/docker/php/files/bin/php-ext-enable @@ -0,0 +1,20 @@ +#!/bin/bash + +if [[ ${#} -eq 0 ]] ; then + echo -e "\\nPHP module name required!\\n" + exit 1 +fi + +for phpmod in "${@}" ; do + + files=($(find /phpIni -type f -iname "*${phpmod}*.ini" -exec ls -1 '{}' +)) + + for i in "${files[@]}" ; do + ln -s "${i}" /usr/local/etc/php/conf.d + done + + if [[ ${#files[@]} -eq 0 ]] ; then + docker-php-ext-enable "${phpmod}" + fi + +done diff --git a/docker/php/files/user-home/.bashrc b/docker/php/files/user-home/.bashrc new file mode 100644 index 00000000..8c1d66f2 --- /dev/null +++ b/docker/php/files/user-home/.bashrc @@ -0,0 +1,7 @@ +alias cls='printf "\033c"' + +export PS1='\[\e[1;32m\]\h\[\e[0m\] \[\e[1;37m\]\w\[\e[0m\] \[\e[1;32m\]\u\[\e[0m\] \[\e[1;37m\]\$\[\e[0m\] ' + +if [ -f ~/.bash_aliases ]; then + . ~/.bash_aliases +fi diff --git a/docker/php/files/user-home/.ssh/config b/docker/php/files/user-home/.ssh/config new file mode 100644 index 00000000..2113240a --- /dev/null +++ b/docker/php/files/user-home/.ssh/config @@ -0,0 +1,4 @@ +Host * + StrictHostKeyChecking no + UserKnownHostsFile /dev/null + IdentityFile /run/secrets/ssh_host_key diff --git a/test.php b/test.php deleted file mode 100644 index e9dbddb7..00000000 --- a/test.php +++ /dev/null @@ -1,23 +0,0 @@ -getData());