Skip to content
forked from psliwa/PHPPdf

Commit

Permalink
Merge pull request #6 from jobcloud/feat/FIAP-197/fix-deprecations
Browse files Browse the repository at this point in the history
feat(FIAP-197): fix deprecations
  • Loading branch information
haeber authored Jun 5, 2023
2 parents 3182975 + cd8fbe4 commit 946b9b7
Show file tree
Hide file tree
Showing 43 changed files with 376 additions and 295 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
"email": "peter.pl7@gmail.com"
}
],
"repositories": [
{"type": "vcs", "no-api": true, "url": "git@github.com:jobcloud/zendpdf.git"}
],
"require": {
"zendframework/zendpdf": "~2.0.0"
"ext-mbstring": "*",
"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",
"suggest": {
"imagine/imagine": "If you want to use image generating (required version: >=v0.2.6)"
},
Expand Down
3 changes: 3 additions & 0 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
COMPOSE_PROJECT_NAME=jobcloud-phppdf
XDEBUG_REMOTE_HOST=localhost
#XDEBUG_REMOTE_HOST=docker.for.mac.localhost
47 changes: 0 additions & 47 deletions docker/Dockerfile

This file was deleted.

25 changes: 25 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 0 additions & 12 deletions docker/docker-compose.yml

This file was deleted.

37 changes: 37 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions docker/php/files/bin/php-ext-disable
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions docker/php/files/bin/php-ext-enable
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions docker/php/files/user-home/.bashrc
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions docker/php/files/user-home/.ssh/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Host *
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
IdentityFile /run/secrets/ssh_host_key
2 changes: 1 addition & 1 deletion lib/PHPPdf/Core/AbstractUnitConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions lib/PHPPdf/Core/AttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

namespace PHPPdf\Core;

use ReturnTypeWillChange;

/**
* Bag of attributes
*
* @author Piotr Śliwa <peter.pl7@gmail.com>
*/
class AttributeBag implements \Countable, \Serializable
class AttributeBag implements \Countable
{
private $elements = array();

Expand All @@ -39,6 +41,7 @@ public function add($name, $value)
return $this;
}

#[ReturnTypeWillChange]
public function count()
{
return count($this->elements);
Expand Down Expand Up @@ -92,4 +95,4 @@ public function unserialize($serialized)
{
$this->elements = \unserialize($serialized);
}
}
}
23 changes: 18 additions & 5 deletions lib/PHPPdf/Core/Boundary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <peter.pl7@gmail.com>
*/
class Boundary implements \Countable, \Iterator, \ArrayAccess, \Serializable
class Boundary implements \Countable, \Iterator, \ArrayAccess
{
private $points = array();
private $numberOfPoints = 0;
Expand Down Expand Up @@ -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();
Expand All @@ -183,6 +186,8 @@ public function current()
/**
* @return array Array of Point objects
*/

#[ReturnTypeWillChange]
public function getPoints()
{
return $this->points;
Expand All @@ -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();
Expand Down Expand Up @@ -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))
Expand All @@ -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.');
Expand Down
8 changes: 4 additions & 4 deletions lib/PHPPdf/Core/ComplexAttribute/ComplexAttributeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PHPPdf\Core\ComplexAttribute;

use PHPPdf\Exception\InvalidArgumentException;
use PHPPdf\Exception\InvalidArgumentException;

use PHPPdf\Core\ComplexAttribute\Exception\DefinitionNotFoundException;

Expand All @@ -20,7 +20,7 @@
*
* @author Piotr Śliwa <peter.pl7@gmail.com>
*/
class ComplexAttributeFactory implements \Serializable
class ComplexAttributeFactory
{
private $definitions = array();
private $constructors = array();
Expand Down Expand Up @@ -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);
}
}
}
}
8 changes: 5 additions & 3 deletions lib/PHPPdf/Core/DrawingTaskHeap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Loading

0 comments on commit 946b9b7

Please sign in to comment.