diff --git a/.docker/development/php74/Dockerfile b/.docker/development/php74/Dockerfile index cddd459..3f82994 100644 --- a/.docker/development/php74/Dockerfile +++ b/.docker/development/php74/Dockerfile @@ -3,3 +3,6 @@ FROM pugx/poser:php74 USER root WORKDIR "/application" + +## To generate phar archive: https://github.com/box-project/box +RUN wget -q -O /usr/bin/box https://github.com/box-project/box/releases/download/3.11.0/box.phar && chmod +x /usr/bin/box diff --git a/.docker/development/php80/Dockerfile b/.docker/development/php80/Dockerfile index 54fe96b..589593f 100644 --- a/.docker/development/php80/Dockerfile +++ b/.docker/development/php80/Dockerfile @@ -3,3 +3,6 @@ FROM pugx/poser:php80 USER root WORKDIR "/application" + +## To generate phar archive: https://github.com/box-project/box +RUN wget -q -O /usr/bin/box https://github.com/box-project/box/releases/download/3.11.0/box.phar && chmod +x /usr/bin/box diff --git a/CHANGELOG.md b/CHANGELOG.md index 26569f3..8bbf109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added * add CircleCI jobs for build and tests with php 8.0 * add Github actions jobs for build and tests with php 7.4 and php 8.0 +* add phar archive powered by [box-project](https://github.com/box-project/box) ### Changed * refactoring of docker-compose to develop with php74 and php80 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8445b52..1ff29fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,5 +55,12 @@ $ composer phpspec $ composer behat ``` +## Update version of `phar` + +```bash +docker-compose up --build -d +docker-compose exec php74 composer box:validate +docker-compose exec php74 composer box:compile +``` ## ENJOY diff --git a/README.md b/README.md index a3a1339..a3986d6 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,37 @@ This library is used by https://poser.pugx.org to use the library with lower php version use the tag [v1.4](https://github.com/badges/poser/tree/v1.4.0) -## Use as command +## Use as `phar` command -#### 1. Create a project +### 1. Download the phar +```bash +wget -q -O /usr/local/bin/poser https://github.com/.../poser.phar +chmod +x /usr/local/bin/poser +``` + +### 2. Launch the command + +Create an image +```bash +poser license MIT blue -p "license.svg" +``` + +Flush an image +```bash +poser license MIT blue +``` + + +## Use as `bin` command + +### 1. Create a project ```bash composer create-project badges/poser ln -s poser/bin/poser /usr/local/bin/poser ``` -#### 2. Launch the command +### 2. Launch the command Create an image ```bash @@ -38,13 +59,13 @@ poser license MIT blue ## Usage as library -#### 1. Add to composer dependencies +### 1. Add to composer dependencies ```bash composer require badges/poser ``` -#### 2. Use in your project as lib +### 2. Use in your project as lib ```php use PUGX\Poser\Render\SvgPlasticRender; diff --git a/box.json.dist b/box.json.dist new file mode 100644 index 0000000..03c7861 --- /dev/null +++ b/box.json.dist @@ -0,0 +1,4 @@ +{ + "force-autodiscovery": true, + "output": "poser.phar" +} \ No newline at end of file diff --git a/composer.json b/composer.json index 6e8aa3e..7241b2d 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,9 @@ "docker:build:php74": "docker build -t pugx/poser:php74 -f .docker/base/php74/Dockerfile .", "docker:push:php74": "docker push pugx/poser:php74", "docker:build:php80": "docker build -t pugx/poser:php80 -f .docker/base/php80/Dockerfile .", - "docker:push:php80": "docker push pugx/poser:php80" + "docker:push:php80": "docker push pugx/poser:php80", + "box:compile": "box compile", + "box:validate": "box validate" }, "extra": { "branch-alias": { diff --git a/poser.phar b/poser.phar new file mode 100755 index 0000000..0dc22a9 Binary files /dev/null and b/poser.phar differ diff --git a/src/Calculator/GDTextSizeCalculator.php b/src/Calculator/GDTextSizeCalculator.php index 07e0c19..670a3e2 100644 --- a/src/Calculator/GDTextSizeCalculator.php +++ b/src/Calculator/GDTextSizeCalculator.php @@ -19,7 +19,14 @@ class GDTextSizeCalculator implements TextSizeCalculatorInterface public function __construct() { - $this->fontPath = __DIR__ . self::TEXT_FONT; + if(0 === strpos(__DIR__, 'phar://')) { + //Hack to work with phar virtual environment + $prefixFontPath = './src/Calculator'; + } else { + $prefixFontPath = __DIR__; + } + + $this->fontPath = $prefixFontPath . self::TEXT_FONT; } /** @@ -28,6 +35,7 @@ public function __construct() public function calculateWidth(string $text, int $size = self::TEXT_SIZE): float { $size = $this->convertToPt($size); + $box = \imagettfbbox($size, 0, $this->fontPath, $text); return \round(\abs($box[2] - $box[0]) + self::SHIELD_PADDING_EXTERNAL + self::SHIELD_PADDING_INTERNAL, 1); diff --git a/src/UI/Command.php b/src/UI/Command.php index 6b7aa8b..f1152bc 100644 --- a/src/UI/Command.php +++ b/src/UI/Command.php @@ -140,7 +140,9 @@ protected function storeImage(OutputInterface $output, string $path, string $ima } @\fclose($fp); - $output->write(\sprintf('Image created at %s', $path)); + $output->writeln(''); + $output->writeln(\sprintf('Image created at %s', $path)); + $output->writeln(''); } protected function printHeaderOnce(OutputInterface $output): void