Skip to content

Commit b8854dd

Browse files
committed
feat(phar): add phar archive to poser
1 parent 148fdff commit b8854dd

File tree

10 files changed

+59
-8
lines changed

10 files changed

+59
-8
lines changed

Diff for: .docker/development/php74/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ FROM pugx/poser:php74
33
USER root
44

55
WORKDIR "/application"
6+
7+
## To generate phar archive: https://github.com/box-project/box
8+
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 for: .docker/development/php80/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ FROM pugx/poser:php80
33
USER root
44

55
WORKDIR "/application"
6+
7+
## To generate phar archive: https://github.com/box-project/box
8+
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 for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
### Added
1414
* add CircleCI jobs for build and tests with php 8.0
1515
* add Github actions jobs for build and tests with php 7.4 and php 8.0
16+
* add phar archive powered by [box-project](https://github.com/box-project/box)
1617

1718
### Changed
1819
* refactoring of docker-compose to develop with php74 and php80

Diff for: CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,12 @@ $ composer phpspec
5555
$ composer behat
5656
```
5757

58+
## Update version of `phar`
59+
60+
```bash
61+
docker-compose up --build -d
62+
docker-compose exec php74 composer box:validate
63+
docker-compose exec php74 composer box:compile
64+
```
5865

5966
## ENJOY

Diff for: README.md

+26-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,37 @@ This library is used by https://poser.pugx.org
1515

1616
to use the library with lower php version use the tag [v1.4](https://github.com/badges/poser/tree/v1.4.0)
1717

18-
## Use as command
18+
## Use as `phar` command
1919

20-
#### 1. Create a project
20+
### 1. Download the phar
21+
```bash
22+
wget -q -O /usr/local/bin/poser https://github.com/.../poser.phar
23+
chmod +x /usr/local/bin/poser
24+
```
25+
26+
### 2. Launch the command
27+
28+
Create an image
29+
```bash
30+
poser license MIT blue -p "license.svg"
31+
```
32+
33+
Flush an image
34+
```bash
35+
poser license MIT blue
36+
```
37+
38+
39+
## Use as `bin` command
40+
41+
### 1. Create a project
2142

2243
```bash
2344
composer create-project badges/poser
2445
ln -s poser/bin/poser /usr/local/bin/poser
2546
```
2647

27-
#### 2. Launch the command
48+
### 2. Launch the command
2849

2950
Create an image
3051
```bash
@@ -38,13 +59,13 @@ poser license MIT blue
3859

3960
## Usage as library
4061

41-
#### 1. Add to composer dependencies
62+
### 1. Add to composer dependencies
4263

4364
```bash
4465
composer require badges/poser
4566
```
4667

47-
#### 2. Use in your project as lib
68+
### 2. Use in your project as lib
4869

4970
```php
5071
use PUGX\Poser\Render\SvgPlasticRender;

Diff for: box.json.dist

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"force-autodiscovery": true,
3+
"output": "poser.phar"
4+
}

Diff for: composer.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
"docker:build:php74": "docker build -t pugx/poser:php74 -f .docker/base/php74/Dockerfile .",
6060
"docker:push:php74": "docker push pugx/poser:php74",
6161
"docker:build:php80": "docker build -t pugx/poser:php80 -f .docker/base/php80/Dockerfile .",
62-
"docker:push:php80": "docker push pugx/poser:php80"
62+
"docker:push:php80": "docker push pugx/poser:php80",
63+
"box:compile": "box compile",
64+
"box:validate": "box validate"
6365
},
6466
"extra": {
6567
"branch-alias": {

Diff for: poser.phar

1.75 MB
Binary file not shown.

Diff for: src/Calculator/GDTextSizeCalculator.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ class GDTextSizeCalculator implements TextSizeCalculatorInterface
1919

2020
public function __construct()
2121
{
22-
$this->fontPath = __DIR__ . self::TEXT_FONT;
22+
if (0 === \strpos(__DIR__, 'phar://')) {
23+
//Hack to work with phar virtual environment
24+
$prefixFontPath = './src/Calculator';
25+
} else {
26+
$prefixFontPath = __DIR__;
27+
}
28+
29+
$this->fontPath = $prefixFontPath . self::TEXT_FONT;
2330
}
2431

2532
/**
@@ -28,6 +35,7 @@ public function __construct()
2835
public function calculateWidth(string $text, int $size = self::TEXT_SIZE): float
2936
{
3037
$size = $this->convertToPt($size);
38+
3139
$box = \imagettfbbox($size, 0, $this->fontPath, $text);
3240

3341
return \round(\abs($box[2] - $box[0]) + self::SHIELD_PADDING_EXTERNAL + self::SHIELD_PADDING_INTERNAL, 1);

Diff for: src/UI/Command.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ protected function storeImage(OutputInterface $output, string $path, string $ima
140140
}
141141
@\fclose($fp);
142142

143-
$output->write(\sprintf('Image created at %s', $path));
143+
$output->writeln('');
144+
$output->writeln(\sprintf('Image created at %s', $path));
145+
$output->writeln('');
144146
}
145147

146148
protected function printHeaderOnce(OutputInterface $output): void

0 commit comments

Comments
 (0)