Skip to content

Commit

Permalink
feat(phar): add phar archive to poser
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBellyDev committed Jan 5, 2021
1 parent 148fdff commit 19ee959
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .docker/development/php74/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .docker/development/php80/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions box.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"force-autodiscovery": true,
"output": "poser.phar"
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Binary file added poser.phar
Binary file not shown.
10 changes: 9 additions & 1 deletion src/Calculator/GDTextSizeCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/UI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 19ee959

Please sign in to comment.